A Nagios plugin for querying Prometheus.
$ docker run -it claranet/nagitheus:latest -h
This tool has been inspired by the upstream provided shell script to be found here. But unfortunately this shell script is deficient in several ways. Nagitheus instead:
- It actually works :)
- No need to specify if vector or scalar
- It doesn't stop at the first result but iterates over whole vector
- Ability to print desired label
- Go binary: no need of specific software on the nagios monitoring
build:
$ go build nagitheus.go
or from mac to linux
env GOOS=linux GOARCH=amd64 go build nagitheus.go
run:
$ ./nagitheus -H "https://prometheus.example.com" -q "Prometheus Query" -w 2 -c 2 -u username -p PASSWORD -m le -l label
$ go run nagitheus.go -H 'https://prometheus.mgt.domain.com' -q "(kubelet_volume_stats_used_bytes/kubelet_volume_stats_capacity_bytes*100)>2" -w 2 -c 5 -m ge -u UN -p PW -l persistentvolumeclaim
WARNING prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 2.2607424766047886 CRITICAL prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 5.625835543270624
exit status 2
-H string
Host to query (Required, i.e. https://example.prometheus.com)
-q string
Prometheus query (Required)
-w string
Warning treshold (Required)
-c string
Critical treshold (Required)
-d string
Print whole prometheus result to output (Optional) (default "no")
-l string
Label to print (Optional) (default "none")
-m string
Comparison method (Optional) (default "ge")
-u string
Username (Optional)
-p string
Password (Optional)
--critical-on-missing
Return CRITICAL if query results are missing (Optional) (default "no")
This software will perform a request on the prometheus server. Required flags are the Host, Query, Warning and Critical.
-d yes
will print to outputn the whole response from Prometheus (best used from command line and not from Nagios):
Prometheus response: {
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {
"endpoint": "http-metrics",
"exported_namespace": "aux",
"instance": "10.42.0.2:10255",
"job": "kubelet",
"namespace": "kube-system",
"persistentvolumeclaim": "prometheus-kube-prometheus-db-prometheus-kube-prometheus-0",
"service": "kubelet"
},
"value": [
1521551995.114,
"2.2607424766047886"
]
},
{
"metric": {
"endpoint": "http-metrics",
"exported_namespace": "aux",
"instance": "10.42.0.4:10255",
"job": "kubelet",
"namespace": "kube-system",
"persistentvolumeclaim": "prometheus-kube-prometheus-db-prometheus-kube-prometheus-0",
"service": "kubelet"
},
"value": [
1521551995.114,
"5.625835543270624"
]
}
]
}
}
-l labelname
takes a label that you want to print toghether with Status and value:
WARNING prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 2.2607424766047886 CRITICAL prometheus-kube-prometheus-db-prometheus-kube-prometheus-0 is 5.625835543270624
Without the label the result would be
WARNING is 2.2607424766047886 CRITICAL is 5.625835543270624
-m ge OR gt OR le OR lt
tells the check how to compare the result with the critical and warning flags
-u username -p password
when both are set the request will be performed with basic auth