Grafana 搭建系统监控面板
Grafana 是一个开源的数据可视化和监控平台
启动容器
我们需要拉取相关的三个镜像并启动
node-exporter
docker-compose.yaml 配置如下:
version: "3.3"
services:
node-exporter:
ports:
- 9100:9100
container_name: node_exporter
image: prom/node-exporter
networks: {}prometheus
docker-compose.yaml 配置如下,把 /path/to 换成你自己的配置路径
version: "3.3"
services:
prometheus:
container_name: prometheus
ports:
- 9090:9090
volumes:
- /path/to/prometheus.yml:/etc/prometheus/prometheus.yml
- /path/to/prometheus-data:/prometheus
image: prom/prometheus
networks: {}其中 prometheus.yml 内容我们设置如下。把相关的 IP 和端口换成我们上面设置的,我这里是 9100 和 9090
# 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).
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['192.168.1.8:9090'] #mertics接口地址,相当于exporter地址
labels:
instance: prometheus
- job_name: nodeExporter #任务名称
static_configs:
- targets: ['192.168.1.8:9100']grafana
docker-compose.yaml 配置如下,把 /path/to 换成你自己的配置路径
version: "3.3"
services:
grafana:
ports:
- 6500:3000
container_name: grafana
volumes:
- /path/to/grafana:/var/lib/grafana
image: grafana/grafana
networks: {}设置 prometheus
在 Connection > Data sources > Add new data source 中,直接选择 prometheus
填入 Connection 的 URL 为 prometheus 启动的地址,我这里是 http://192.168.1.8:9090
然后点保存并测试。显示正确后再进行下一步
配置 Grafana 面板
在 Dashboard > New > Import 中,填入 8919 这个 ID 并且 load
选择我们刚刚设置的 prometheus
点击导入后,就可以看到我们的系统数据了:
你可以在官方的 dashboard 模版市场中找到更多模版