|
1 | | -from grafanalib.core import ( |
2 | | - Dashboard, |
3 | | - Templating, |
4 | | - Template, |
5 | | - TimeSeries, |
6 | | - Target, |
7 | | - GridPos, |
8 | | - Row, |
9 | | -) |
10 | | -from grafanalib.formatunits import PERCENT_UNIT, SECONDS, NUMBER_FORMAT, TRUE_FALSE |
11 | | - |
12 | | -from common import PROMETHEUS_DATASOURCE_NAME |
13 | | - |
14 | | - |
15 | | -def get_office_card_row(): |
16 | | - return Row( |
17 | | - title="Office Access Card", |
18 | | - panels=[ |
19 | | - TimeSeries( |
20 | | - title="Office Access Card - 200 Responses", |
21 | | - targets=[ |
22 | | - Target( |
23 | | - datasource=PROMETHEUS_DATASOURCE_NAME, |
24 | | - expr='sum(endpoint_hits{route=~"/api/OfficeAccessCard/verify.*", statusCode="200"})', |
25 | | - legendFormat="total", |
26 | | - refId="A", |
27 | | - ), |
28 | | - Target( |
29 | | - datasource=PROMETHEUS_DATASOURCE_NAME, |
30 | | - expr='sum(rate(endpoint_hits{route=~"/api/OfficeAccessCard/verify.*", statusCode="200"}[1h])) * 3600', |
31 | | - legendFormat="dY/dt [hourly]", |
32 | | - refId="B", |
33 | | - ), |
34 | | - ], |
35 | | - ), |
36 | | - TimeSeries( |
37 | | - title="Office Access Card - Non 200 Responses", |
38 | | - targets=[ |
39 | | - Target( |
40 | | - datasource=PROMETHEUS_DATASOURCE_NAME, |
41 | | - expr='sum(endpoint_hits{route=~"/api/OfficeAccessCard/verify.*", statusCode!="200"}) by (statusCode)', |
42 | | - legendFormat="{{statusCode}} total", |
43 | | - refId="A", |
44 | | - ), |
45 | | - Target( |
46 | | - datasource=PROMETHEUS_DATASOURCE_NAME, |
47 | | - expr='sum(rate(endpoint_hits{route=~"/api/OfficeAccessCard/verify.*", statusCode!="200"}[1h])) by (statusCode) * 3600', |
48 | | - legendFormat="{{statusCode}} dY/dt [hourly]", |
49 | | - refId="B", |
50 | | - ), |
51 | | - ], |
52 | | - ), |
53 | | - ], |
54 | | - ) |
55 | | - |
56 | | - |
57 | | -def get_other_row(): |
58 | | - return Row( |
59 | | - title="Endpoint Requests", |
60 | | - panels=[ |
61 | | - TimeSeries( |
62 | | - title="All main-endpoints traffic", |
63 | | - unit=NUMBER_FORMAT, |
64 | | - gridPos=GridPos(h=8, w=12, x=0, y=0), |
65 | | - lineWidth=2, |
66 | | - stacking={"group": "A", "mode": "none"}, |
67 | | - tooltipMode="all", |
68 | | - tooltipSort="desc", |
69 | | - targets=[ |
70 | | - Target( |
71 | | - datasource=PROMETHEUS_DATASOURCE_NAME, |
72 | | - expr='endpoint_hits{route!="/metrics"}', |
73 | | - legendFormat="{{route}} {{method}} {{statusCode}}", |
74 | | - refId="A", |
75 | | - ), |
76 | | - ], |
77 | | - ), |
78 | | - TimeSeries( |
79 | | - title="Account access", |
80 | | - unit=NUMBER_FORMAT, |
81 | | - gridPos=GridPos(h=8, w=12, x=12, y=0), |
82 | | - lineWidth=2, |
83 | | - stacking={"group": "A", "mode": "none"}, |
84 | | - tooltipMode="all", |
85 | | - tooltipSort="desc", |
86 | | - targets=[ |
87 | | - Target( |
88 | | - datasource=PROMETHEUS_DATASOURCE_NAME, |
89 | | - expr='endpoint_hits{route=~"/api/Auth.*"}', |
90 | | - legendFormat="{{route}} {{method}} {{statusCode}}", |
91 | | - refId="A", |
92 | | - ), |
93 | | - ], |
94 | | - ), |
95 | | - TimeSeries( |
96 | | - title="Messaging", |
97 | | - unit=NUMBER_FORMAT, |
98 | | - gridPos=GridPos(h=8, w=12, x=12, y=8), |
99 | | - lineWidth=2, |
100 | | - stacking={"group": "A", "mode": "none"}, |
101 | | - tooltipMode="all", |
102 | | - tooltipSort="desc", |
103 | | - targets=[ |
104 | | - Target( |
105 | | - datasource=PROMETHEUS_DATASOURCE_NAME, |
106 | | - expr='endpoint_hits{route=~"/api/messages/.*"}', |
107 | | - legendFormat="{{route}} {{method}} {{statusCode}}", |
108 | | - refId="A", |
109 | | - ), |
110 | | - ], |
111 | | - ), |
112 | | - ], |
113 | | - ) |
| 1 | +from wrapper import SceGrafanalibWrapper, ExpressionAndLegendPair |
114 | 2 |
|
| 3 | +from grafanalib.formatunits import NUMBER_FORMAT |
115 | 4 |
|
116 | | -dashboard = Dashboard( |
117 | | - title="Clark", |
118 | | - uid="clark", |
119 | | - description="sce club website", |
120 | | - timezone="browser", |
121 | | - rows=[get_office_card_row(), get_other_row()], |
122 | | -).auto_panel_ids() |
| 5 | +wrapper = SceGrafanalibWrapper("Clark") |
| 6 | +wrapper.AddPanel( |
| 7 | + title="Office Access Card - 200 Responses", |
| 8 | + queries=[ |
| 9 | + ExpressionAndLegendPair( |
| 10 | + 'endpoint_hits{route=~"/api/OfficeAccessCard/verify.*", statusCode="200"}', |
| 11 | + "", |
| 12 | + ) |
| 13 | + ], |
| 14 | + dydt=True, |
| 15 | +) |
| 16 | +wrapper.AddPanel( |
| 17 | + title="Office Access Card - Non 200 Responses", |
| 18 | + queries=[ |
| 19 | + ExpressionAndLegendPair( |
| 20 | + 'endpoint_hits{route=~"/api/OfficeAccessCard/verify.*", statusCode!="200"}', |
| 21 | + "{{statusCode}}", |
| 22 | + ) |
| 23 | + ], |
| 24 | + dydt=True, |
| 25 | +) |
| 26 | +wrapper.AddPanel( |
| 27 | + title="All main-endpoints traffic", |
| 28 | + queries=[ |
| 29 | + ExpressionAndLegendPair( |
| 30 | + 'endpoint_hits{route!="/metrics"}', "{{route}} {{method}} {{statusCode}}" |
| 31 | + ) |
| 32 | + ], |
| 33 | + unit=NUMBER_FORMAT, |
| 34 | +) |
| 35 | +wrapper.AddPanel( |
| 36 | + title="Account access", |
| 37 | + queries=[ |
| 38 | + ExpressionAndLegendPair( |
| 39 | + 'endpoint_hits{route=~"/api/Auth.*"}', "{{route}} {{method}} {{statusCode}}" |
| 40 | + ) |
| 41 | + ], |
| 42 | + unit=NUMBER_FORMAT, |
| 43 | +) |
| 44 | +wrapper.AddPanel( |
| 45 | + title="Messaging", |
| 46 | + queries=[ |
| 47 | + ExpressionAndLegendPair( |
| 48 | + 'endpoint_hits{route=~"/api/messages/.*"}', |
| 49 | + "{{route}} {{method}} {{statusCode}}", |
| 50 | + ) |
| 51 | + ], |
| 52 | + unit=NUMBER_FORMAT, |
| 53 | +) |
| 54 | +dashboard = wrapper.Render() |
0 commit comments