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())); }
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状态码数量统计异常")); }
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); }
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; }
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; }
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); }
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); }
/// <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); }
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的平均请求处理时间统计异常")); }
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); }
/// <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); }
public Task <List <UrlRequestCount> > GetUrlRequestStatisticsAsync(RequestInfoFilterOption filterOption) { throw new NotImplementedException(); }
public Task <List <RequestAvgResponeTime> > GetRequestAvgResponeTimeStatisticsAsync(RequestInfoFilterOption filterOption) { throw new NotImplementedException(); }
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); }
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); }
public static SearchDescriptor <T> BuildWhere <T>(this SearchDescriptor <T> search, RequestInfoFilterOption option) where T : class { return(search); }