Skip to content

Logflare/turnio-prometheus-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrometheusParser

A simple parser for the Prometheus text format built with nimble_parsec. Likely incomplete but works well enough for our use case.

iex(1)> PrometheusParser.parse("# Some documenting text")
%PrometheusParser.Line{
               documentation: "Some documenting text",
               line_type: "COMMENT"
             }

iex(1)> PrometheusParser.parse("# HELP web_uptime Number of seconds since web server has started") ==
%PrometheusParser.Line{
  documentation: "Number of seconds since web server has started",
  label: "web_uptime",
  line_type: "HELP"
}

iex(1)> PrometheusParser.parse("# TYPE web_uptime gauge") ==
%PrometheusParser.Line{label: "web_uptime", line_type: "TYPE", type: "gauge"}

iex(1)> PrometheusParser.parse("web_connections{node=\"abc-123-def-0\"} 607180") ==
%PrometheusParser.Line{
  documentation: nil,
  label: "web_connections",
  line_type: "ENTRY",
  pairs: [{"node", "abc-123-def-0"}],
  timestamp: nil,
  type: nil,
  value: "607180"
}

Rebuild them into Prometheus output again with to_string():

%PrometheusParser.Line{
  documentation: nil,
  label: "web_connections",
  line_type: "ENTRY",
  pairs: [{"node", "abc-123-def-0"}],
  timestamp: nil,
  type: nil,
  value: "607180"
}
iex(3)> to_string(line)
"web_connections{node=\"abc-123-def-0\"} 607180"

Installation

If available in Hex, the package can be installed by adding prometheus_parser to your list of dependencies in mix.exs:

def deps do
  [
    {:prometheus_parser, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/prometheus_parser.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%