2021-05-02 08:44:50 +00:00
|
|
|
from itertools import count
|
|
|
|
from os.path import join
|
|
|
|
from pathlib import Path
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from bundlewrap.metadata import metadata_to_json
|
|
|
|
|
|
|
|
for row in Path(join(repo.path, 'bundles', 'grafana', 'dashboard-rows')).rglob("*.py"):
|
|
|
|
with open(row, 'r') as f:
|
|
|
|
exec(f.read())
|
|
|
|
|
|
|
|
directories = {
|
|
|
|
'/etc/grafana/provisioning/dashboards': {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/datasources': {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/notifiers': {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/plugins': {
|
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/var/lib/grafana/dashboards': {
|
|
|
|
'purge': True,
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
files = {
|
|
|
|
'/etc/grafana/grafana.ini': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': node.metadata['grafana'],
|
|
|
|
'owner': 'grafana',
|
|
|
|
'mode': '0640',
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/dashboards/bundlewrap.yaml': {
|
|
|
|
'source': 'dashboards.yaml',
|
|
|
|
'owner': 'grafana',
|
|
|
|
'mode': '0640',
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
|
|
|
'grafana-server': {
|
|
|
|
'needs': {
|
|
|
|
'file:/etc/grafana/grafana.ini',
|
|
|
|
'pkg_apt:grafana',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
### dashboard management starts here
|
|
|
|
for rnode in repo.nodes:
|
|
|
|
if not rnode.has_bundle('telegraf'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
panel_id = count(start=1)
|
|
|
|
dashboard = {
|
|
|
|
'title': rnode.name,
|
|
|
|
'uid': UUID(int=rnode.magic_number).hex[:10],
|
|
|
|
|
|
|
|
'editable': False,
|
|
|
|
'graphTooltip': 1,
|
|
|
|
'refresh': '30s',
|
|
|
|
'schemaVersion': 12,
|
|
|
|
'style': 'dark',
|
|
|
|
'tags': {'bw'},
|
|
|
|
'time': {
|
|
|
|
'from': 'now-1d',
|
|
|
|
'to': 'now'
|
|
|
|
},
|
|
|
|
'version': 1,
|
|
|
|
|
|
|
|
'rows': [
|
|
|
|
dashboard_row_cpu(panel_id, rnode),
|
|
|
|
dashboard_row_ip_traffic(panel_id, rnode),
|
|
|
|
dashboard_row_memory(panel_id, rnode),
|
|
|
|
dashboard_row_disk_space(panel_id, rnode),
|
|
|
|
dashboard_row_disk_iops(panel_id, rnode),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:34:55 +00:00
|
|
|
if rnode.has_bundle('nginx'):
|
|
|
|
dashboard['rows'].append(dashboard_row_nginx(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('nginx')
|
|
|
|
|
2021-05-02 09:55:34 +00:00
|
|
|
if rnode.has_bundle('postfix'):
|
|
|
|
dashboard['rows'].append(dashboard_row_postfix(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('postfix')
|
|
|
|
|
2021-05-02 08:44:50 +00:00
|
|
|
files[f'/var/lib/grafana/dashboards/{rnode.name}.json'] = {
|
|
|
|
# use metadata_to_json, because this supports sets
|
|
|
|
'content': metadata_to_json(dashboard),
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
}
|