Skip to content
Snippets Groups Projects
Commit c9327288 authored by Christoph Alt's avatar Christoph Alt
Browse files

added thresholds for panels

parent 25a3bedc
No related branches found
No related tags found
No related merge requests found
from collections import namedtuple
from dataclasses import dataclass, field
# from collections import namedtuple
from dashboards.influx_queries import Query
from grafanalib.core import TimeSeries, Text, Stat, Template, Repeat, Threshold
from dashboards.dashboard_base import get_influx_target
from dashboards.legends import Units
from numbers import Number
PanelInfos = namedtuple("PanelInfos", ("name", "unit"))
# PanelInfos = namedtuple("PanelInfos", ("name", "unit"))
def get_time_series_panel(field: PanelInfos,
@dataclass
class PanelInfos:
name: str
unit: Units
absthreshold: Number = field(default=None)
def get_time_series_panel(panel_infos: PanelInfos,
data_source: str,
measurment_name: str,
*,
......@@ -16,19 +26,29 @@ def get_time_series_panel(field: PanelInfos,
is_regex = False
if measurment_name[0] == '/' and measurment_name[-1] == '/':
is_regex = True
query = Query(select_=field.name,
query = Query(select_=panel_infos.name,
from_=measurment_name,
where_=where,
group_by=group_by,
from_string=not is_regex)
kwargs = {}
if panel_infos.absthreshold is not None:
kwargs.update({'thresholdType': 'absolute',
'thresholds': [Threshold('green', 0, 0.0),
Threshold('red', index=1, value=float(panel_infos.absthreshold), op='lt'), ],
'thresholdsStyleMode': 'line',
}
)
return TimeSeries(
title=field.name,
title=panel_infos.name,
dataSource=data_source,
targets=[get_influx_target(str(query))],
unit=field.unit,
unit=panel_infos.unit,
pointSize=9,
overrides=overrides,
**kwargs,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment