Created
August 1, 2025 11:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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