Reputation: 2438
My application has a /health
Http endpoint, configured for Kubernetes liveness check probe. The API returns a json, containing the health indicators.
Kubernetes only cares about the returned http status, but I would like to store the json responses in Prometheus for monitoring purposes.
Is it possible to catch the response once Kubernetes calls the API? I do not want to add the feature to the application itself but use an external component.
What is the recommended way of doing it?
Upvotes: 1
Views: 1341
Reputation: 6040
Answering to what you've asked:
Make a sidecar that calls localhost:port/health
every N
seconds and stores the most recent reply. N
should be equal to the prometheus scraping interval for accurate results.
A sidecar then exposes the most recent reply in the form of metric in /metrics
endpoint, on a separate port of a pod. You could use https://github.com/prometheus/client_python to implement the sidecar. Prometheus exporter sidecar is actually a widely used pattern, try searching for it.
Point Prometheus to service /metrics
endpoint, which is now served by a sidecar, on a separate port. You will need a separate port in a Service
object, to point to your sidecar port. The scraping interval can be adjusted at this stage, to be in sync with your N
, or otherwise, just adjust N
. For scrape_config
details refer to: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#service
If you need an automatic Prometheus target discovery, say you have a bunch of deployments like this and their number varies - refer to my recent answer: https://stackoverflow.com/a/64269434/923620
Proposing a simpler solution:
/health
Upvotes: 3