write004 function

void write004(
  1. StringSink sink,
  2. Iterable<MetricFamilySamples> metricFamilySamples
)

Write out the text version 0.0.4 of the given MetricFamilySamples.

Implementation

void write004(
    StringSink sink, Iterable<MetricFamilySamples> metricFamilySamples) {
  // See http://prometheus.io/docs/instrumenting/exposition_formats/
  // for the output format specification
  for (var metricFamilySample in metricFamilySamples) {
    sink.write('# HELP ');
    sink.write(metricFamilySample.name);
    sink.write(' ');
    _writeEscapedHelp(sink, metricFamilySample.help);
    sink.write('\n');

    sink.write('# TYPE ');
    sink.write(metricFamilySample.name);
    sink.write(' ');
    _writeMetricType(sink, metricFamilySample.type);
    sink.write('\n');

    for (var sample in metricFamilySample.samples) {
      sink.write(sample.name);
      if (sample.labelNames.isNotEmpty) {
        sink.write('{');
        for (var i = 0; i < sample.labelNames.length; ++i) {
          sink.write(sample.labelNames[i]);
          sink.write('="');
          _writeEscapedLabelValue(sink, sample.labelValues[i]);
          sink.write('",');
        }
        sink.write('}');
      }
      sink.write(' ');
      sink.write(formatDouble(sample.value));
      if (sample.timestamp != null) {
        sink.write(' ');
        sink.write(sample.timestamp);
      }
      sink.writeln();
    }
  }
}