Prometheus is an open source system monitoring and alerting tool kit. Docker can be configured to Prometheus goal . Currently, you can only monitor Docker itself. You can not use the Docker target monitoring application.
Docker's monitoring procedure:
1. docker metrics-address of the monitoring port is exposed to Prometheus:
Modify the docker's daemon.json file
{ "Metrics-addr": "192.168.191.18:9323", #docker official website of the configuration is not connected to the Prometheus in 127.0.0.1:9323 ip, curl manually performed may be displayed when the docker monitoring -L 127.0.0.1:9323 indicators reason may be due to isolation between the container can not connect it. "Experimental": to true }
After the container docker service: systemctl restart docker
2. Edit Prometheus.yml
# my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'codelab-monitor' # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first.rules" # - "second.rules" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] - job_name: 'docker' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['192.168.191.18:9323']
3. Start a container of Prometheus
Command mode to create services when swarm cluster approach docker environments are not the same. self swarm cluster deployment operation
[root@docker ~]# docker service create --replicas 1 --name my-prometheus --mount type=bind,source=/root/prometheus.yml,destination=/etc/prometheus/prometheus.yml --publish published=9090,target=9090,protocol=tcp prom/prometheus rgkmwhwqepl1qivlpq8r3nt2n overall progress: 1 out of 1 tasks 1/1: running [==================================================>] verify: Service converged
View service information created
[root@docker ~]# docker service ls ID NAME MODE REPLICAS IMAGE PORTS rgkmwhwqepl1 my-prometheus replicated 1/1 prom/prometheus:latest *:9090->9090/tcp
View service specific information
[root@docker ~]# docker service ps my-prometheus ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS y8akc5dmwjrn my-prometheus.1 prom/prometheus:latest docker Running Running 16 minutes ago
4. Access page to view monitoring the value of Prometheus
Watched Item View
The basic content prometheus monitoring docker has been deployed and verification is complete, docke official website about Prometheus · Configuration Lab's monitoring docker error when viewing the monitoring target of Prometheus: dial tcp xxxx: connect: connection refused.
docker's official website https://docs.docker.com/config/thirdparty/prometheus/