module Prometheus::Client::Formats::Text
Text
format is human readable mainly used for manual inspection.
Constants
- CONTENT_TYPE
- DELIMITER
- HELP_LINE
- LABEL
- MEDIA_TYPE
- METRIC_LINE
- REGEX
- REPLACE
- SEPARATOR
- TYPE_LINE
- VERSION
Public Class Methods
marshal(registry)
click to toggle source
# 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
Private Class Methods
escape(string, format = :doc)
click to toggle source
# File lib/prometheus/client/formats/text.rb, line 84 def escape(string, format = :doc) string.to_s.gsub(REGEX[format], REPLACE) end
histogram(name, set, value) { |metric(bucket, labels(merge(le: q)), v)| ... }
click to toggle source
# File lib/prometheus/client/formats/text.rb, line 58 def histogram(name, set, value) bucket = "#{name}_bucket" value.each do |q, v| next if q == "sum" yield metric(bucket, labels(set.merge(le: q)), v) end l = labels(set) yield metric("#{name}_sum", l, value["sum"]) yield metric("#{name}_count", l, value["+Inf"]) end
labels(set)
click to toggle source
# File lib/prometheus/client/formats/text.rb, line 74 def labels(set) return if set.empty? strings = set.each_with_object([]) do |(key, value), memo| memo << format(LABEL, key, escape(value, :label)) end "{#{strings.join(SEPARATOR)}}" end
metric(name, labels, value)
click to toggle source
# File lib/prometheus/client/formats/text.rb, line 70 def metric(name, labels, value) format(METRIC_LINE, name, labels, value) end
representation(metric, label_set, value) { |metric(name, labels(label_set), value)| ... }
click to toggle source
# File lib/prometheus/client/formats/text.rb, line 42 def representation(metric, label_set, value, &block) if metric.type == :summary summary(metric.name, label_set, value, &block) elsif metric.type == :histogram histogram(metric.name, label_set, value, &block) else yield metric(metric.name, labels(label_set), value) end end
summary(name, set, value) { |metric("#{name}_sum", l, value)| ... }
click to toggle source
# File lib/prometheus/client/formats/text.rb, line 52 def summary(name, set, value) l = labels(set) yield metric("#{name}_sum", l, value["sum"]) yield metric("#{name}_count", l, value["count"]) end