Scrape RabbitMQ Metrics With Prometheus in Kubernetes
… without all the complicated fuzz around it. This is probably only interesting to you if you’re running a Kubernetes cluster with something like k3s and want some monitoring and metrics from RabbitMQ without installing extra Kubernetes PlugIns and all these things.
I’m running the kube-prometheus-stack from the prometheus-community github repository. They have a helm chart available to make installing easy.
I’m just going with the default things here:
kubectl create ns monitoring
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install -n monitoring monitoring prometheus-community/kube-prometheus-stack
Now, to make Prometheus scrape the metrics from RabbitMQ, first make sure that you’re running the RabbitMQ management container image, right now this would be: 3.9-management. The releases are available on Docker Hub.
Next, let’s create a ServiceMonitor. This will tell Prometheus where to look for things to get data from. Create the following file rabbitmq_servicemonitor.yaml:
- interval: 15s
The important bits in here are:
- namespaceSelector: Where should Prometheus look for RabbitMQ. My RabbitMQ installation is in the default namespace
- the matchLabels and labels where it says release. They need to match to Prometheus, I first thought this has something to do with the actual version (it might still have? Who knows… this is all rocket science) but this needs to match the name of the installation we did with helm earlier. And this was called monitoring
Create a RabbitMQ service to expose metrics
Last thing, you need to create an additional service/port to expose the metrics to Prometheus. Chances are, that you have a service already configured for RabbitMQ, so other services can communicate with it. Anyway, here’s an example service which has both things in there. RabbitMQ itself and the metrics endpoint for Prometheus.
release: monitoring # put this in here
- port: 5672
- port: 15692 # put this in here
targetPort: 15692 # put this in here
name: metrics # put this in here
If you have a service already configured, just update the changes I commented with # put this in here above. These are the important bits again. The release, and that you have a name configured for the port.
I hope this helps a few folks who just want a basic setup (if you can even call this basic). Otherwise, it’s for my future self, so I can find this again when I’m doing a multi-hour google search again in the future.