Prometheus是一个开源系统监控和警报工具包。可以将Docker配置为Prometheus目标。目前,您只能监控Docker本身。您目前无法使用Docker目标监控应用程序。
监控docker的操作步骤:
1.使用docker的metrics-address向Prometheus暴露监控端口:
修改docker的daemon.json文件
{ "metrics-addr": "192.168.191.18:9323", #docker官网上的配置是127.0.0.1:9323在Prometheus无法连接该ip,手动执行curl -L 127.0.0.1:9323时可以显示docker的监控指标的,可能由于容器之间的隔离原因无法连接吧。 “experimental": true }
之后容器docker服务:systemctl restart docker
2.编辑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.启动一个Prometheus的容器
docker环境使用的时swarm集群方式创建服务的命令方式不一样。swarm集群部署可自行操作
[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
查看创建的服务信息
[root@docker ~]# docker service ls ID NAME MODE REPLICAS IMAGE PORTS rgkmwhwqepl1 my-prometheus replicated 1/1 prom/prometheus:latest *:9090->9090/tcp
查看服务的具体信息
[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.访问Prometheus的页面查看监控值
监控项的查看
prometheus监控docker的基本内容已经部署及验证完成,docke官网有关Prometheus·监控docker的配置实验在查看Prometheus的监控target时报错:dial tcp xxxx: connect: connection refused。
docker官网https://docs.docker.com/config/thirdparty/prometheus/
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。