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); })); }