/// <summary> /// 依据 tags 求聚合周期内Matrix 数量 /// </summary> /// <param name="tags"></param> /// <returns></returns> public int? GetCount(IDictionary<string, string> tags = null) { int? count = null; var tmpaggregateResult = aggregateResult; if (tmpaggregateResult == null || tmpaggregateResult.Count == 0) { return count; } Arch.CFramework.Aggregating.AggregateKey aggregateKey = new Aggregating.AggregateKey(nameSpace, metricName, tags, (AggregateType)metricAttribute.MetricType); if (tags == null || tags.Count == 0) { count = 0; foreach (var item in tmpaggregateResult) { count += item.Value.Count; } } else { KeyValuePair<AggregateKey, AggregateResult> s = tmpaggregateResult.FirstOrDefault(c => c.Key.Equals(aggregateKey)); if (s.Key != null) { count = s.Value.Count; } } return count; }
/// <summary> /// 依据 tags 计算聚合周期内平均值 /// </summary> /// <param name="tags"></param> /// <returns></returns> public double? GetAvg(IDictionary<string, string> tags = null) { double? avg = null; var tmpaggregateResult = aggregateResult; if (tmpaggregateResult == null || tmpaggregateResult.Count == 0) { return avg; } Arch.CFramework.Aggregating.AggregateKey aggregateKey = new Aggregating.AggregateKey(nameSpace, metricName, tags, (AggregateType)metricAttribute.MetricType); if (tags == null || tags.Count == 0) { avg = 0; if (metricAttribute.MetricType == MetricType.Counter) { foreach (var item in tmpaggregateResult) { avg += item.Value.Sum; } } else { foreach (var item in tmpaggregateResult) { avg += item.Value.Avg; } } avg = avg / tmpaggregateResult.Count; } else { KeyValuePair<AggregateKey, AggregateResult> s = tmpaggregateResult.FirstOrDefault(c => c.Key.Equals(aggregateKey)); if (s.Key != null) { avg = s.Value.Avg; } } return avg; }
/// <summary> /// 依据 tags 求聚合周期内和 /// </summary> /// <param name="tags"></param> /// <returns></returns> public double? GetSum(Dictionary<string, string> tags = null) { double? sum = null; var tmpaggregateResult = aggregateResult; if (tmpaggregateResult != null && tmpaggregateResult.Count > 0) { var aggregateKey = new Aggregating.AggregateKey(nameSpace, metricName, tags, (AggregateType)metricAttribute.MetricType); if (tags == null || tags.Count == 0) { sum = 0; foreach (var item in tmpaggregateResult) { sum += item.Value.Sum; } } else { var s = tmpaggregateResult.FirstOrDefault(c => c.Key.Equals(aggregateKey)); if (s.Key != null) { sum = s.Value.Sum; } } } return sum; }
/// <summary> /// 依据 tags 检索聚合周期内最小值 /// </summary> /// <param name="tags"></param> /// <returns></returns> public double? GetMin(IDictionary<string, string> tags = null) { double? min = null; ; var tmpaggregateResult = aggregateResult; if (tmpaggregateResult != null && tmpaggregateResult.Count > 0) { var aggregateKey = new Aggregating.AggregateKey(nameSpace, metricName, tags, (AggregateType)metricAttribute.MetricType); if (tags == null || tags.Count == 0) { if (metricAttribute.MetricType == MetricType.Counter) { min = tmpaggregateResult.Values.Min(c => c.Sum); } else { min = tmpaggregateResult.Values.Min(c => c.Min); } } else { var s = tmpaggregateResult.FirstOrDefault(c => c.Key.Equals(aggregateKey)); if (s.Key != null) { if (metricAttribute.MetricType == MetricType.Counter) { min = s.Value.Sum; } else { min = s.Value.Min; } } } } return min; }
private void Set(IDictionary<string, string> tags, double val, int flag) { if (config == null || config.IsEnabled == false) return; if (ValidTags(tags)) { #region Version 1.4.6 Arch.CFramework.Aggregating.AggregateKey aggregateKey = new Aggregating.AggregateKey(nameSpace, metricName, tags, (AggregateType)metricAttribute.MetricType, IsIgnoreCase); Arch.CFramework.Aggregating.AggregateManager.PutDouble(aggregateKey, val); #endregion } }