//
        // GET: /TimeWatchCustomer/TimeWatchLogApiDayReport/

        public ActionResult Index(string url, string timebegin, string timeend, string orderby = "", int connid = 0, int pagesize = 15, int pageindex = 1)
        {
            return(this.ConnVisit(connid, (conn) =>
            {
                if (string.IsNullOrWhiteSpace(timebegin))
                {
                    timebegin = DateTime.Now.Date.AddDays(-10).ToString("yyyy-MM-dd");
                }
                if (string.IsNullOrWhiteSpace(timeend))
                {
                    timeend = DateTime.Now.Date.ToString("yyyy-MM-dd");
                }
                ViewBag.url = url; ViewBag.timebegin = timebegin; ViewBag.timeend = timeend; ViewBag.orderby = orderby;
                tb_timewatchlog_api_dayreport_dal dal = new tb_timewatchlog_api_dayreport_dal();
                PagedList <tb_timewatchlog_api_dayreport_model> pageList = null;
                int count = 0;
                using (DbConn PubConn = DbConfig.CreateConn(conn))
                {
                    PubConn.Open();
                    List <tb_timewatchlog_api_dayreport_model> List = dal.GetList(PubConn, url, timebegin, timeend, orderby, pagesize, pageindex, out count);
                    pageList = new PagedList <tb_timewatchlog_api_dayreport_model>(List, pageindex, pagesize, count);
                }
                if (Request.IsAjaxRequest())
                {
                    return PartialView("List", pageList);
                }
                return View(pageList);
            }));
        }
        private void Do()
        {
            tb_timewatchlog_api_dayreport_dal Dal = new tb_timewatchlog_api_dayreport_dal();
            bool c = Dal.StatisApiMinitor();

            if (c)
            {
                base.OpenOperator.Log("性能监控定时统计API性能成功");
            }
        }
 public ActionResult ChartJson(int connid, string Sday, string Eday, string key)
 {
     return(this.ConnVisit(connid, (conn) =>
     {
         List <Dictionary <string, object> > dic = new List <Dictionary <string, object> >();
         tb_timewatchlog_api_dayreport_dal dal = new tb_timewatchlog_api_dayreport_dal();
         using (DbConn PubConn = DbConfig.CreateConn(conn))
         {
             PubConn.Open();
             dic = dal.GetChartJson(PubConn, Sday, Eday, key);
         }
         return Json(new { data = dic });
     }));
 }
Esempio n. 4
0
 /// <summary>
 /// 检查api的接口性能
 /// </summary>
 private void CheckPerformanceOfApi(string connectstring, Domain.PlatformManage.Model.tb_database_config_model configmodel)
 {
     try
     {
         DateTime dtime = DateTime.Now;
         string   msg   = "";
         Dictionary <string, tb_timewatchlog_api_dayreport_model> dic = new Dictionary <string, tb_timewatchlog_api_dayreport_model>();
         List <string> urls = new List <string>();
         SqlHelper.ExcuteSql(connectstring, (c) =>
         {
             tb_timewatchlog_api_dayreport_dal dal = new tb_timewatchlog_api_dayreport_dal();
             var models = dal.GetDayReport(c, dtime.Date.AddDays(-1));
             models.ForEach(o =>
             {
                 string key = o.date.Date.ToString("yyyyMMdd") + o.url.ToLower();
                 if (!dic.Keys.Contains(key))
                 {
                     dic.Add(key, o);
                 }
                 if (!urls.Contains(o.url.ToLower()))
                 {
                     urls.Add(o.url.ToLower());
                 }
             });
         });
         foreach (var u in urls)
         {
             string keynow      = dtime.Date.ToString("yyyyMMdd") + u.ToLower();
             string keyyestoday = dtime.Date.AddDays(-1).ToString("yyyyMMdd") + u.ToLower();
             if (dic.ContainsKey(keynow) && dic.ContainsKey(keyyestoday))
             {
                 var per = (dic[keyyestoday].avgtime == 0 ? 0 : ((dic[keynow].avgtime - dic[keyyestoday].avgtime) / dic[keyyestoday].avgtime));
                 if (per > 0.2)
                 {
                     msg += string.Format("【{1}】上升{0}%({2}s,{3}s)\r\n", (per * 100).ToString("f2"), u, dic[keynow].avgtime.ToString("f2"), dic[keyyestoday].avgtime.ToString("f2"));
                 }
             }
         }
         if (msg != "")
         {
             TaskLogHelper.Error("检查api的接口性能", "【" + configmodel.dblocalname + "】Api接口性能检查(与昨日对比平均耗时)" + "\r\n" + msg, "耗时性能预警任务");
         }
     }
     catch (Exception exp)
     {
         this.OpenOperator.Error("【耗时性能预警任务】检查api的接口性能", exp);
     }
 }
 public ActionResult Chart(string Fday, string Nday, string key, int pageindex = 1, int connid = 0)
 {
     return(this.ConnVisit(connid, (conn) =>
     {
         if (string.IsNullOrWhiteSpace(Fday))
         {
             Fday = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
         }
         if (string.IsNullOrWhiteSpace(Nday))
         {
             Nday = DateTime.Now.ToString("yyyy-MM-dd");
         }
         if (string.IsNullOrWhiteSpace(key))
         {
             key = "avgtime";
         }
         ViewBag.Fday = Fday;
         ViewBag.Nday = Nday;
         ViewBag.Key = key;
         List <ChartModel> model = new List <ChartModel>();
         PagedList <ChartModel> pageList = null;
         int pagesize = 10;
         int count = 0;
         tb_timewatchlog_api_dayreport_dal dal = new tb_timewatchlog_api_dayreport_dal();
         using (DbConn PubConn = DbConfig.CreateConn(conn))
         {
             PubConn.Open();
             model = dal.GetKeyChartJson(PubConn, Fday, Nday, key, pagesize, pageindex, out count);
             pageList = new PagedList <ChartModel>(model, pageindex, pagesize, count);
         }
         if (Request.IsAjaxRequest())
         {
             return PartialView("List", pageList);
         }
         return View(pageList);
     }));
 }
        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);
            }));
        }