summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-07-05 04:12:44 -0400
committerJesse Luehrs <doy@tozt.net>2020-07-05 04:58:17 -0400
commit9fbae5055d5bc5966167d7da652627728c71bb06 (patch)
tree2d844d414fa1e1e5752b8ce655178a20617ce9c6 /modules
parentf5d1b69f90a73b1c88c8fd9b33ce3a92fcb6611b (diff)
downloadpuppet-tozt-9fbae5055d5bc5966167d7da652627728c71bb06.tar.gz
puppet-tozt-9fbae5055d5bc5966167d7da652627728c71bb06.zip
add cpu usage alert
Diffstat (limited to 'modules')
-rw-r--r--modules/tozt/files/kapacitor/cpu.tick32
-rw-r--r--modules/tozt/manifests/tick.pp2
2 files changed, 34 insertions, 0 deletions
diff --git a/modules/tozt/files/kapacitor/cpu.tick b/modules/tozt/files/kapacitor/cpu.tick
new file mode 100644
index 0000000..821ebb4
--- /dev/null
+++ b/modules/tozt/files/kapacitor/cpu.tick
@@ -0,0 +1,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(10m)
+|mean('usage')
+|alert()
+ .crit(lambda: "mean" > 90)
+ .message(message)
+ .details(details)
diff --git a/modules/tozt/manifests/tick.pp b/modules/tozt/manifests/tick.pp
index d7bef74..39b341d 100644
--- a/modules/tozt/manifests/tick.pp
+++ b/modules/tozt/manifests/tick.pp
@@ -4,6 +4,8 @@ class tozt::tick {
tick::server::kapacitor::alert {
"deadman":
source => 'puppet:///modules/tozt/kapacitor/deadman.tick';
+ "cpu":
+ source => 'puppet:///modules/tozt/kapacitor/cpu.tick';
}
secret {