Esempio n. 1
0
        private void Process(DateTime date, IList <Int32> appIds)
        {
            // 统计数据
            var list = TraceData.SearchGroupApp(date, appIds.ToArray());

            if (list.Count == 0)
            {
                return;
            }

            // 统计对象
            var sts = AppDayStat.Search(date, list.Select(e => e.AppId).ToArray());

            // 聚合
            foreach (var item in list)
            {
                var st = sts.FirstOrDefault(e => e.AppId == item.AppId);
                if (st == null)
                {
                    st = new AppDayStat {
                        StatDate = date, AppId = item.AppId
                    };
                    sts.Add(st);
                }

                st.Total     = item.Total;
                st.Errors    = item.Errors;
                st.TotalCost = item.TotalCost;
                st.MaxCost   = item.MaxCost;
                st.MinCost   = item.MinCost;
            }

            // 保存统计
            sts.Save(true);
        }
Esempio n. 2
0
        private void Process(DateTime date)
        {
            // 统计数据,每日跟踪根据应用和类型分组
            var list = TraceDayStat.SearchGroupApp(date);

            if (list.Count == 0)
            {
                return;
            }

            // 统计对象
            var sts = AppDayStat.Search(date, null);

            // 聚合,按应用分组,每一组内每个类型一行
            var dic = list.GroupBy(e => e.AppId);

            foreach (var item in dic)
            {
                var appId = item.Key;
                if (appId <= 0)
                {
                    continue;
                }

                var ds = item.ToList();
                var st = sts.FirstOrDefault(e => e.AppId == appId);
                if (st == null)
                {
                    st = new AppDayStat {
                        StatDate = date, AppId = appId
                    };
                    sts.Add(st);
                }

                st.Total     = ds.Sum(e => e.Total);
                st.Errors    = ds.Sum(e => e.Errors);
                st.TotalCost = ds.Sum(e => e.TotalCost);
                st.MaxCost   = ds.Max(e => e.MaxCost);
                st.MinCost   = ds.Min(e => e.MinCost);

                // 分类统计,应用有可能缺失某些类别
                st.Apis   = ds.Where(e => e.Type == "api").Sum(e => e.Total);
                st.Https  = ds.Where(e => e.Type == "http").Sum(e => e.Total);
                st.Dbs    = ds.Where(e => e.Type == "db").Sum(e => e.Total);
                st.Mqs    = ds.Where(e => e.Type == "mq").Sum(e => e.Total);
                st.Redis  = ds.Where(e => e.Type == "redis").Sum(e => e.Total);
                st.Others = ds.Where(e => e.Type == "other").Sum(e => e.Total);
            }

            // 保存统计
            sts.Save(false);
        }