Endpoint monitoring with Prometheus and Blackbox Exporter
As a DevOps engineer, I am working on the migration of the CaaS (Cloudify as a Service) solution to Kubernetes (EKS), which includes monitoring of multiple critical endpoints with Prometheus/Grafana.
I will describe in this post how I do it.
Prerequisites
-
Existing k8s cluster, EKS in my case.
-
Prometheus/Grafana Installed to your cluster, I am using kube-prometheus-stack
kube-prometheus-stack
Installs the kube-prometheus stack, a collection of Kubernetes manifests, Grafana dashboards, and Prometheus rules combined with documentation and scripts to provide easy to operate end-to-end Kubernetes cluster monitoring with Prometheus using the Prometheus Operator.
Let’s start.
Problem Definition
CaaS (Cloudify as a Service) solution depends on multiple endpoints to be constantly available, like API endpoint, license generation endpoint for each CaaS environment, external services of HubSpot which are tightly integrated into CaaS, and multiple other endpoints. If one of these endpoints goes down I want to be notified immediately.
For this exampe I will monitor 3 endpoints using the HTTP/HTTPS status checks:
- api.myorganization.com
- license.myorganization.com
- api.hubspot.com
Solution
To solve this problem I had 3 options:
- Use external product/service for monitoring which supports status checks via HTTP/HTTPS protocols.
- To build my solution, using k8s cron jobs or write some scheduled job(script) with my CI (Jenkins).
- Use Prometheus/Grafana.
And the winner is Prometheus/Grafana, because that is exactly what a monitoring solution like Prometheus must do, besides that I am already using Prometheus for monitoring in general.
Blackbox Exporter
https://github.com/prometheus/blackbox_exporter
The blackbox exporter allows blackbox probing of endpoints over HTTP, HTTPS, DNS, TCP and ICMP.
A great example of what you can do with black box exporter: https://github.com/prometheus/blackbox_exporter/blob/master/example.yml
Deploying Blackbox Exporter to EKS with helm
https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-blackbox-exporter
This is how the config of black box exporter looks like after installation:
It’s worth mentioning that I added:
because one of my endpoints returns 403 status and I still want to see success/green in grafana for this endpoint instead of failure/down.
Modify Prometheus.yaml
In my case I am using kube-prometheus-stack, so what I need is to modify values.yaml of this helm chart:
If you not using this helm chart, you can add this to prometheus.yaml instead
prometheus-blackbox-exporter.monitoring is the DNS name of prometheus-blackbox-exporter service, monitoring is namespace:
Verify your metrics coming to prometheus
Adding Alerts
I created endpoint-alerts.yaml, which is PrometheusRule resource, CRD of Prometheus Operator.
Deploy endpoint-alerts.yaml
Grafana Dashboard
I used existing dashboard: https://grafana.com/grafana/dashboards/7587
Go to Grafana -> + sign -> Import and enter 7587 number.
In this post, I described how to monitor multiple endpoints critical to your application with Prometheus, Grafana and Blackbox Exporter.
Thank you for reading, I hope you enjoyed it, see you in the next post.
Please subscribe to my YT channel
If you want to be notified when the next post of this tutorial is published, please follow me on Twitter @warolv.
Medium account: warolv.medium.com