Пример #1
0
        public dynamic GetLogOnOff(int appId = 0)
        {
            string resp = string.Empty;

            var on_off = LogViewerManager.GetLogViewer().GetLogOnOff(appId);

            if (on_off != null)
            {
                resp += on_off.Debug + "," + on_off.Info + "," + on_off.Warn + "," + on_off.Error;
            }

            #region 计数

            TMetricEntity metric = new TMetricEntity();
            metric.Name  = "logging_client_getLogOnOff_count";
            metric.Time  = Utils.GetTimeStamp(DateTime.Now) / 10000000;
            metric.Value = 1;
            metric.Tags  = new Dictionary <string, string>();
            metric.Tags.Add("AppId", appId.ToString());
            List <TMetricEntity> metrics = new List <TMetricEntity>();
            metrics.Add(metric);

            TLogPackage logPackage = new TLogPackage();
            logPackage.AppId       = appId;
            logPackage.IP          = 0;
            logPackage.MetricItems = metrics;

            LogReciverBase LogReciver = new LogReciverBase();

            LogReciver.Log(logPackage);

            #endregion 计数

            return(resp);
        }
Пример #2
0
        public dynamic StatisticsViewer(long start, long end, int appId = 0)
        {
            //long start = Convert.ToInt64(Request.Query["start"]);
            //long end = Convert.ToInt64(Request.Query["end"]);
            //int appId = Convert.ToInt32(Request.Query["appId"]);
            var viewer = LogViewerManager.GetLogViewer();
            var s      = viewer.GetStatistics(start, end, appId);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(s));
        }
Пример #3
0
        public dynamic LogViewer()
        {
            long start = Convert.ToInt64(Request.Query["start"]);
            long end   = Convert.ToInt64(Request.Query["end"]);
            int  appId = Convert.ToInt32(Request.Query["appId"]);

            string level_str = Request.Query["level"];

            if (string.IsNullOrWhiteSpace(level_str))
            {
                level_str = "1,2,3,4";
            }
            List <int> level = new List <int>();

            level_str.Split(',').ToList().ForEach(x => level.Add(Convert.ToInt32(x)));

            string title    = Request.Query["title"];
            string msg      = Request.Query["msg"];
            string ip       = Request.Query["ip"];
            string source   = Request.Query["source"];
            int    limit    = Convert.ToInt32(Request.Query["limit"]);
            string tags_str = Request.Query["tags"];
            var    viewer   = LogViewerManager.GetLogViewer();

            var result = new LogVM();

            long ipNum = Utils.IPToNumber(ip);

            List <string> tags = new List <string>();

            if (!string.IsNullOrWhiteSpace(tags_str))
            {
                tags = tags_str.Split(',').Distinct().ToList();
            }

            var lst = viewer.GetLogs(start, end, appId, level.ToArray(), title, msg, source, ipNum, tags, limit);

            result.List  = lst;
            result.Start = start;
            result.End   = end;
            var last = lst.LastOrDefault();

            if (last != null)
            {
                result.Cursor = lst.Min(x => x.Time);
                long min = result.List.Min(x => x.Time);
                long max = result.List.Max(x => x.Time);

                long first = result.List.FirstOrDefault().Time;
                long lastt = result.List.LastOrDefault().Time;
            }
            var json_result = Newtonsoft.Json.JsonConvert.SerializeObject(result);

            return(json_result);
        }
Пример #4
0
        private LogViewerManager CreateLogViewer()
        {
            var pagerDb   = new DatabaseLogDbActions(GetConnectionString());
            var logViewer = new LogViewerManager(pagerDb);

            sortType                 = GetPersistedSortType();
            logViewer.PageSize       = PageSize();
            logViewer.PageNumber     = CurrentPage();
            logViewer.SortColumnName = SortColumnName();
            logViewer.SortType       = sortType;
            return(logViewer);
        }
Пример #5
0
        public static Dictionary <string, string> GetOptions()
        {
            var opts = LogViewerManager.GetLogViewer().GetOptions(OptKeys);

            if (opts.Count == 0)
            {
                return(new Dictionary <string, string>());
            }
            else
            {
                return(opts.ToDictionary(x => x.Key, x => x.Value));
            }
        }
