예제 #1
0
        public async Task <List <UrlRequestCount> > GetUrlRequestStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string sql = $@"Select Url,COUNT(1) as Total From ""{Prefix}RequestInfo"" {BuildSqlFilter(filterOption)} Group By Url order by Total {BuildSqlControl(filterOption)};";

            TraceLogSql(sql);

            return(await LoggingSqlOperation(async connection => (await connection.QueryAsync <UrlRequestCount>(sql)).ToList()));
        }
예제 #2
0
        public async Task <List <StatusCodeCount> > GetStatusCodeStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string where = BuildSqlFilter(filterOption, true);

            var sql = string.Join(" Union ", filterOption.StatusCodes.Select(m => $@"Select '{m}' AS Code,COUNT(1) AS Total From ""{Prefix}RequestInfo"" {where} AND StatusCode = {m}"));

            TraceLogSql(sql);

            return(await LoggingSqlOperation(async connection => (await connection.QueryAsync <StatusCodeCount>(sql)).ToList(), "获取http状态码数量统计异常"));
        }
예제 #3
0
        public async Task <List <StatusCodeCount> > GetStatusCodeStatisticsAsync(RequestInfoFilterOption option)
        {
            List <StatusCodeCount> statusCodes = new List <StatusCodeCount>();

            var response = await Client.SearchAsync <RequestInfo>(x => x.Index(GetIndexName <RequestInfo>())
                                                                  .Query(d =>

                                                                         d.HasDateWhere(option.StartTime, option.EndTime) &&
                                                                         d.Terms(f => f.Field(e => e.Node).Terms(option.Nodes)) &&
                                                                         d.Terms(f => f.Field(e => e.StatusCode).Terms(option.StatusCodes))

                                                                         ).Aggregations(b =>

                                                                                        b.Terms("statusCode", c => c.Field("statusCode"))

                                                                                        ).Size(0));

            if (response != null && response.IsValid)
            {
                if (response.Aggregations.Count > 0)
                {
                    var buckets = (response.Aggregations.FirstOrDefault().Value as Nest.BucketAggregate).Items.ToList();

                    foreach (var item in buckets)
                    {
                        var model = item as Nest.KeyedBucket <object>;

                        statusCodes.Add(new StatusCodeCount
                        {
                            Code  = model.Key.ToString().ToInt(),
                            Total = Convert.ToInt32(model.DocCount.Value)
                        });
                    }
                }
            }

            foreach (var item in option.StatusCodes)
            {
                var k = statusCodes.Where(x => x.Code == item).FirstOrDefault();

                if (k == null)
                {
                    statusCodes.Add(new StatusCodeCount
                    {
                        Code  = item,
                        Total = 0
                    });
                }
            }

            return(statusCodes);
        }
예제 #4
0
        public async Task<List<UrlRequestCount>> GetUrlRequestStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string sql = $"Select TOP {filterOption.Take} Url,COUNT(1) as Total From RequestInfo {BuildSqlFilter(filterOption)} Group By Url order by Total {BuildSqlControl(filterOption)};";

            TraceLogSql(sql);

            List<UrlRequestCount> result = null;
            await LoggingSqlOperation(async connection =>
            {
                result = (await connection.QueryAsync<UrlRequestCount>(sql).ConfigureAwait(false)).ToList();
            }).ConfigureAwait(false);

            return result;
        }
예제 #5
0
        public async Task<List<StatusCodeCount>> GetStatusCodeStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string where = BuildSqlFilter(filterOption, true);

            var sql = string.Join(" Union ", filterOption.StatusCodes.Select(m => $"Select '{m}' Code,COUNT(1) Total From RequestInfo {where} AND StatusCode = {m}"));

            TraceLogSql(sql);

            List<StatusCodeCount> result = null;
            await LoggingSqlOperation(async connection =>
            {
                result = (await connection.QueryAsync<StatusCodeCount>(sql).ConfigureAwait(false)).ToList();
            }, "获取http状态码数量统计异常").ConfigureAwait(false);

            return result;
        }
예제 #6
0
        public async Task <List <UrlRequestCount> > GetUrlRequestStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string sql = $@"Select Url,COUNT(1)  Total From RequestInfo {BuildSqlFilter(filterOption)} Group By Url order by Total {BuildSqlControl(filterOption)}";

            sql = BuildTopSql(sql, filterOption.Take);

            TraceLogSql(sql);

            List <UrlRequestCount> result = null;

            await LoggingSqlOperation(async connection =>
            {
                result = (await connection.QueryAsync <UrlRequestCount>(sql)).ToList();
            });

            return(result);
        }
예제 #7
0
        public async Task <List <UrlRequestCount> > GetUrlRequestStatisticsAsync(RequestInfoFilterOption option)
        {
            List <UrlRequestCount> urlRequests = new List <UrlRequestCount>();

            var response = await Client.SearchAsync <RequestInfo>(x => x.Index(GetIndexName <RequestInfo>())
                                                                  .Query(d =>

                                                                         d.HasDateWhere(option.StartTime, option.EndTime) &&
                                                                         d.Terms(f => f.Field(e => e.Node).Terms(option.Nodes)) &&
                                                                         d.Terms(f => f.Field(e => e.StatusCode).Terms(option.StatusCodes))

                                                                         ).Aggregations(b =>

                                                                                        b.Terms("url", c => c.Field("url").Order(d => option.IsAscend ? d.CountAscending() : d.CountDescending()).Size(option.Take))

                                                                                        ).Size(0));

            if (response != null && response.IsValid)
            {
                if (response.Aggregations.Count > 0)
                {
                    var buckets = (response.Aggregations.FirstOrDefault().Value as Nest.BucketAggregate).Items.ToList();

                    foreach (var item in buckets)
                    {
                        var model = item as Nest.KeyedBucket <object>;

                        urlRequests.Add(new UrlRequestCount
                        {
                            Url   = model.Key.ToString(),
                            Total = Convert.ToInt32(model.DocCount.Value)
                        });
                    }
                }
            }

            return(urlRequests);
        }
예제 #8
0
        /// <summary>
        /// 获取Url的平均请求处理时间统计
        /// </summary>
        /// <param name="filterOption"></param>
        /// <returns></returns>
        public async Task <List <RequestAvgResponeTime> > GetRequestAvgResponeTimeStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string sql = $"Select TOP {filterOption.Take} Url,Avg(Milliseconds) Time FROM RequestInfo {BuildSqlFilter(filterOption)} Group By Url order by Time {BuildSqlControl(filterOption)}";

            TraceLogSql(sql);

            List <RequestAvgResponeTime> result = null;

            await LoggingSqlOperation(async connection =>
            {
                result = (await connection.QueryAsync <RequestAvgResponeTime>(sql).ConfigureAwait(false)).ToList();
            }, "获取Url的平均请求处理时间统计异常").ConfigureAwait(false);

            return(result);
        }
예제 #9
0
        public async Task <List <RequestAvgResponeTime> > GetRequestAvgResponeTimeStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string sql = $@"Select Url,Avg(Milliseconds) AS Time FROM ""{Prefix}RequestInfo"" {BuildSqlFilter(filterOption)} Group By Url order by Time {BuildSqlControl(filterOption)}";

            TraceLogSql(sql);

            return(await LoggingSqlOperation(async connection => (await connection.QueryAsync <RequestAvgResponeTime>(sql)).ToList(), "获取Url的平均请求处理时间统计异常"));
        }
예제 #10
0
        public async Task <List <RequestAvgResponeTime> > GetRequestAvgResponeTimeStatisticsAsync(RequestInfoFilterOption option)
        {
            List <RequestAvgResponeTime> requestAvgs = new List <RequestAvgResponeTime>();

            var response = await Client.SearchAsync <RequestInfo>(x => x.Index(GetIndexName <RequestInfo>()).Query(c =>

                                                                                                                   c.HasDateWhere(option.StartTime, option.EndTime)

                                                                                                                   && c.Terms(f => f.Field(e => e.StatusCode).Terms(option.StatusCodes))

                                                                                                                   && c.Terms(f => f.Field(e => e.Node).Terms(option.Service.ToLowerInvariant()))

                                                                                                                   ).Aggregations(c => c.Terms("url", cc => cc.Field("url").Order(d => option.IsAscend ? d.Ascending("Milliseconds") : d.Descending("Milliseconds")).Aggregations(h =>

                                                                                                                                                                                                                                                                                  h.Average("Milliseconds", d => d.Field(e => e.Milliseconds))

                                                                                                                                                                                                                                                                                  ).Size(option.Take))).Size(0)

                                                                  );

            if (response != null && response.IsValid)
            {
                if (response.Aggregations.Count > 0)
                {
                    var buckets = (response.Aggregations.FirstOrDefault().Value as Nest.BucketAggregate).Items.ToList();

                    foreach (var item in buckets)
                    {
                        var model = item as Nest.KeyedBucket <object>;

                        requestAvgs.Add(new RequestAvgResponeTime
                        {
                            Url  = model.Key.ToString(),
                            Time = Convert.ToSingle(model.ValueCount("Milliseconds").Value.Value)
                        });
                    }
                }
            }

            return(requestAvgs);
        }
예제 #11
0
        /// <summary>
        /// 获取Url的平均请求处理时间统计
        /// </summary>
        /// <param name="filterOption"></param>
        /// <returns></returns>
        public async Task <List <RequestAvgResponeTime> > GetRequestAvgResponeTimeStatisticsAsync(RequestInfoFilterOption filterOption)
        {
            string sql = $"Select  Url,Round(Avg(Milliseconds),2) Time FROM RequestInfo {BuildSqlFilter(filterOption)} Group By Url order by Time {BuildSqlControl(filterOption)}";

            sql = BuildTopSql(sql, filterOption.Take);

            TraceLogSql(sql);

            List <RequestAvgResponeTime> result = null;

            await LoggingSqlOperation(async _ =>
            {
                result = (await _.QueryAsync <RequestAvgResponeTime>(sql)).ToList();
            }, "获取Url的平均请求处理时间统计异常");

            return(result);
        }
예제 #12
0
 public Task <List <UrlRequestCount> > GetUrlRequestStatisticsAsync(RequestInfoFilterOption filterOption)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 public Task <List <RequestAvgResponeTime> > GetRequestAvgResponeTimeStatisticsAsync(RequestInfoFilterOption filterOption)
 {
     throw new NotImplementedException();
 }
예제 #14
0
        public static SearchDescriptor <T> EndWhere <T>(this SearchDescriptor <T> search, RequestInfoFilterOption option) where T : class
        {
            if (option.StartTime.HasValue)
            {
                search = search.Query(x => x.DateRange(c => c.Field("createTime").GreaterThanOrEquals(option.StartTime.Value)));
            }

            return(search);
        }
예제 #15
0
        public static SearchDescriptor <T> SizeWhere <T>(this SearchDescriptor <T> search, RequestInfoFilterOption option) where T : class
        {
            if (option.Take > 0)
            {
                search = search.Size(option.Take);
            }

            return(search);
        }
예제 #16
0
 public static SearchDescriptor <T> BuildWhere <T>(this SearchDescriptor <T> search, RequestInfoFilterOption option) where T : class
 {
     return(search);
 }