Docker-compose快速搭建Prometheus+Grafana监控系统

Docker-Compose项目是Docker官方的开源项目,负责实现对Docker容器集群的快速编排。
Prometheus 是由 SoundCloud 开源监控告警解决方案。
Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。

1、安装docker,docker-compose

1.1、安装docker

1
2
3
4
5
6
7
8
9
10
11
12
# 安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加Docker软件包源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 安装Docker CE
yum install docker-ce -y
# 启动
systemctl start docker
# 开机启动
systemctl enable docker
# 查看Docker信息
docker info

1.2、安装docker-compose

1
2
curl -L https://github.com/docker/compose/releases/download/1.28.6/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

2、添加配置文件

在/mydata/prometheus 下添加prometheus.yml配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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).

# 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'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ['localhost:9090']

- job_name: 'springboot_prometheus'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['172.17.0.7:8888']

3、编写docker-compose

1
vim docker-compose-monitor.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: '3.8'
services:
prometheus:
image: prom/prometheus:v2.4.3
container_name: prometheus
ports:
- 9090:9090
volumes:
- /mydata/prometheus:/etc/prometheus
- /etc/localtime:/etc/localtime:ro
grafana:
image: grafana/grafana:7.5.7
container_name: grafana
ports:
- 3000:3000
depends_on:
- prometheus

4、启动docker-compose

4.1、启动容器

1
docker-compose -f docker-compose-monitor.yml up -d

4.2、单独命令启动

1
2
3
4
5
6
7
#启动prometheus
docker run -d -p 9090:9090 --name=prometheus \
-v /mydata/prometheus:/etc/prometheus \
prom/prometheus

# 启动grafana
docker run -d -p 3000:3000 --name=grafana grafana/grafana

Docker-compose快速搭建Prometheus+Grafana监控系统
https://river106.cn/posts/2594526d.html
作者
river106
发布于
2021年9月28日
许可协议