Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import json
- f = open('prom.txt')
- metrics = []
- for line in f:
- if line.startswith('#'):
- continue
- metric = {}
- labels = line.split(' ')[0]
- idx = labels.find('{')
- if idx == -1:
- metric['__name__'] = labels
- metrics.append(metric)
- continue
- name = labels[:idx]
- metric['__name__'] = name
- labels = labels[idx+1:len(labels)-1].split(",")
- for label in labels:
- label = label.replace('"', "")
- vals = label.split("=")
- metric[vals[0]] = vals[1]
- metrics.append(metric)
- for metric in metrics:
- print(json.dumps(metric))
Add Comment
Please, Sign In to add comment