Пример #6
0
        public dynamic StatisticsPeriod(long period, int appId)
        {
            //long period = Convert.ToInt64(Request.Query["period"]);
            //int appId = Convert.ToInt32(Request.Query["appId"]);
            long    start_num = Utils.GetTimeStamp(DateTime.Now.AddMinutes(-period));
            long    end_num   = Utils.GetTimeStamp(DateTime.Now);
            var     viewer    = LogViewerManager.GetLogViewer();
            var     s         = viewer.GetStatistics(start_num, end_num, appId);
            JObject obj       = new JObject();

            obj.Add("Data", JToken.FromObject(s));
            return(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
        }
Пример #7
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            long start = Convert.ToInt64(context.Request["start"]);
            long end   = Convert.ToInt64(context.Request["end"]);
            int  appId = Convert.ToInt32(context.Request["appId"]);

            //long start_num = Utils.GetTimeStamp(start);

            //long end_num = Utils.GetTimeStamp(end);

            var viewer = LogViewerManager.GetLogViewer();

            var s = viewer.GetStatistics(start, end, appId);

            context.Response.AddHeader("Access-Control-Allow-Origin", "*");//允许跨域请求
            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(s));
        }
Пример #8
0
        public void ProcessRequest(HttpContext context)
        {
            int appId = Convert.ToInt32(context.Request["appId"]);

            string resp = string.Empty;


            var on_off = LogViewerManager.GetLogViewer().GetLogOnOff(appId);

            if (on_off != null)
            {
                resp += on_off.Debug + "," + on_off.Info + "," + on_off.Warn + "," + on_off.Error;
            }

            #region 计数
            TMetricEntity metric = new TMetricEntity();
            metric.Name  = "logging_client_getLogOnOff_count";
            metric.Time  = Utils.GetTimeStamp(DateTime.Now) / 10000000;
            metric.Value = 1;
            metric.Tags  = new Dictionary <string, string>();
            metric.Tags.Add("AppId", appId.ToString());
            List <TMetricEntity> metrics = new List <TMetricEntity>();
            metrics.Add(metric);


            TLogPackage logPackage = new TLogPackage();
            logPackage.AppId       = appId;
            logPackage.IP          = 0;
            logPackage.MetricItems = metrics;

            LogReciverBase LogReciver = new LogReciverBase();

            LogReciver.Log(logPackage);


            #endregion

            context.Response.Write(resp);
        }
Пример #9
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            long period = Convert.ToInt64(context.Request["period"]);
            //long end = Convert.ToInt64(context.Request["end"]);
            int appId = Convert.ToInt32(context.Request["appId"]);

            long start_num = Utils.GetTimeStamp(DateTime.Now.AddMinutes(-period));

            long end_num = Utils.GetTimeStamp(DateTime.Now);

            var viewer = LogViewerManager.GetLogViewer();

            var s = viewer.GetStatistics(start_num, end_num, appId);

            JObject obj = new JObject();

            obj.Add("Data", JToken.FromObject(s));

            context.Response.AddHeader("Access-Control-Allow-Origin", "*");//允许跨域请求
            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
        }
Пример #10
0
 /// <summary>
 /// 刷新所有开关
 /// </summary>
 private static void RefreshLogOnOff()
 {
     ALL_LOG_ONOFF  = LogViewerManager.GetLogViewer().GetALLLogOnOff();
     LastUpdateTime = DateTime.Now;
 }
Пример #11
0
        public override void Alert()
        {
            if (this.EmailReceivers == null || this.EmailReceivers.Length == 0)
            {
                return;
            }

            long start1 = Utils.GetUnixTime(DateTime.Now.AddMinutes(-1)) * 10000000;
            long end1   = Utils.GetUnixTime(DateTime.Now) * 10000000;

            long start2 = Utils.GetUnixTime(DateTime.Now.AddMinutes(-2)) * 10000000;
            long end2   = start1;

            var data1 = LogViewerManager.GetLogViewer().GetStatistics(start1, end1, 0);

            var data2 = LogViewerManager.GetLogViewer().GetStatistics(start2, end2, 0);

            var data_grp1 = data1.GroupBy(x => x.AppId);

            foreach (var item in data_grp1)
            {
                var appId = item.Key;


                var lastAH = LogViewerManager.GetLogViewer().GetLastAlertingHistory(appId, AlertingType.AppError);
                if (lastAH != null)
                {
                    if ((Utils.GetDateTimeFromUnix(lastAH.Time) - DateTime.Now).TotalMinutes < this.Interval)
                    {
                        continue;
                    }
                }

                int error_count1 = item.Sum(x => x.Error);
                int error_count2 = data2.Where(x => x.AppId == appId).Sum(x => x.Error);
                int error_count  = error_count1 + error_count2;

                string msg_body_fmt = string.Empty;
                if ((error_count) > ErrorCountLimit)
                {
                    //报警
                    msg_body_fmt = "应用{0}程序异常过多,请及时处理";
                }
                else if (error_count2 > 0 && error_count1 > 10 * this.Interval && ((error_count1 - error_count2) / error_count2) * 100 > ErrorGrowthLimit)
                {
                    //报警
                    msg_body_fmt = "应用{0}程序异常增长很快,请及时处理";
                }
                else
                {
                    continue;
                }

                string appName = appId.ToString();
                var    loo     = LogViewerManager.GetLogViewer().GetLogOnOff(appId);
                if (loo != null)
                {
                    appName = $"{appId}({ loo.AppName})";
                }

                string msg_subject = "【报警】应用" + appName + "程序异常";

                for (int i = 0; i < EmailReceivers.Length; i++)
                {
                    MailHelper.SendMail(msg_subject, EmailReceivers[i], string.Format(msg_body_fmt, appName), true);
                }

                AlertingHistory ah = new AlertingHistory();
                ah.AlertingType = AlertingType.AppError;
                ah.Time         = Utils.GetUnixTime(DateTime.Now);
                ah.ObjId        = appId;
                ILogWriter w = LogWriterManager.GetLogWriter();
                w.RecordAlerting(ah);
            }
        }
Пример #12
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            long start = Convert.ToInt64(context.Request["start"]);
            long end   = Convert.ToInt64(context.Request["end"]);
            int  appId = Convert.ToInt32(context.Request["appId"]);

            string level_str = context.Request["level"];

            if (string.IsNullOrWhiteSpace(level_str))
            {
                level_str = "1,2,3,4";
            }
            int[] level = Array.ConvertAll <string, int>(level_str.Split(','), x => Convert.ToInt32(x));

            string title    = context.Request["title"];
            string msg      = context.Request["msg"];
            string ip       = context.Request["ip"];
            string source   = context.Request["source"];
            int    limit    = Convert.ToInt32(context.Request["limit"]);
            string tags_str = context.Request["tags"];
            var    viewer   = LogViewerManager.GetLogViewer();

            var result = new LogVM();

            long ipNum = Utils.IPToNumber(ip);

            //long start_num = Utils.GetTimeStamp(start);

            //long end_num = Utils.GetTimeStamp(end);

            List <string> tags = new List <string>();

            if (!string.IsNullOrWhiteSpace(tags_str))
            {
                tags = tags_str.Split(',').Distinct().ToList();
            }

            //tags.Add("a=a");

            var lst = viewer.GetLogs(start, end, appId, level, title, msg, source, ipNum, tags, limit);

            result.List  = lst;
            result.Start = start;
            result.End   = end;
            var last = lst.LastOrDefault();

            if (last != null)
            {
                result.Cursor = lst.Min(x => x.Time);
                long min = result.List.Min(x => x.Time);
                long max = result.List.Max(x => x.Time);

                long first = result.List.FirstOrDefault().Time;
                long lastt = result.List.LastOrDefault().Time;
            }
            var json_result = Newtonsoft.Json.JsonConvert.SerializeObject(result);

            context.Response.AddHeader("Access-Control-Allow-Origin", "*");//允许跨域请求

            context.Response.Write(json_result);
        }
Пример #13
0
 private void PersistPagingOptions(LogViewerManager logViewer)
 {
     lblTotalPages.Text    = logViewer.GetTotalNumberOfPages().ToString();
     hfSortByColumn.Value  = logViewer.SortColumnName;
     hfSortDirection.Value = logViewer.SortType.ToString();
 }