摘自:https://juejin.cn/post/7097166804044218405

安装运行Prometheus(docker版)

Grafana是一个开源的功能丰富的数据可视化平台,通常用于时序数据的可视化。它内置了多种数据源的支持

下载镜像包

1
2
3
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana

启动node-exporter

1
2
3
4
5
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
prom/node-exporter

访问url:

http://127.0.0.1:9100/metrics

效果如下:

这些都是收集到的数据,有了它就可以做数据展示了。

启动prometheus

新建目录 prometheus,编辑配置文件prometheus.yml

1
2
3
mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml

内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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).
# Attach these extra labels to all timeseries collected by this Prometheus instance.
external_labels:
monitor: 'codelab-monitor'
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: ["192.168.3.153:8080"]
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['127.0.0.1:9100']
labels:
instance: localhost

启动prometheus

1
2
3
4
docker run  -d \
-p 9090:9090 \
-v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus

访问url :

1
127.0.0.1:9090/graph

启动grafana

新建空文件夹grafana-storage,用来存储数据

1
mkdir /opt/grafana-storage

设置权限

1
chmod 777 -R /opt/grafana-storage

因为grafana用户会在这个目录写入文件,直接设置777,比较简单粗暴!

启动grafana

1
2
3
4
5
docker run -d \
-p 3000:3000 \
--name=grafana \
-v /opt/grafana-storage:/var/lib/grafana \
grafana/grafana

访问url:

1
127.0.0.1:3000

默认会先跳转到登录页面,默认的用户名和密码都是admin

登录之后,它会要求你重置密码。你还可以再输次admin密码!

密码设置完成之后,就会跳转到首页

提示,有个地方在创建data source时,ip地址要填写本机Ip地址,而不是127.0.0.1