private void BtnChart_Click(object sender, RoutedEventArgs e) { if (dataGridList.Count > 1) { ChartStatistics model = new ChartStatistics(); List <long> ado = new List <long>(); List <long> entity = new List <long>(); List <long> petapoco = new List <long>(); List <long> drapper = new List <long>(); foreach (var item in dataGridList) { ado.Add((long)item.ADO); entity.Add((long)item.EntityFramework); petapoco.Add((long)item.PetaPoco); drapper.Add((long)item.Drapper); } model.ADO = ado; model.EntityFramework = entity; model.PetaPoco = petapoco; model.Drapper = drapper; TimeChart chart = new TimeChart(model); chart.ShowDialog(); } /// else if (dataGridList.Count == 1) { TimeChartModel mod = new TimeChartModel(); mod.ChartData = new List <TimeModel>(); mod.ChartData.Add(new TimeModel { Name = ".NET ADO", Time = (long)dataGridList[0].ADO }); mod.ChartData.Add(new TimeModel { Name = "Entity Framework", Time = (long)dataGridList[0].EntityFramework }); mod.ChartData.Add(new TimeModel { Name = "PetaPoco", Time = (long)dataGridList[0].PetaPoco }); mod.ChartData.Add(new TimeModel { Name = "Drapper", Time = (long)dataGridList[0].Drapper }); TimeChart ch = new TimeChart(mod); ch.ShowDialog(); } }
public TimeChart(TimeChartModel model) { InitializeComponent(); var colSeries = new ColumnSeries(); Axis axis = new Axis(); axis.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); Axis axisy = new Axis(); axisy.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); axisy.FontSize = 15; axisy.Title = "Czas [ms]"; axis.Labels = new List <string>(); axis.MinRange = 0; axis.FontSize = 15; chartModel = model; CharSeries = new SeriesCollection(); colSeries.Values = new ChartValues <long>(); colSeries.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); foreach (var item in model.ChartData) { colSeries.Values.Add(item.Time); axis.Labels.Add(item.Name); } CharSeries.Add(colSeries); this.lvTimeChart.Series = CharSeries; this.lvTimeChart.AxisX = new AxesCollection { axis }; this.lvTimeChart.AxisY = new AxesCollection { axisy }; }
public ActionResult Chart(string serverip, string serverid, string date, string columns = "cpu,memory,ioread,iowrite,networkupload,networkdownload", string datatype = "avg") { if (string.IsNullOrWhiteSpace(date)) { date = DateTime.Now.Date.ToString("yyyy-MM-dd"); } ViewBag.columns = columns; ViewBag.serverip = serverip; ViewBag.serverid = serverid; ViewBag.date = date; ViewBag.datatype = datatype; List <TimeChartModel> ms = new List <TimeChartModel>(); if (string.IsNullOrWhiteSpace(serverip) && string.IsNullOrWhiteSpace(serverid)) { return(View(ms)); } TimeChartDataType chartdatatype = (TimeChartDataType)Enum.Parse(typeof(TimeChartDataType), datatype); TimeChartType charttype = TimeChartType.Day; if (date.Split('-').Length == 3) { charttype = TimeChartType.Day; } else if (date.Split('-').Length == 2) { charttype = TimeChartType.Month; } else if (date.Split('-').Length == 1) { charttype = TimeChartType.Year; date = new DateTime(Convert.ToInt32(date), 1, 1, 0, 0, 0).ToString("yyyy-MM-dd"); } var startDate = DateTime.Parse(date).Date; string[] cs = columns.TrimEnd(',').Split(','); foreach (var c in cs) { if (c == "") { continue; } var model = new TimeChartModel(); model.DataType = chartdatatype; model.Type = charttype; model.StartDate = startDate; model.Key = c; if (c == "cpu") { model.Title = "CPU"; model.UnitText = "%"; } if (c == "memory") { model.Title = "可用内存"; model.UnitText = "M"; } if (c == "networkupload") { model.Title = "网络上传"; model.UnitText = "Byte"; } if (c == "networkdownload") { model.Title = "网络下载"; model.UnitText = "Byte"; } if (c == "ioread") { model.Title = "磁盘读"; model.UnitText = "Byte"; } if (c == "iowrite") { model.Title = "磁盘写"; model.UnitText = "Byte"; } if (c == "iisrequest") { model.Title = "iis请求"; model.UnitText = "次/s"; } model.SubTitle = model.Title + "【" + model.DataType.ToString() + "】值统计图"; if (model.Type == TimeChartType.Day) { model.PointInterval = "60 * 1000";//一分钟 model.EndDate = model.StartDate.AddDays(1); model.MaxZoom = "60 * 60 * 1000"; model.SubTitle += ",采集单位【分钟】"; } else if (model.Type == TimeChartType.Month) { model.PointInterval = "24 * 60 * 60 * 1000";//一天 model.EndDate = model.StartDate.AddMonths(1); model.MaxZoom = "10 * 24 * 60 * 60 * 1000"; model.SubTitle += ",采集单位【天】"; } else if (model.Type == TimeChartType.Year) { model.PointInterval = "24 * 60 * 60 * 1000";//一天 model.EndDate = model.StartDate.AddYears(1); model.MaxZoom = "10 * 24 * 60 * 60 * 1000"; model.SubTitle += ",采集单位【天】"; } Dictionary <DateTime, double> dic = new Dictionary <DateTime, double>(); using (DbConn PubConn = DbConfig.CreateConn(Config.ClusterConnectString)) { PubConn.Open(); if (model.Type == TimeChartType.Day) { tb_performance_collect_dal dal = new tb_performance_collect_dal(); dic = dal.GetTimeChart(PubConn, c, model.StartDate, serverip, serverid, model.DataType.ToString()); } else { tb_performance_dayreport_dal dal = new tb_performance_dayreport_dal(); dic = dal.GetTimeChart(PubConn, c, model.StartDate, model.EndDate, serverip, serverid, model.DataType.ToString()); } } DateTime dtbegin = model.StartDate; DateTime dtend = model.EndDate; while (true) { if (!dic.ContainsKey(dtbegin)) { dic.Add(dtbegin, 0); } if (model.Type == TimeChartType.Day) { dtbegin = dtbegin.AddMinutes(1); } else { dtbegin = dtbegin.AddDays(1); } if (dtbegin >= dtend) { break; } } model.DataJson = new XXF.Serialization.JsonHelper().Serializer(dic.OrderBy(c1 => c1.Key).Select(c1 => c1.Value)); ms.Add(model); } using (DbConn PubConn = DbConfig.CreateConn(Config.PlatformManageConnectString)) { PubConn.Open(); tb_cluster_dal dal = new tb_cluster_dal(); ViewBag.ServerName = dal.GetServerName(PubConn, serverip, serverid); } return(View(ms)); }
public ActionResult Chart(string logtag, string date, XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType type = XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType.ApiUrl, string datatype = "avg", int connid = 0, string columns = "time") { return(this.ConnVisit(connid, (conn) => { if (string.IsNullOrWhiteSpace(date)) { date = DateTime.Now.Date.ToString("yyyy-MM-dd"); } ViewBag.type = type; ViewBag.date = date; ViewBag.datatype = datatype; ViewBag.logtag = logtag; ViewBag.connid = connid; List <TimeChartModel> ms = new List <TimeChartModel>(); if (string.IsNullOrWhiteSpace(logtag)) { return View(ms); } int a = 0; if (!int.TryParse(logtag, out a)) { type = XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType.ApiUrl; } TimeChartDataType chartdatatype = (TimeChartDataType)Enum.Parse(typeof(TimeChartDataType), datatype); TimeChartType charttype = TimeChartType.Day; if (date.Split('-').Length == 3) { charttype = TimeChartType.Day; } else if (date.Split('-').Length == 2) { charttype = TimeChartType.Month; } else if (date.Split('-').Length == 1) { charttype = TimeChartType.Year; date = new DateTime(Convert.ToInt32(date), 1, 1, 0, 0, 0).ToString("yyyy-MM-dd"); } var startDate = DateTime.Parse(date).Date; string[] cs = columns.TrimEnd(',').Split(','); foreach (var c in cs) { if (c == "") { continue; } var model = new TimeChartModel(); model.DataType = chartdatatype; model.Type = charttype; model.StartDate = startDate; model.Key = c; model.Title = "耗时"; model.UnitText = "秒"; if (model.DataType == TimeChartDataType.count) { model.UnitText = "次"; } model.SubTitle = model.Title + "【" + model.DataType.ToString() + "】值统计图"; if (model.Type == TimeChartType.Day) { model.PointInterval = "60 * 1000";//一分钟 model.EndDate = model.StartDate.AddDays(1); model.MaxZoom = "60 * 60 * 1000"; model.SubTitle += ",采集单位【分钟】"; } else if (model.Type == TimeChartType.Month) { model.PointInterval = "24 * 60 * 60 * 1000";//一天 model.EndDate = model.StartDate.AddMonths(1); model.MaxZoom = "10 * 24 * 60 * 60 * 1000"; model.SubTitle += ",采集单位【天】"; } else if (model.Type == TimeChartType.Year) { model.PointInterval = "24 * 60 * 60 * 1000";//一天 model.EndDate = model.StartDate.AddYears(1); model.MaxZoom = "10 * 24 * 60 * 60 * 1000"; model.SubTitle += ",采集单位【天】"; } Dictionary <DateTime, double> dic = new Dictionary <DateTime, double>(); using (DbConn PubConn = DbConfig.CreateConn(conn)) { if (model.Type == TimeChartType.Day) { if (type == XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType.ApiUrl) { tb_timewatchlog_api_dal dal = new tb_timewatchlog_api_dal(); dic = dal.GetTimeChart(PubConn, c, model.StartDate, logtag, model.DataType.ToString(), (int)type + ""); } else if (type == XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType.SqlCmd) { tb_timewatchlog_dal dal = new tb_timewatchlog_dal(); dic = dal.GetTimeChart(PubConn, c, model.StartDate, logtag, model.DataType.ToString(), (int)type + ""); } } else { if (type == XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType.ApiUrl) { tb_timewatchlog_api_dayreport_dal dal = new tb_timewatchlog_api_dayreport_dal(); dic = dal.GetTimeChart(PubConn, c, model.StartDate, model.EndDate, logtag, model.DataType.ToString()); } else if (type == XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType.SqlCmd) { tb_timewatchlog_sql_dayreport_dal dal = new tb_timewatchlog_sql_dayreport_dal(); dic = dal.GetTimeChart(PubConn, c, model.StartDate, model.EndDate, logtag, model.DataType.ToString()); } } } DateTime dtbegin = model.StartDate; DateTime dtend = model.EndDate; while (true) { if (!dic.ContainsKey(dtbegin)) { dic.Add(dtbegin, 0); } if (model.Type == TimeChartType.Day) { dtbegin = dtbegin.AddMinutes(1); } else { dtbegin = dtbegin.AddDays(1); } if (dtbegin >= dtend) { break; } } model.DataJson = new XXF.Serialization.JsonHelper().Serializer(dic.OrderBy(c1 => c1.Key).Select(c1 => c1.Value)); ms.Add(model); } return View(ms); })); }