Skip to content

Instantly share code, notes, and snippets.

@replay
Created March 18, 2020 21:06
Show Gist options
  • Save replay/e88ca1695818f52fff8dc52ac0cd2cde to your computer and use it in GitHub Desktop.
Save replay/e88ca1695818f52fff8dc52ac0cd2cde to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import fileinput
data_points_by_id = {}
metric_names_by_id = {}
# that's expecting the output of
# MT_KAFKA_MDM_IN_OFFSET=newest time mt-kafka-mdm-sniff -format-md '{{.OrgId}} {{.Id}} {{.Name}} {{.Tags}} {{.Time}}' -format-point '{.MKey}} {{.Time}}'
for line in fileinput.input():
line = line.rstrip()
splits = line.split(' ')
if len(splits) == 2:
id = splits[0]
time = splits[1]
elif len(splits) == 5:
id = splits[1]
name = splits[2]
tags = splits[3]
time = splits[4]
metric_names_by_id[id] = name
else:
print('invalid line: {line}'.format(line=line))
continue
data_points_by_id[id] = data_points_by_id.get(id, 0) + 1
ids = list(data_points_by_id.keys())
ids.sort(key=lambda id: data_points_by_id[id], reverse=False)
for id in ids:
print('count: {count} metric: {metric}'.format(count=data_points_by_id[id], metric=metric_names_by_id.get(id, id)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment