time method

Metric time(
  1. String name,
  2. Stopwatch stopwatch, {
  3. int? interval,
  4. List<String> tags = const <String>[],
})

Log the time delta for a metric

Implementation

Metric time(
  String name,
  Stopwatch stopwatch, {
  int? interval,
  List<String> tags = const <String>[],
}) {
  // since currentTime is in seconds
  final elapsed = (stopwatch.elapsedMilliseconds / 1000).round();
  stopwatch.stop();
  final metric = Metric(
    name,
    MetricType.gauge,
    [
      [currentTime - elapsed, currentTime - elapsed],
      [currentTime, currentTime]
    ],
    host: host,
    interval: interval,
    prefix: prefix,
    tags: mergeTags(tags),
  );

  send(metric);
  return metric;
}