文档:

https://prometheus.fuckcloudnative.io/di-yi-zhang-jie-shao/overview

下载镜像包

  1. sudo docker pull prom/node-exporter
  2. sudo docker pull prom/prometheus
  3. sudo docker pull grafana/grafana

启动node-exporter

  1. sudo docker run -d -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter

访问url:

http://127.0.0.1:9100/metrics

启动prometheus

新建目录 prometheus,编辑配置文件prometheus.yml

  1. sudo mkdir /opt/prometheus
  2. cd /opt/prometheus/
  3. sudo vim prometheus.yml

内容如下:

  1. global:
  2. scrape_interval: 60s
  3. evaluation_interval: 60s
  4. scrape_configs:
  5. - job_name: prometheus
  6. static_configs:
  7. - targets: ['localhost:9090']
  8. labels:
  9. instance: prometheus
  10. - job_name: linux
  11. static_configs:
  12. - targets: ['127.0.0.1:9100']
  13. labels:
  14. instance: localhost

启动prometheus

  1. sudo docker run -d \
  2. -p 9090:9090 \
  3. -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
  4. prom/prometheus

如果grafana启动遇到问题: grafana报错Panel plugin not found grafana-piechart-panel
可以参考: https://blog.csdn.net/qq_41980563/article/details/121231939

访问url

127.0.0.1:9090/graph

启动grafana

新建空文件夹grafana-storage,用来存储数据

  1. mkdir /opt/grafana-storage

设置权限

  1. chmod 777 -R /opt/grafana-storage

启动grafana(如果和已有的端口冲突改一下端口)

  1. sudo docker run -d \
  2. -p 3000:3000 \
  3. --name=grafana \
  4. -v /opt/grafana-storage:/var/lib/grafana \
  5. grafana/grafana

访问
127.0.0.1:3000