-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathdashboards.libsonnet
103 lines (100 loc) · 4.39 KB
/
dashboards.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
local g = import './g.libsonnet';
local logslib = import 'logs-lib/logs/main.libsonnet';
{
local root = self,
new(this):
local prefix = this.config.dashboardNamePrefix;
local links = this.grafana.links;
local tags = this.config.dashboardTags;
local uid = g.util.string.slugify(this.config.uid);
local vars = this.grafana.variables;
local annotations = this.grafana.annotations;
local refresh = this.config.dashboardRefresh;
local period = this.config.dashboardPeriod;
local timezone = this.config.dashboardTimezone;
local panels = this.grafana.panels;
local stat = g.panel.stat;
{
'fleet.json':
g.dashboard.new(prefix + 'Helloworld fleet')
+ g.dashboard.withPanels(
// wrapPanels returns an array of panels organized in a grid,
// wrapping up to next 'row' if total width exceeds full grid of 24 columns.
// 'panelHeight' and 'panelWidth' are used unless panels already have height and width defined.
// https://grafana.github.io/grafonnet/API/util.html#fn-gridwrappanels
g.util.grid.wrapPanels(this.grafana.rows.fleet, 12, 7)
)
// hide link to self
+ root.applyCommon(vars.multiInstance, uid + '-fleet', tags, links { backToFleet+:: {}, backToOverview+:: {} }, annotations, timezone, refresh, period),
'overview.json':
g.dashboard.new(prefix + 'Helloworld overview')
+ g.dashboard.withPanels(
g.util.grid.wrapPanels(
std.flattenArrays([
this.grafana.rows.overview_1,
this.grafana.rows.overview_2,
this.grafana.rows.overview_3,
this.grafana.rows.overview_4,
this.grafana.rows.overview_5,
]), 6, 2
)
)
+ root.applyCommon(vars.singleInstance, uid + '-overview', tags, links { backToOverview+:: {} }, annotations, timezone, refresh, period),
'dashboard3.json':
g.dashboard.new(prefix + 'Helloworld dashboard 3')
+ g.dashboard.withPanels(
g.util.grid.wrapPanels(
this.grafana.rows.dashboard_3_row, 12, 8
)
)
+ root.applyCommon(vars.singleInstance, uid + '-dashboard3', tags, links, annotations, timezone, refresh, period),
}
+
if this.config.enableLokiLogs
then
{
logs:
logslib.new(prefix + 'Hello world logs',
datasourceName=this.grafana.variables.datasources.loki.name,
datasourceRegex=this.grafana.variables.datasources.loki.regex,
filterSelector=this.config.filteringSelector,
labels=this.config.groupLabels + this.config.instanceLabels + this.config.extraLogLabels,
formatParser=null,
showLogsVolume=this.config.showLogsVolume,
logsVolumeGroupBy=this.config.logsVolumeGroupBy,
extraFilters=this.config.logsExtraFilters)
{
dashboards+:
{
logs+:
// reference to self, already generated variables, to keep them, but apply other common data in applyCommon
root.applyCommon(super.logs.templating.list, uid=uid + '-logs', tags=tags, links=links, annotations=annotations, timezone=timezone, refresh=refresh, period=period),
},
panels+:
{
// modify log panel
logs+:
g.panel.logs.options.withEnableLogDetails(true)
+ g.panel.logs.options.withShowTime(false)
+ g.panel.logs.options.withWrapLogMessage(false),
},
variables+: {
// add prometheus datasource for annotations processing
toArray+: [
this.grafana.variables.datasources.prometheus { hide: 2 },
],
},
}.dashboards.logs,
}
else {},
//Apply common options(uids, tags, annotations etc..) to all dashboards above
applyCommon(vars, uid, tags, links, annotations, timezone, refresh, period):
g.dashboard.withTags(tags)
+ g.dashboard.withUid(uid)
+ g.dashboard.withLinks(std.objectValues(links))
+ g.dashboard.withTimezone(timezone)
+ g.dashboard.withRefresh(refresh)
+ g.dashboard.time.withFrom(period)
+ g.dashboard.withVariables(vars)
+ g.dashboard.withAnnotations(std.objectValues(annotations)),
}