准备配置文件

docker-compose.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
services:
prometheus:
container_name: prometheus
image: prom/prometheus
ports:
- "9090:9090"
environment:
- TZ=Asia/Shanghai
volumes:
- /usr/local/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
networks:
- apm
# restart: always

# grafana作为可视化界面
grafana:
container_name: grafana
image: grafana/grafana
ports:
- "3000:3000"
environment:
- TZ=Asia/Shanghai
networks:
- apm
# restart: always

networks:
apm:
driver: bridge

Prometheus配置文件

新建配置文件 prometheus.yml 填入以下内容:

1
2
3
4
5
6
7
8
global:
scrape_interval: 15s # 每隔15秒抓取一次
Gran
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

启动服务

prometheus.yml 放到 docker-compose.yml 中配置的指定目录中,启动docker服务。

1
docker-compose up -d

验证安装

  1. 检查容器状态:

    1
    docker-compose ps
  2. 访问web页面: