-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.libsonnet
185 lines (160 loc) · 7.1 KB
/
queries.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet';
local prometheusQuery = g.query.prometheus;
local variables = import './variables.libsonnet';
// TODO: move into "telegraf' parent key.
{
cpuUsage(type, legend=null, cpu='$%s' % variables.cpu.name):
prometheusQuery.new(
'$' + variables.datasource.name,
'cpu_usage_%s{job="telegraf", host="$%s", cpu="%s"}' % [type, variables.host.name, cpu]
)
+ prometheusQuery.withRefId(type)
+ prometheusQuery.withLegendFormat(if legend != null then legend else type),
diskUsage(type, legend=null):
prometheusQuery.new(
'$' + variables.datasource.name,
'disk_%s{job="telegraf", host="$%s", path="$%s"}' % [type, variables.host.name, variables.mountpoint.name]
)
+ prometheusQuery.withRefId(type)
+ prometheusQuery.withLegendFormat(if legend != null then legend else type),
diskQueueDepth(id):
prometheusQuery.new(
'$' + variables.datasource.name,
'rate(diskio_weighted_io_time{job="telegraf", host="$%s", name=~"$%s"}[$__rate_interval]) / 1000' % [variables.host.name, variables.disk.name]
)
+ prometheusQuery.withRefId(id)
+ prometheusQuery.withLegendFormat('{{name}}'),
diskLatency(type):
prometheusQuery.new(
'$' + variables.datasource.name,
'rate(diskio_%s_time{job="telegraf", host="$%s", name=~"$%s"}[$__rate_interval]) / rate(diskio_%ss{job="telegraf", host="$%s", name=~"$%s"}[$__rate_interval])' % [type, variables.host.name, variables.disk.name, type, variables.host.name, variables.disk.name]
)
+ prometheusQuery.withRefId(type)
+ prometheusQuery.withLegendFormat('{{name}}'),
diskIops(type):
prometheusQuery.new(
'$' + variables.datasource.name,
'rate(diskio_%ss{job="telegraf", host="$%s", name=~"$%s"}[$__rate_interval])' % [type, variables.host.name, variables.disk.name]
)
+ prometheusQuery.withRefId(type)
+ prometheusQuery.withLegendFormat('{{name}}'),
diskThroughput(type):
prometheusQuery.new(
'$' + variables.datasource.name,
'rate(diskio_%s_bytes{job="telegraf", host="$%s", name=~"$%s"}[$__rate_interval])' % [type, variables.host.name, variables.disk.name]
)
+ prometheusQuery.withRefId(type)
+ prometheusQuery.withLegendFormat('{{name}}'),
hostMetric(metric, id, legend=null):
prometheusQuery.new(
'$' + variables.datasource.name,
'%s{job="telegraf", host="$%s"}' % [metric, variables.host.name]
)
+ prometheusQuery.withRefId(id)
+ prometheusQuery.withLegendFormat(if legend != null then legend else id),
hostRateMetric(metric, id, legend=null):
prometheusQuery.new(
'$' + variables.datasource.name,
'rate(%s{job="telegraf", host="$%s"}[$__rate_interval])' % [metric, variables.host.name]
)
+ prometheusQuery.withRefId(id)
+ prometheusQuery.withLegendFormat(if legend != null then legend else id),
networkRateMetric(metric):
prometheusQuery.new(
'$' + variables.datasource.name,
'rate(net_%s{job="telegraf", host="$%s", interface=~"$%s"}[$__rate_interval])' % [metric, variables.host.name, variables.interface.name]
)
+ prometheusQuery.withRefId(metric)
+ prometheusQuery.withLegendFormat('{{interface}}'),
uptime(id):
prometheusQuery.new(
'$' + variables.datasource.name,
'system_uptime{job="telegraf", host="$%s"}' % [variables.host.name]
)
+ prometheusQuery.withRefId(id),
diskUsagePercentInstant(id):
prometheusQuery.new(
'$' + variables.datasource.name,
// Keep value and the path label only,
'max by (path) (disk_used_percent{job="telegraf", host="$%s", path=~"$%s"})' % [variables.host.name, variables.mountpoint.name]
)
+ prometheusQuery.withInstant(true)
+ prometheusQuery.withFormat('table')
+ prometheusQuery.withRefId(id),
mdAllArraysActive(id):
prometheusQuery.new(
'$' + variables.datasource.name,
|||
count(mdstat_DisksTotal{job="telegraf", host="$%(hostvar)s", ActivityState=~"active|checking"}) OR vector(0)
/ count(mdstat_DisksTotal{job="telegraf", host="$%(hostvar)s"})
||| % { hostvar: variables.hostWithMdArrays.name }
)
+ prometheusQuery.withInstant(true)
+ prometheusQuery.withRefId(id),
mdAllArrayMembersActive(id):
prometheusQuery.new(
'$' + variables.datasource.name,
|||
sum without (Name, ActivityState) (mdstat_DisksActive{job="telegraf", host="$%(hostvar)s"})
/ sum without (Name, ActivityState) (mdstat_DisksTotal{job="telegraf", host="$%(hostvar)s"})
||| % { hostvar: variables.hostWithMdArrays.name }
)
+ prometheusQuery.withInstant(true)
+ prometheusQuery.withRefId(id),
mdTotalArrays(id):
prometheusQuery.new(
'$' + variables.datasource.name,
|||
count(mdstat_DisksTotal{job="telegraf", host="$%(hostvar)s"})
||| % { hostvar: variables.hostWithMdArrays.name }
)
+ prometheusQuery.withInstant(true)
+ prometheusQuery.withRefId(id)
+ prometheusQuery.withLegendFormat('total arrays'),
mdMetric(metric, id, legend=null):
prometheusQuery.new(
'$' + variables.datasource.name,
'mdstat_%s{job="telegraf", Name=~"$%s", host="$%s"}' % [metric, variables.mdArray.name, variables.hostWithMdArrays.name]
)
+ prometheusQuery.withRefId(id)
+ prometheusQuery.withLegendFormat(if legend != null then legend else id),
mdStatelessMetric(metric, id, legend=null):
prometheusQuery.new(
'$' + variables.datasource.name,
'max(mdstat_%s{job="telegraf", Name=~"$%s", host="$%s"}) without (ActivityState)' % [metric, variables.mdArray.name, variables.hostWithMdArrays.name]
)
+ prometheusQuery.withRefId(id)
+ prometheusQuery.withLegendFormat(if legend != null then legend else id),
mdArrayState(id):
self.mdMetric('DisksTotal', id, '{{ActivityState}}')
+ prometheusQuery.withInstant(true),
mdActiveArrayMembers(id, legend=null):
self.mdMetric('DisksActive', id, legend)
+ prometheusQuery.withInstant(true),
mdTotalArrayMembers(id, legend=null):
self.mdMetric('DisksTotal', id, legend)
+ prometheusQuery.withInstant(true),
mdFailedArrayMembers(id):
self.mdMetric('DisksFailed', id)
+ prometheusQuery.withInstant(true),
mdSyncFinishTime(id):
prometheusQuery.new(
'$' + variables.datasource.name,
'mdstat_BlocksSyncedFinishTime{job="telegraf", Name=~"$%s", host="$%s", ActivityState!="active"}' % [variables.mdArray.name, variables.hostWithMdArrays.name]
)
+ prometheusQuery.withInstant(true)
+ prometheusQuery.withRefId(id),
mdSyncSpeed(id):
prometheusQuery.new(
'$' + variables.datasource.name,
'mdstat_BlocksSyncedSpeed{job="telegraf", Name=~"$%s", host="$%s", ActivityState!="active"}' % [variables.mdArray.name, variables.hostWithMdArrays.name]
)
+ prometheusQuery.withRefId(id),
mdBlockSyncedPercentage(id):
prometheusQuery.new(
'$' + variables.datasource.name,
'mdstat_BlocksSyncedPct{job="telegraf", Name=~"$%s", host="$%s"} > 0' % [variables.mdArray.name, variables.hostWithMdArrays.name]
)
+ prometheusQuery.withInstant(true)
+ prometheusQuery.withRefId(id),
}