Skip to content

Instantly share code, notes, and snippets.

@christophschubert
Created August 1, 2025 11:48
Show Gist options
  • Select an option

  • Save christophschubert/9387211d9bde6388ddd75e4ee83e1d81 to your computer and use it in GitHub Desktop.

Select an option

Save christophschubert/9387211d9bde6388ddd75e4ee83e1d81 to your computer and use it in GitHub Desktop.
Parse metrics output in Prometheus exposition format using Python and print metrics and labels.
import sys
seen = set()
for line in sys.stdin:
if not line.startswith('#'):
name, _, rest = line.partition('{')
kvStrings = rest.split(',')[:-1]
labels = [p.split('=')[0] for p in kvStrings]
if not name in seen:
seen.add(name)
# print(name, labels)
print(name)
for l in labels:
print('\t' + l)%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment