/// <summary> /// Used to make sure we report 0 values if nothing new comes in /// </summary> public static void HandleZeroReports(DateTime currentMinute) { foreach (KeyValuePair <string, MetricAggregate> item in LastAggregates) { MetricSetting setting; if (MetricSettings.TryGetValue(item.Value.NameKey, out setting)) { if (setting == null) { MetricSetting remove; MetricSettings.TryRemove(item.Value.NameKey, out remove); continue; } var agg = new MetricAggregate(item.Value.Category, item.Value.Name, item.Value.MetricType, item.Value.IsIncrement); agg.OccurredUtc = currentMinute; switch (item.Value.MetricType) { case MetricType.Counter: setting.AutoReportLastValueIfNothingReported = false; // do not allow this break; case MetricType.CounterTime: setting.AutoReportLastValueIfNothingReported = false; // do not allow this break; } if (setting.AutoReportZeroIfNothingReported) { agg.Count = 1; agg.Value = 0; } else if (setting.AutoReportLastValueIfNothingReported) { agg.Count = item.Value.Count; agg.Value = item.Value.Value; } else { continue; } var aggKey = agg.AggregateKey(); if (AggregateMetrics.ContainsKey(aggKey) == false) { agg.NameKey = item.Value.NameKey; StackifyAPILogger.Log($"Creating default value for {aggKey}"); AggregateMetrics[aggKey] = agg; } } } }
private static void Aggregate(MetricAggregate aggregate) { try { var aggKey = aggregate.AggregateKey(); MetricAggregate agg; if (AggregateMetrics.TryGetValue(aggKey, out agg) == false) { if (AggregateMetrics.Count > 1000) { StackifyAPILogger.Log("No longer aggregating new metrics because more than 1000 are queued", true); return; } StackifyAPILogger.Log($"Creating aggregate for {aggKey}"); AggregateMetrics[aggKey] = aggregate; agg = aggregate; } if (aggregate.MetricType == MetricType.MetricLast) { agg.Count = 1; agg.Value = aggregate.Value; } else { agg.Count += aggregate.Count; agg.Value += aggregate.Value; } AggregateMetrics[aggKey] = agg; } catch (Exception ex) { StackifyAPILogger.Log($"Error in StackifyLib with aggregating metrics\r\n{ex}"); } }
private static void Aggregate(MetricAggregate aggregate) { try { string aggKey = aggregate.AggregateKey(); MetricAggregate agg; if (!_AggregateMetrics.TryGetValue(aggKey, out agg)) { if (_AggregateMetrics.Count > 1000) { Utils.StackifyAPILogger.Log("No longer aggregating new metrics because more than 1000 are queued"); return; } StackifyAPILogger.Log("Creating aggregate for " + aggKey); _AggregateMetrics[aggKey] = aggregate; agg = aggregate; } if (aggregate.MetricType == MetricType.MetricLast) { agg.Count = 1; agg.Value = aggregate.Value; } else { agg.Count += aggregate.Count; agg.Value += aggregate.Value; } _AggregateMetrics[aggKey] = agg; } catch (Exception ex) { StackifyAPILogger.Log("Error in StackifyLib with aggregating metrics"); } }
/// <summary> /// Used to make sure we report 0 values if nothing new comes in /// </summary> public static void HandleZeroReports(DateTime currentMinute) { foreach (var item in _LastAggregates) { MetricSetting setting; if (_MetricSettings.TryGetValue(item.Value.NameKey, out setting)) { if (setting == null) { MetricSetting remove; _MetricSettings.TryRemove(item.Value.NameKey, out remove); continue; } MetricAggregate agg = new MetricAggregate(item.Value.Category, item.Value.Name, item.Value.MetricType); agg.OccurredUtc = currentMinute; switch (item.Value.MetricType) { case MetricType.Counter: setting.AutoReportLastValueIfNothingReported = false; //do not allow this break; case MetricType.CounterTime: setting.AutoReportLastValueIfNothingReported = false; //do not allow this break; case MetricType.MetricAverage: break; case MetricType.MetricLast: break; } if (setting.AutoReportZeroIfNothingReported) { agg.Count = 1; agg.Value = 0; } else if (setting.AutoReportLastValueIfNothingReported) { agg.Count = item.Value.Count; agg.Value = item.Value.Value; } else { continue; } string aggKey = agg.AggregateKey(); if (!_AggregateMetrics.ContainsKey(aggKey)) { agg.NameKey = item.Value.NameKey; StackifyAPILogger.Log("Creating 0 default value for " + aggKey); _AggregateMetrics[aggKey] = agg; } } } }