Module: Prometheus::Client::Formats::Text

Defined in:
lib/prometheus/client/formats/text.rb

Overview

Text format is human readable mainly used for manual inspection.

Constant Summary collapse

MEDIA_TYPE =
'text/plain'
VERSION =
'0.0.4'
CONTENT_TYPE =
"#{MEDIA_TYPE}; version=#{VERSION}"
METRIC_LINE =
'%s%s %s'
TYPE_LINE =
'# TYPE %s %s'
HELP_LINE =
'# HELP %s %s'
LABEL =
'%s="%s"'
SEPARATOR =
','
DELIMITER =
"\n"
REGEX =
{ doc: /[\n\\]/, label: /[\n\\"]/ }
REPLACE =
{ "\n" => '\n', '\\' => '\\\\', '"' => '\"' }

Class Method Summary collapse

Class Method Details

.marshal(registry) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/prometheus/client/formats/text.rb', line 23

def self.marshal(registry)
  lines = []

  registry.metrics.each do |metric|
    lines << format(TYPE_LINE, metric.name, metric.type)
    lines << format(HELP_LINE, metric.name, escape(metric.docstring))

    metric.values.each do |label_set, value|
      representation(metric, label_set, value) { |l| lines << l }
    end
  end

  # there must be a trailing delimiter
  (lines << nil).join(DELIMITER)
end