Caddy.Metrics.Parser (Caddy v2.3.1)

View Source

Prometheus text format parser.

Parses Prometheus exposition format into %Caddy.Metrics{} structs.

Prometheus Format

The Prometheus text format consists of:

  • Comments starting with #
  • HELP lines: # HELP metric_name description
  • TYPE lines: # TYPE metric_name type
  • Metric lines: metric_name{label="value"} number timestamp?

Supported Metric Types

  • counter - Monotonically increasing value
  • gauge - Value that can go up or down
  • histogram - Buckets + sum + count
  • summary - Quantiles + sum + count

Summary

Functions

Parse Prometheus text format into a Metrics struct.

Functions

parse(text)

@spec parse(binary()) :: Caddy.Metrics.t()

Parse Prometheus text format into a Metrics struct.

Examples

text = """
# HELP caddy_http_requests_total Total HTTP requests
# TYPE caddy_http_requests_total counter
caddy_http_requests_total{server="srv0",code="200"} 1234
"""

metrics = Caddy.Metrics.Parser.parse(text)
metrics.http_requests_total
#=> %{%{server: "srv0", code: "200"} => 1234}