discomon is a small Go program, expected to run in Kubernetes, that fetches metrics from Prometheus, searches for known patterns and load corresponding dashboards in Grafana.
This repository contains an OpenShift template to deploy Prometheus, Grafana and discomon (prometheus-grafana-discovery.yml
).
There's another template (example/wfapp/wfapp.yml
) to demo a WildFly application deployed and automatically discovered in Prometheus and Grafana. This sample app is really just an empty wildfly with prometheus' JMX Exporter configured. No more.
To prevent Prometheus from discovering an application, its pod must be annotated prometheus.io/scrape: 'false'
(like this).
- Create a new project and import
prometheus-grafana-discovery.yml
- Open Grafana: after a while you should see the Prometheus datasource and dashboard being added
- Add to project
examples/wfapp.yml
- Check Grafana: after a while you should see a JVM dashboard being added
- Repeat steps 1 and 2 of demo 1 to setup discomon in OpenShift, or use the existing setup
- [Optionally] add Jaeger into the project:
oc process -f https://raw.githubusercontent.com/jaegertracing/jaeger-openshift/master/all-in-one/jaeger-all-in-one-template.yml | oc create -f -
- Run
oc create -f examples/otapp.yml
(these demo microservices come from https://github.com/objectiser/opentracing-prometheus-example) - Now when you hit a URL that involves OpenTracing (for instance:
http://ordermgr-test.127.0.0.1.nip.io/buy
), metrics will be created in Prometheus, and based on that discomon will create the OpenTracing dashboard in Grafana after a few seconds.
- Repeat steps 1 and 2 of demo 1 to setup discomon in OpenShift, or use the existing setup
- Click on Add to Project > Deploy Image and provide image name
jotak/falco-the-hawk:prometheus
. Click on Create. In Grafana you will soon see 3 dashboards: the usual Prometheus, JVM which is there because the supplied docker image comes with Prometheus JMX Exporter, and Vert.X. - Now, there's a dashboard for my game metrics that I would like to use. I could manually import it to Grafana, but it may not be the recommended way to go, think immutable. I'd rather add it as a ConfigMap. So click on Resources > Config Maps > discomon-config > Edit.
- Because the game metrics are prefixed with
falco
, we will add a pattern in config.yml:
- patterns: ["^falco.*"]
name: "falco"
category: "game"
- Click on Add Item, enter key
falco.json
and in Value paste the content of this file: https://raw.githubusercontent.com/jotak/falco-demo/prometheus/docker-graf/Falco.json . Save. - In order to have game metrics, you must play a little bit. Create a route on falco-the-hawk service (default parameters), and play!
- :-( At this point, nothing happens because discomon didn't reload its config files. We have to kill the pod, it will automatically restart and push our dashboard to Grafana. You can also check again the Vert.X dashboard, it has started to animate a bit more.
Federation consists in distributing targets over several slave Prometheis (yes, Prometheis), and having a master Prometheus that picks a subset of metrics from the slaves. In this demo we will have 1 master and 2 slaves.
In discomon, the targets distribution is ruled by the annotation prometheus.io/slave
defined on the pods annotations, similarly to the well known prometheus.io/scrape
.
There are other possible kinds of federation, see https://www.robustperception.io/scaling-and-federating-prometheus/.
- Start from a clean project in OpenShift
- Import
federation-tpl/sa-role.yml
(note: sometimes it fails to create the role binding, because it doesn't resolve the objects in the expected order... when that's the case, just edit membership manually from the console to add "prom-discover-pods" role to service account "prometheus") - Import
federation-tpl/grafana-discomon.yml
. At this point it won't show anything because there's no Prometheus. - Select for import
federation-tpl/prometheus-master.yml
, and check at the end of its YAML that it's configured to scrape two slaves,prometheus-prometheis
andprometheus-other
. You should have:
# ...
static_configs:
- targets:
- prometheus-prometheis:9090
- prometheus-other:9090
- Import
federation-tpl/prometheus-slave.yml
, and set SLAVE parameter toother
. This slave will collect metrics from pods annotatedprometheus.io/slave: other
. - Select for import
examples/wfapp.yml
and modify its YAML to add theprometheus.io/slave
annotation:
# ...
template:
metadata:
labels:
app: wfapp
deploymentconfig: wfapp
# ===>
annotations:
prometheus.io/slave: other
# <===
- Now, you should start to see the metrics both in
prometheus-other
(the slave) and inprometheus
(the master). You should also see changes in discomon and grafana. - Import
federation-tpl/prometheus-slave.yml
, and set SLAVE parameter toprometheis
.
It will automatically start to pick prometheus slaves own metrics (the ones starting with prometheus_.*
). This is because the prometheus-slave
template already has the annotation prometheus.io/slave: prometheis
. Discomon and grafana should now show the prometheus dashboard.
NOTE: Here for the demo, we don't bother about fine-tuning which metrics are aggregated upto the master. It takes eveything that comes from the kubernetes_sd. For something lighter, we would have to tune federation-tpl/prometheus-master.yml
and especially lines:
params:
match[]:
- '{job="k8s-pods"}'
- Build/edit dashboard manually as desired in Grafana
- Get from API (not import/export), example:
curl -u admin:admin http://grafana-test.127.0.0.1.nip.io/api/dashboards/db/JVM
(use your grafana URL) - Update the json output to set dashboard id to null (that is the first "id" you should see in json)
- Save in
dashboards/
directory - Rebuild docker image
./dockerbuild.sh
& push to dockerhub
For development, use the OpenShift template prometheus-grafana-discovery-dev.yml
instead of the other one.
Once imported in OpenShift, discomon
won't run because it expects a build. From the command line run:
go build; oc start-build discomon --from-dir=. --follow
Repeat this command every time you want to update the deployment.