koder aka kdanilov | a639e0a | 2015-03-17 15:30:36 +0200 | [diff] [blame] | 1 | import json |
| 2 | |
| 3 | |
| 4 | query = """ |
| 5 | select value from "{series}" |
| 6 | where $timeFilter and |
| 7 | host='{host}' and device='{device}' |
| 8 | order asc |
| 9 | """ |
| 10 | |
| 11 | |
| 12 | def make_dashboard_file(config): |
| 13 | series = ['writes_completed', 'sectors_written'] |
| 14 | dashboards = [] |
| 15 | |
| 16 | for serie in series: |
| 17 | dashboard = dict(title=serie, type='graph', |
| 18 | span=12, fill=1, linewidth=2, |
| 19 | tooltip={'shared': True}) |
| 20 | |
| 21 | targets = [] |
| 22 | |
| 23 | for ip, devs in config.items(): |
| 24 | for device in devs: |
| 25 | params = { |
| 26 | 'series': serie, |
| 27 | 'host': ip, |
| 28 | 'device': device |
| 29 | } |
| 30 | |
| 31 | target = dict( |
| 32 | target="disk io", |
| 33 | query=query.replace("\n", " ").format(**params).strip(), |
| 34 | interval="", |
| 35 | alias="{0} io {1}".format(ip, device), |
| 36 | rawQuery=True |
| 37 | ) |
| 38 | targets.append(target) |
| 39 | |
| 40 | dashboard['targets'] = targets |
| 41 | dashboards.append(dashboard) |
| 42 | |
| 43 | fc = open("grafana_template.js").read() |
| 44 | return fc % (json.dumps(dashboards),) |
| 45 | |
| 46 | |
| 47 | print make_dashboard_file({'192.168.0.104': ['sda1', 'rbd1']}) |