private void SendResponseSize(RequestStatInfo info) { if (info.ResponseSizeMax.HasValue) SendAggregateValue(MetricNames.HttpResponse_Size, info.ResponseSizeMax.Value, info.Tags, "max", info.StatTime); if (info.ResponseSizeMin.HasValue) SendAggregateValue(MetricNames.HttpResponse_Size, info.ResponseSizeMin.Value, info.Tags, "min", info.StatTime); if (info.ResponseSizeSum.HasValue) { SendAggregateValue(MetricNames.HttpResponse_Size, info.ResponseSizeSum.Value, info.Tags, "sum", info.StatTime); SendAggregateValue(MetricNames.HttpResponse_Size, info.RequestCount, info.Tags, "count", info.StatTime); } }
private RequestStatInfo GetMetricInfoByUrl(UrlItem item, DateTime minute) { //统计各区间的请求次数 var requestCount = 0L; var requestRanges = new Dictionary<Dictionary<string, string>, long>(); foreach (var counter in item.GetAllCounters()) { var count = (long)AggregateHelper.GetDoubles(MetricNames.Namespace, MetricNames.HttpRequest_Count, counter.TagInfo.FullTags, minute, minute, AggregateType.SUM)[0].GetValueOrDefault(); if (count > 0) { requestRanges.Add(counter.TagInfo.FullTags, count); requestCount += count; } } //无请求时忽略统计 if (requestCount == 0) return null; var statInfo = new RequestStatInfo(); statInfo.RequestCount = requestCount; statInfo.RequestCountByRange = requestRanges; //统计请求耗时 var reqCost = AggregateHelper.GetDoubles(MetricNames.Namespace, MetricNames.HttpRequest_Cost, item.Tags, minute, minute, AggregateType.MAX, AggregateType.MIN, AggregateType.AVG, AggregateType.SUM); statInfo.RequestCostMax = Round(reqCost[0], 2); statInfo.RequestCostMin = Round(reqCost[1], 2); statInfo.RequestCostAvg = Round(reqCost[2], 2); statInfo.RequestCostSum = reqCost[3]; //统计请求内容大小 var reqSize = AggregateHelper.GetDoubles(MetricNames.Namespace, MetricNames.HttpRequest_Size, item.Tags, minute, minute, AggregateType.MAX, AggregateType.MIN, AggregateType.AVG, AggregateType.SUM); statInfo.RequestSizeMax = (long?)reqSize[0]; statInfo.RequestSizeMin = (long?)reqSize[1]; statInfo.RequestSizeAvg = (long?)reqSize[2]; statInfo.RequestSizeSum = (long?)reqSize[3]; //统计响应内容大小 var respSize = AggregateHelper.GetDoubles(MetricNames.Namespace, MetricNames.HttpResponse_Size, item.Tags, minute, minute, AggregateType.MAX, AggregateType.MIN, AggregateType.AVG, AggregateType.SUM); statInfo.ResponseSizeMax = (long?)respSize[0]; statInfo.ResponseSizeMin = (long?)respSize[1]; statInfo.ResponseSizeAvg = (long?)respSize[2]; statInfo.ResponseSizeSum = (long?)respSize[3]; statInfo.StatTime = minute; statInfo.Tags = new Dictionary<string,string>(item.Tags); return statInfo; }