通过docker compose部署Grafana和Prometheus
目标:
基于我们之前制作的nginx-exporter:v0.2镜像,我们使用docker compose编排文件实现一次性部署Prometheus和Grafana
与前面手工部署三个容器不一样的地方是,我们这里需要修改一下Prometheus和Grafana配置里的数据源地址。
1
#more prometheus-compose.yml
2
global:
3
scrape_interval: 15s
4
evaluation_interval: 15s
5
6
scrape_configs:
7
- job_name: 'prometheus'
8
static_configs:
9
- targets: ['localhost:9090']
10
- job_name: 'nginx_exporter'
11
static_configs:
12
- targets: ['nginx_exporter:9113']
13
labels:
14
group: 'services'
Copied!
1
#more datasource-compose.yaml
2
apiVersion: 1
3
4
datasources:
5
- name: Prometheus
6
type: prometheus
7
access: proxy
8
orgId: 1
9
url: http://prometheus:9090
10
basicAuth: false
11
isDefault: true
12
version: 1
13
editable: true
Copied!
清除之前测试的容器:
1
docker stop $(docker ps -q)
2
docker rm $(docker ps -aq)
Copied!
新建一个docker-compose.yaml文件:
1
version: '3'
2
3
services:
4
5
nginx:
6
image: nginx-exporter:v0.2
7
networks:
8
webnet:
9
aliases:
10
- "nginx_exporter"
11
expose:
12
- "9113"
13
ports:
14
- "9113:9113"
15
16
prometheus:
17
image: prom/prometheus
18
volumes:
19
- ./prometheus/prometheus-compose.yml:/etc/prometheus/prometheus.yml
20
networks:
21
webnet:
22
aliases:
23
- "prometheus"
24
expose:
25
- "9090"
26
ports:
27
- "9090:9090"
28
depends_on:
29
- nginx
30
31
grafana:
32
image: grafana/grafana
33
volumes:
34
- ./grafana/dashboards/dashboard.json:/var/lib/grafana/dashboards/dashboard.json
35
- ./grafana/provisioning/dashboard.yaml:/etc/grafana/provisioning/dashboards/dashboard.yaml
36
- ./grafana/provisioning/datasource-compose.yaml:/etc/grafana/provisioning/datasources/datasource.yaml
37
networks:
38
webnet:
39
aliases:
40
- "grafana"
41
expose:
42
- "3000"
43
ports:
44
- "3000:3000"
45
depends_on:
46
- prometheus
47
48
networks:
49
webnet: {}
Copied!
然后使用docker-compose up -d命令运行起来,之后访问宿主机3000端口即可获取grafana界面。
Last modified 1yr ago
Copy link