I have a simple pod with a nginx container which returns text healthy
on path /
. I have prometheus to scrape port 80 on path /
. When I ran up == 0
in the prometheus dashboard it showed this pod which means this pod is not healthy. But I tried ssh into the container, it was running fine and I saw in the nginx log prometheus was pinging /
and getting 200 response. Any idea why?
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
...
template:
metadata:
labels:
...
annotations:
prometheus.io/scrape: "true"
prometheus.io/path: "/"
prometheus.io/port: "80"
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: nginx-conf
mountPath: /etc/nginx
readOnly: true
ports:
- containerPort: 80
volumes:
- name: nginx-conf
configMap:
name: nginx-conf
items:
- key: nginx.conf
path: nginx.conf
nginx.conf
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
http {
server {
listen 80;
location / {
return 200 'healthyn';
}
}
}
nginx access log
192.168.88.81 - - [xxx +0000] "GET / HTTP/1.1" 200 8 "-" "Prometheus/2.26.0"
192.168.88.81 - - [xxx +0000] "GET / HTTP/1.1" 200 8 "-" "Prometheus/2.26.0"
192.168.88.81 - - [xxx +0000] "GET / HTTP/1.1" 200 8 "-" "Prometheus/2.26.0"
2
Answers
When you configure these annotations to pods, the Prometheus expects that the given path returns Prometheus-readable metrics. But
'healthyn'
is not a valid Prometheus metrics type.Recommended Fix:
Now, try querying
nginx_up
from Prometheus. The nginx-prometheus-exporter also comes with a grafana dashboard, you can also give it a try.When Prometheus scrapes an endpoint it expects metrics. Typical metrics look like this:
"healthy"
doesn’t meet the standard and thus it causes Prometheus to fail on scraping this target. There is the blackbox exporter, which is designed to check endpoints from users perspective (this is what black box monitoring is). The exporter can perform HTTP requests and make metrics of the results. For example it can check whether the response code was 200, or if the response body contains certain text. Here are sample metrics returned by this exporter (noteprobe_success
, this is the same asup
):