docker-compose部署Prometheus+grafana


1.docker和docker-compose请自行下载安装

2.docker-compose.-prometheus.yml文件

 1 vim docker-compose-prometheus.yml  2 
 3 version: "3.7"
 4 services:  5   node-exporter:  6     image: prom/node-exporter:latest  7     network_mode: "host"
 8 # prots:  9 #      - "9100:9100"
10  restart: always 11  prometheus: 12     image: prom/prometheus:latest 13     network_mode: "host"
14  restart: always 15 # prots: 16 #      - "9090:9090"
17  volumes: 18       - "./prometheus.yml:/etc/prometheus/prometheus.yml"
19       - "./prometheus_data:/prometheus"
20  grafana: 21     image: grafana/grafana 22     network_mode: "host"
23 # prots: 24 #      - "3000:3000"
25  restart: always 26  volumes: 27       - "./grafana_data:/var/lib/grafana"
prometheus主机需要部署以上容器,其他被监控主机只需要部署node-exporter
3.prometheus配置文件
vim prometheus.yml # my global config global: scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 5s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # 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' static_configs: - targets: ['172.16.48.51:9090'] #prometheus主机地址 - job_name: 'node' static_configs: - targets: ['172.16.48.51:9100','172.16.49.14:9100','172.16.49.43:9100']      #监控node-exporter地址

4.docker-compose启动

./docker-compose -f docker-compose-prometheus.yml up -d         # 挂载目录给权限,不然会启动失败

5.访问主机的9090端口可以查到Prometheus监控到的数据,访问3000端口是grafana的界面,

   账密admin/admin

6.配置监控,点击齿轮,选择Data Sources

0

7.点击Add data source

0

 

 8.填写prometheus地址 ip+端口或者主机名+端口(需要配置hosts)

0
9.点击save&test
0
10.点击+号,选择import
0
11.输入模板号9276,点击load
0
0
11.导入模板完成
0


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM