-
Notifications
You must be signed in to change notification settings - Fork 157
/
influxdb2_cardinality_now.yml
285 lines (269 loc) · 8.33 KB
/
influxdb2_cardinality_now.yml
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
apiVersion: influxdata.com/v2alpha1
kind: Label
metadata:
name: determined-torvalds-b69001
spec:
color: '#fafafc'
name: cardinality
---
apiVersion: influxdata.com/v2alpha1
kind: Task
metadata:
name: unruffled-sinoussi-769001
spec:
associations:
- kind: Label
name: determined-torvalds-b69001
every: 1h
name: 'Cardinality Alert '
offset: 5m0s
query: |-
import "influxdata/influxdb"
import "slack"
// TODO: create a slack notification endpoint and paste link here
// documentation: https://docs.influxdata.com/influxdb/v2.0/monitor-alert/notification-endpoints/create/
slackWebhook = "https://hooks.slack.com/services/XXXX/XXXX/XXXXX"
// TODO: specify the channel based on the webhook
slackChannel = "##"
// default cardinality
cardinalityThreshold = 1000000
alert = (bucketCard, bucketName) =>
(if bucketCard >= cardinalityThreshold then () =>
(slack.message(
url: slackWebhook,
channel: slackChannel,
text: "${bucketName} cardinality at ${string(v: bucketCard)}!",
color: "warning",
)) else () =>
(0))
buckets()
|> map(fn: (r) => {
cards = influxdb.cardinality(start: -task.every, bucket: r.name)
|> findRecord(idx: 0, fn: (key) =>
(true))
result = alert(bucketCard: cards._value, bucketName: r.name)
return {r with card: cards._value, sent: result()}
})
status: inactive
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name: admiring-fermat-b69007
spec:
associations:
- kind: Label
name: determined-torvalds-b69001
language: flux
name: measurement
query: |-
import "influxdata/influxdb/v1"
v1.measurements(bucket: v.bucket)
type: query
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name: vivid-aryabhata-b69003
spec:
associations:
- kind: Label
name: determined-torvalds-b69001
language: flux
name: bucket
query: |-
buckets()
|> filter(fn: (r) => r.name !~ /^_/)
|> rename(columns: {name: "_value"})
|> keep(columns: ["_value"])
type: query
---
apiVersion: influxdata.com/v2alpha1
kind: Dashboard
metadata:
name: elated-mirzakhani-f69001
spec:
associations:
- kind: Label
name: determined-torvalds-b69001
charts:
- axes:
- base: "10"
name: x
scale: linear
- base: "10"
name: y
scale: linear
colors:
- hex: '#31C0F6'
id: 5b3aea53-4f8a-47e5-bda3-3e9299df5fa1
name: Nineteen Eighty Four
type: scale
- hex: '#A500A5'
id: e8fec99c-5ff4-43aa-b30a-d3c88d343fb9
name: Nineteen Eighty Four
type: scale
- hex: '#FF7E27'
id: 3f9c84bb-6dfa-42e3-aa35-2e87e6a88842
name: Nineteen Eighty Four
type: scale
geom: line
height: 4
hoverDimension: auto
kind: Xy
legendOpacity: 1
legendOrientationThreshold: 10
name: Cardinality Per Bucket
position: overlaid
queries:
- query: |-
import "influxdata/influxdb"
import "experimental"
time = experimental.subDuration(
d: v.timeRangeStart,
from: now(),
)
buckets()
|> map(fn: (r) => {
cardinality = influxdb.cardinality(bucket: r.name, start: -7d)
|> findRecord(idx: 0, fn: (key) =>
(true))
return {
_time: time,
_measurement: "buckets",
bucket: r.name,
_field: "cardinality",
_value: cardinality._value,
}
})
|> group(columns: ["bucket"], mode:"by")
width: 12
xCol: _time
yCol: _value
- colors:
- hex: '#ffffff'
id: base
name: white
type: text
fieldOptions:
- displayName: _field
fieldName: _field
- displayName: _measurement
fieldName: _measurement
- displayName: _time
fieldName: _time
- displayName: bucket
fieldName: bucket
visible: true
- displayName: _value
fieldName: _value
visible: true
height: 4
kind: Table
name: Top 10 Buckets
queries:
- query: |-
import "influxdata/influxdb"
import "experimental"
time = experimental.subDuration(
d: v.timeRangeStart,
from: now(),
)
buckets()
|> map(fn: (r) => {
cardinality = influxdb.cardinality(bucket: r.name, start: -7d)
|> findRecord(idx: 0, fn: (key) =>
(true))
return {
_time: time,
_measurement: "buckets",
bucket: r.name,
_field: "cardinality",
_value: cardinality._value,
}
})
|> group(columns: ["bucket"], mode:"by")
|> last()
|> group()
|> top(n:10)
tableOptions:
verticalTimeAxis: true
timeFormat: YYYY-MM-DD HH:mm:ss
width: 12
yPos: 4
- colors:
- hex: '#ffffff'
id: base
name: white
type: text
fieldOptions:
- displayName: bucket
fieldName: bucket
visible: true
- displayName: measurement
fieldName: measurement
visible: true
- displayName: cardinality
fieldName: _value
visible: true
height: 3
kind: Table
name: Cardinality By Mesurement
queries:
- query: |-
import "influxdata/influxdb"
import "influxdata/influxdb/schema"
schema.measurements(bucket: v.bucket, start: v.timeRangeStart)
|> map(fn: (r) => {
m = r._value
return {
bucket: v.bucket,
measurement: m,
_value: (influxdb.cardinality(bucket: v.bucket, start: v.timeRangeStart, predicate: (r) => r._measurement == m) |> findRecord(idx:0, fn:(key) => true))._value
}
})
|> sort(desc:true)
tableOptions:
verticalTimeAxis: true
timeFormat: YYYY-MM-DD HH:mm:ss
width: 12
yPos: 8
- colors:
- hex: '#ffffff'
id: base
name: white
type: text
fieldOptions:
- displayName: tag
fieldName: tag
visible: true
- displayName: cardinality
fieldName: _value
visible: true
height: 3
kind: Table
name: Cardinality By Tag
queries:
- query: |-
import "influxdata/influxdb/schema"
cardinalityByTag = (bucket, measurement) => schema.tagKeys(bucket: bucket, predicate: (r) => r._measurement == measurement)
|> filter(fn: (r) => r._value != "_start" and r._value != "_stop")
|> map(
fn: (r) => ({
tag: r._value,
_value: (schema.tagValues(bucket: bucket, tag: r._value)
|> count()
|> findRecord(fn: (key) => true, idx: 0))._value,
}),
)
|> group(columns: ["tag"])
|> sum()
cardinalityByTag(bucket: v.bucket, measurement: v.measurement)
|> group()
|> top(n: 10)
tableOptions:
verticalTimeAxis: true
timeFormat: YYYY-MM-DD HH:mm:ss
width: 12
yPos: 11
name: Cardinality Now