workshop/dockerdesktop/mac/preference/prometheus/README.md
Prometheus is an open-source systems monitoring and alerting toolkit. Prometheus collects metrics from monitored targets by scraping metrics from HTTP endpoints on these targets. Docker instance can be configured as Prometheus target. Different targets to scrape are defined in the Prometheus configuration file. Targets may be statically configured via the static_configs parameter in the configuration fle or dynamically discovered using one of the supported service-discovery mechanisms (Consul, DNS, Etcd, etc.). Prometheus collects metrics from monitored targets by scraping metrics from HTTP endpoints on these targets. Since Prometheus also exposes data in the same manner about itself, it can also scrape and monitor its own health.
Docker exposes Prometheus-compatible metrics on port 9323. This support is only available as an experimental feature.
For Docker for Mac, click on Docker icon in the status menu
Select Preferences…, Daemon, Advanced tab
Update daemon settings:
{
"metrics-addr" : "0.0.0.0:9323",
"experimental" : true
}
Show the complete list of metrics using curl http://localhost:9323/metrics
Show the list of engine metrics using curl http://localhost:9323/metrics | grep engine
In this section, we’ll start Prometheus and use it to scrape it’s own health.
Create a new directory prometheus and change to that directory
Create a text file prometheus.yml and use the following content:
# A scrape configuration scraping a Node Exporter and the Prometheus server
# itself.
scrape_configs:
# Scrape Prometheus itself every 5 seconds.
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
This configuration file scrapes data from the Prometheus container which will be started subsequently on port 9090.
docker service create \
--replicas 1 \
--name metrics \
--mount type=bind,source=`pwd`/prometheus.yml,destination=/etc/prometheus/prometheus.yml \
--publish 9090:9090/tcp \
prom/prometheus
This will start the Prometheus container on port 9090.
It shows that the Prometheus endpoint is available for scraping.
These are all the metrics published by the Prometheus endpoint.