every libs/*.py and hooks/*.py now starts with a one-line module docstring; every bin/* script starts with a `# purpose:` header. discovery-by-`ls`-and-read instead of by index. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
829 B
Python
31 lines
829 B
Python
"""grafana: panel and Flux-query generators for Mako-templated dashboards under data/grafana/rows/."""
|
|
|
|
from mako.template import Template
|
|
from copy import deepcopy
|
|
|
|
|
|
def generate_flux(bucket, host, field, data):
|
|
return Template(flux_template).render(
|
|
bucket=bucket,
|
|
host=host,
|
|
field=field,
|
|
data=data
|
|
).strip()
|
|
|
|
|
|
def generate_panel(bucket, host, title, targets, min=None, max=None):
|
|
panel = deepcopy(panel_template)
|
|
panel['title'] = title
|
|
|
|
if min:
|
|
panel['fieldConfig']['defaults']['min'] = min
|
|
if max:
|
|
panel['fieldConfig']['defaults']['max'] = max
|
|
|
|
panel['targets'] = [
|
|
{
|
|
'hide': False,
|
|
'refId': field,
|
|
'query': generate_flux(bucket, host, field, data),
|
|
} for field, data in targets.items()
|
|
]
|