Docker安装Prometheus与Grafana
# 概述
本文记录,使用docker在Linux机器,安装Prometheus与Grafana。
# 正文
- 1.新建prometheus.yml文件,内容如下
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# 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'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090','192.168.31.162:9100']
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- 2.启动prometheus容器
docker run --name=prometheus -d -p 9090:9090
-v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
-v /data/prometheus/rules.yml:/etc/prometheus/rules.yml prom/prometheus
--config.file=/etc/prometheus/prometheus.yml
--web.enable-lifecycle
1
2
3
4
5
2
3
4
5
//重载配置文件命令
curl -X POST http://localhost:9090/-/reload
1
2
2
- 3.收集Linux信息
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
prom/node-exporter
1
2
3
4
5
2
3
4
5
- 4.启动Grafana
docker run -d -p 3001:3000 --name grafana grafana/grafana
1
- 5.配置模版信息
https://grafana.com/grafana/dashboards/11074