Created
September 2, 2014 13:12
-
-
Save mvintila/70141f7afdb2887a2186 to your computer and use it in GitHub Desktop.
Grafana dashboard generator
This file contains 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
#!/usr/bin/python | |
import json | |
import sys | |
import re | |
import copy | |
prefix = 'servers' | |
names = sys.argv[2:] | |
file = open(sys.argv[1], 'r') | |
dash = json.load(file) | |
initial_row = dash['rows'][0] | |
rows = [] | |
dash['rows'] = rows | |
for name in names: | |
row = copy.deepcopy(initial_row) | |
for panel in row['panels']: | |
for target in panel['targets']: | |
target['target'] = re.sub('%s\.[a-zA-Z0-9-_]+\.' % prefix, '%s.%s.' % (prefix, name), target['target']) | |
panel['title'] = name | |
rows.append(row) | |
print json.dumps(dash, sort_keys=True, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment