reportMetrics method

  1. @override
void reportMetrics({
  1. Map<String, Gauge>? gauges,
  2. Map<String, Counter>? counters,
  3. Map<String, Histogram>? histograms,
  4. Map<String, Meter>? meters,
  5. Map<String, Timer>? timers,
})
override

Called periodically by the polling thread. Subclasses should report all the given metrics.

Implementation

@override
void reportMetrics({
  Map<String, Gauge>? gauges,
  Map<String, Counter>? counters,
  Map<String, Histogram>? histograms,
  Map<String, Meter>? meters,
  Map<String, Timer>? timers,
}) {
  final time = _clock.now();
  try {
    if (!_graphite.isConnected) {
      _graphite.connect();
    }
    if (gauges != null) {
      gauges.forEach((name, gauge) {
        reportGauge(time, name, gauge);
      });
    }
    if (counters != null) {
      counters.forEach((name, counter) {
        reportCounter(time, name, counter);
      });
    }
    if (histograms != null) {
      histograms.forEach((name, histogram) {
        reportHistogram(time, name, histogram);
      });
    }
    if (meters != null) {
      meters.forEach((name, meter) {
        reportMeter(time, name, meter);
      });
    }
    if (timers != null) {
      timers.forEach((name, timer) {
        reportTimer(time, name, timer);
      });
    }
    _graphite.flush();
  } on IOException catch (e) {
    _log.warning("Unable to report to Graphite", e);
    try {
      _graphite.close();
    } on IOException catch (e1) {
      _log.warning("Error closing Graphite", e1);
    }
  }
}