summaryrefslogtreecommitdiffstats
path: root/modules/tozt/files/kapacitor/cpu.tick
blob: cc7eb149e9435be6fb97eccaddd29850dc77ad94 (plain) (blame)
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
dbrp "telegraf"."autogen"

var message = '''
{{- if eq .Level "OK" -}}
{{ index .Tags "host" }} is no longer using excessive CPU
{{- else -}}
{{ index .Tags "host" }} is using excessive CPU
{{- end -}}
'''

var details = '''
{{- if eq .Level "OK" -}}
{{ index .Tags "host" }} is now only using {{ index .Fields "mean" }}% CPU
{{- else -}}
{{ index .Tags "host" }} has used an average of {{ index .Fields "mean" }}% CPU for the last 10 minutes
{{- end -}}
'''

stream
|from()
    .measurement('cpu')
    .groupBy('host')
    .where(lambda: "cpu" == 'cpu-total')
|eval(lambda: 100.0 - "usage_idle")
    .as('usage')
|window()
    .period(1h)
|mean('usage')
|alert()
    .crit(lambda: "mean" > 90)
    .message(message)
    .details(details)