Skip to content

Commit d2e1005

Browse files
authored
remake sceta dashboard w/ wrapper (#26)
1 parent b43a49b commit d2e1005

2 files changed

Lines changed: 37 additions & 95 deletions

File tree

Lines changed: 32 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,35 @@
1-
from grafanalib.core import Dashboard, Templating, Template, TimeSeries, Target, GridPos
2-
from grafanalib.formatunits import PERCENT_UNIT, SECONDS, NUMBER_FORMAT
1+
from wrapper import SceGrafanalibWrapper, ExpressionAndLegendPair
32

4-
from common import PROMETHEUS_DATASOURCE_NAME
3+
from grafanalib.formatunits import SECONDS, NUMBER_FORMAT
54

6-
7-
dashboard = Dashboard(
8-
title='SCEta',
9-
uid='sceta',
10-
description='Transit prediction service metrics',
11-
timezone='browser',
12-
panels=[
13-
TimeSeries(
14-
title='Cache Update Errors',
15-
unit=NUMBER_FORMAT,
16-
gridPos=GridPos(h=8, w=12, x=0, y=0),
17-
lineWidth=2,
18-
stacking={'group': 'A','mode': 'none'},
19-
tooltipMode='all',
20-
tooltipSort='desc',
21-
targets=[
22-
Target(
23-
datasource=PROMETHEUS_DATASOURCE_NAME,
24-
expr='cache_update_errors_total',
25-
legendFormat="__auto",
26-
refId='A',
27-
),
28-
],
29-
),
30-
TimeSeries(
31-
title='HTTP Response Codes',
32-
gridPos=GridPos(h=8, w=12, x=12, y=0),
33-
unit=NUMBER_FORMAT,
34-
lineWidth=2,
35-
tooltipMode='all',
36-
tooltipSort='desc',
37-
targets=[
38-
Target(
39-
datasource=PROMETHEUS_DATASOURCE_NAME,
40-
expr='http_code_total{job=\"sceta-server\", path!=\"/metrics\"}',
41-
legendFormat='{{code}} {{path}}',
42-
refId='A',
43-
),
44-
],
45-
),
46-
TimeSeries(
47-
title='Cache Age',
48-
unit=SECONDS,
49-
gridPos=GridPos(h=8, w=12, x=0, y=8),
50-
lineWidth=2,
51-
tooltipMode='all',
52-
tooltipSort='desc',
53-
targets=[
54-
Target(
55-
datasource=PROMETHEUS_DATASOURCE_NAME,
56-
expr='time() - cache_last_updated',
57-
legendFormat="__auto",
58-
refId='A',
59-
),
60-
],
61-
),
62-
TimeSeries(
63-
title='511 API Response Codes',
64-
gridPos=GridPos(h=8, w=12, x=12, y=8),
65-
unit=NUMBER_FORMAT,
66-
lineWidth=2,
67-
tooltipMode='all',
68-
tooltipSort='desc',
69-
targets=[
70-
Target(
71-
datasource=PROMETHEUS_DATASOURCE_NAME,
72-
expr='api_response_codes_total',
73-
legendFormat="__auto",
74-
refId='A',
75-
),
76-
],
77-
),
78-
TimeSeries(
79-
title='511 API Latency',
80-
gridPos=GridPos(h=8, w=12, x=0, y=16),
81-
unit=SECONDS,
82-
lineWidth=2,
83-
tooltipMode='all',
84-
tooltipSort='desc',
85-
targets=[
86-
Target(
87-
datasource=PROMETHEUS_DATASOURCE_NAME,
88-
expr='api_latency_sum / api_latency_count',
89-
legendFormat="__auto",
90-
refId='A',
91-
),
92-
],
93-
),
5+
wrapper = SceGrafanalibWrapper("SCEta")
6+
wrapper.AddPanel(
7+
"Cache Update Errors",
8+
[ExpressionAndLegendPair("cache_update_errors_total", "__auto")],
9+
NUMBER_FORMAT,
10+
)
11+
wrapper.AddPanel(
12+
"HTTP Response Codes",
13+
[
14+
ExpressionAndLegendPair(
15+
'http_code_total{job="sceta-server", path!="/metrics"}', "{{code}} {{path}}"
16+
)
9417
],
95-
).auto_panel_ids()
18+
NUMBER_FORMAT,
19+
)
20+
wrapper.AddPanel(
21+
"Cache Age",
22+
[ExpressionAndLegendPair("time() - cache_last_updated", "__auto")],
23+
SECONDS,
24+
)
25+
wrapper.AddPanel(
26+
"511 API Response Codes",
27+
[ExpressionAndLegendPair("api_response_codes_total", "__auto")],
28+
NUMBER_FORMAT,
29+
)
30+
wrapper.AddPanel(
31+
"511 API Latency",
32+
[ExpressionAndLegendPair("api_latency_sum / api_latency_count", "__auto")],
33+
SECONDS,
34+
)
35+
dashboard = wrapper.Render()

grafana/provisioning/dashboards/wrapper.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, title, panel_width=12, panel_height=8):
3636
self.panel_width = min(panel_width, self.MAX_WIDTH)
3737
self.panel_height = panel_height
3838

39-
def AddPanel(self, title, queries: list[ExpressionAndLegendPair]):
39+
def AddPanel(self, title, queries: list[ExpressionAndLegendPair], unit):
4040
targets = []
4141
iterator = RefIdGenerator()
4242
for query in queries:
@@ -61,14 +61,16 @@ def AddPanel(self, title, queries: list[ExpressionAndLegendPair]):
6161
x=self.current_x,
6262
y=self.current_y,
6363
),
64+
lineWidth=2,
65+
unit=unit
6466
)
6567
)
6668
self.current_x += self.panel_width
67-
if self.current_x >= self.MAX_WIDTH / 2:
69+
if self.current_x > self.MAX_WIDTH / 2:
6870
self.current_y += self.panel_height
6971
self.current_x = 0
7072

7173
def Render(self):
7274
return Dashboard(
73-
title=self.title, rows=self.rows, panels=self.panels
75+
title=self.title, rows=self.rows, panels=self.panels, timezone='browser'
7476
).auto_panel_ids()

0 commit comments

Comments
 (0)