ibmendoza / prometheus-docker-swarm

Bridges Docker Swarm services to Prometheus via file-based service discovery

Home Page:https://function61.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What?

tl;dr: use -e METRICS_ENDPOINT=/metrics (or METRICS_ENDPOINT=:8080/metrics if using port != 80) for your Docker Swarm service, and Prometheus will automatically discover your service and scrape metrics from it.

Integrates Docker (Swarm) with Prometheus via the file config option (Prometheus currently doesn't have support for Swarm mode).

This image contains the whole bundle, Prometheus + docker-prometheus-bridge + configuration for truly automated service discovery.

+--------------------------+           +----------------------+
|                          | writes    |                      |
| docker-prometheus-bridge +-----------> Configuration file   |
|                          |           | (Scrapeable targets) |
+-------^------------------+           |                      |
        |                              +-----------+----------+
        | queries                                  |
        |                                          |
        |                                          | reads
+-------+------+                                   |
|              |                              +----v-------+
| Docker API   |                              |            |
| (Swarm mode) |                              | Prometheus |
|              |                              |            |
+--------------+                              +------------+

Only advertises services that have environment variable defined: METRICS_ENDPOINT=/metrics (whitelisting).

Uses service name as job name in Prometheus.

NOTE: current limitation is that you have to deploy Prometheus on the same node as a Swarm manager! (use constraint with $ docker service create if/when you have a multi-node cluster)

DISCLAIMER: This is the first Go program I wrote, so it probably violates many Go idioms I am yet to learn.

Howto run

Basically, you need to run this as a Swarm service (for Prometheus to have access to services running in Swarm network):

$ docker service create --network YOUR_NETWORK --name prometheus -p 9090:9090 \
	--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
	--mount type=volume,src=prometheus-dev,dst=/prometheus \
	fn61/prometheus-docker-swarm:latest

Example config file to be fed to Prometheus

This is the file format that docker-prometheus-bridge generated for Prometheus:

[
	{
		"targets": [
			"10.0.0.23:80"
		],
		"labels": {
			"job": "html2pdf"
		}
	}
]

Alternatives

About

Bridges Docker Swarm services to Prometheus via file-based service discovery

https://function61.com/

License:Apache License 2.0


Languages

Language:Go 84.4%Language:Shell 15.6%