# 要準備的檔案 ``` ├── data │   ├── grafana │   │   └── provisioning │   │   └── datasources │   │   └── datasources.yaml │   └── prometheus │   └── prometheus.yml ├── docker-compose.yml ``` - `docker-compose.yml` - `data/grafana/provisioning/datasources/datasources.yaml` - `data/prometheus/prometheus.yml` # `docker-compose.yml` ```yaml hl:5 services: grafana: image: grafana/grafana:latest restart: always user: "1000" ports: - "8082:3000" volumes: - ./data/grafana/data:/var/lib/grafana # data path - ./data/grafana/grafana.ini:/etc/grafana/grafana.ini - ./data/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards - ./data/grafana/provisioning/datasources:/etc/grafana/provisioning/datasources environment: - GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource prometheus: image: prom/prometheus:latest container_name: grafana-prometheus-1 restart: always command: - --storage.tsdb.retention.time=7d - --config.file=/etc/prometheus/prometheus.yml ports: - "8083:9090" volumes: - ./data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml node_exporter: image: prom/node-exporter:latest restart: always ports: - "8084:9100" ``` 要注意 `user: "1000"` 這一行,這一行是你的 user ID,有可能會變,請用 `id -u` 確認一下。 # `datasources.yaml` ```yaml hl:6 # datasources.yaml apiVersion: 1 datasources: - name: Prometheus type: prometheus url: http://192.168.1.24:8083 access: proxy ``` 要注意 `url: http://192.168.1.24:8083` 這一行,要更新 IP 位置。 # `prometheus.yml` ```yaml hl:11 # prometheus.yml 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). scrape_configs: - job_name: 'node-exporter-local' scrape_interval: 5s static_configs: - targets: ['192.168.1.24:8084'] ``` 要注意 `- targets: ['192.168.1.24:8084']` 這一行,要更新 IP 位置。 # Grafana template template ID: `1860` # 參考 - [Docker Compose 部署监控系统 Prometheus + Grafana + Node Exporter + Cadvisor-腾讯云开发者社区-腾讯云](https://cloud.tencent.com/developer/article/2016801) - [基于docker-compose快速搭建Prometheus+Grafana监控系统 - 掘金](https://juejin.cn/post/7320525843737460771) - [Deep Dive into Using Docker Compose for Monitoring with Prometheus, Grafana, and node_exporter | by mefengl | Medium](https://medium.com/@mefengl/unknown-title-95cb5a15ce83) - [使用docker-compose快速部署Prometheus+grafana环境_docker-compose安装grafana-CSDN博客](https://blog.csdn.net/weixin_45070882/article/details/132104496) - [Dashboards | Grafana Labs](https://grafana.com/grafana/dashboards/?collector=nodeexporter&dataSource=prometheus)