Skip to content

Instantly share code, notes, and snippets.

@bmabey
Last active March 4, 2018 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmabey/d513b1bb9fb91c3dfe92d3a8270a0081 to your computer and use it in GitHub Desktop.
Save bmabey/d513b1bb9fb91c3dfe92d3a8270a0081 to your computer and use it in GitHub Desktop.
instaparse parser for prometheus text format exporter (text version 0.0.4)
(* see https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md#text-format-details *)
statements = (type-def | help | metric)*
type-def = <"# TYPE "> metric-name <space> type <newline>?
type = #"counter|gauge|histogram|summary|untyped"
help = <"# HELP "> metric-name <space> docstring <newline>?
metric = metric-name labels? <space> value (<space> timestamp)? <newline>?
labels = <'{'> label-name label-value {<','> label-name label-value} <','>? <'}'>
(* the below doesn't take into account escaping but probably not an issue for our use case *)
label-value=<'="'>#'\w+'<'"'>
value = #"[0-9]+\.[0-9]"
timestamp = #'[0-9]+'
(* via https://github.com/prometheus/client_java/issues/28 *)
metric-name = #'[a-zA-Z_:]([a-zA-Z0-9_:])*'
label-name = #'[a-zA-Z_]([a-zA-Z0-9_])*'
newline = #'\n'
space = ' '
docstring=<string>
string= #'[^\n]*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment