Skip to content

Instantly share code, notes, and snippets.

@matthewoliver
Last active January 27, 2021 02:03
Show Gist options
  • Save matthewoliver/75fd90db06feea53cf56decfcae4a6ec to your computer and use it in GitHub Desktop.
Save matthewoliver/75fd90db06feea53cf56decfcae4a6ec to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from graphviz import Graph
import sys
import time
import re
from collections import OrderedDict
from hashlib import md5
graph = Graph("config_info")
GROK_START = "Name: "
GROK_END = "Meta Timestamp: "
record_started = False
records = []
record = []
try:
for line in sys.stdin:
line = line.strip()
if line.startswith(GROK_START):
record_started = True
elif line.startswith(GROK_END):
record.append(line)
records.append(record)
record = []
record_started = False
if record_started:
record.append(line)
except Exception as ex:
print(str(ex))
finally:
sys.stdin.flush()
sys.stdin.close()
pattern = ('(Name:|lower:|upper:|Object Count:|Bytes Used:|'
'State:|Created at:|Meta Timestamp:)')
for record in records:
pairs = re.split(pattern, "\n".join(record))[1:]
rec_dict = OrderedDict((pairs[i*2], pairs[i*2+1]) for i in range(8))
# some cleanups
for comma in ('lower:', 'Object Count:', 'Bytes Used:'):
if rec_dict[comma].strip().endswith(','):
rec_dict[comma] = rec_dict[comma].strip()[:-1]
print(comma + " " + rec_dict[comma])
if rec_dict['lower:'] == "''":
rec_dict["lower:"] = "MIN"
if rec_dict['upper:'] == "''":
rec_dict["upper:"] = "MAX"
lower_key = md5(rec_dict['lower:'].strip().encode('utf-8')).hexdigest()
upper_key = md5(rec_dict['upper:'].strip().encode('utf-8')).hexdigest()
graph.node(lower_key, label=rec_dict["lower:"].strip())
graph.node(upper_key, label=rec_dict["upper:"].strip())
edge_name = '%s %s' % (rec_dict['Name:'], rec_dict['Object Count:'])
graph.edge(lower_key, upper_key, edge_name)
graph.render("{}-{}.gv".format("container_info", time.time()),
view=True, format='svg')
@matthewoliver
Copy link
Author

Thanks to clay's tip on the label to allow ':'s and also adding the shard name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment