admin 管理员组

文章数量: 887021

监控

Prometheus监控

架构

步骤1 - 启动Prometheus服务器
参考文档,编写配置文件,名为prometheus.yml

global:scrape_interval:     15sevaluation_interval: 15sscrape_configs:- job_name: 'prometheus'static_configs:- targets: ['127.0.0.1:9090', '127.0.0.1:9100']labels:group: 'prometheus'

其中127.0.0.1:9090是Prometheus自身,它将内部的指标与性能暴露出来。127.0.0.1:9091是Node Exporter进程,它将如磁盘空间、内存与CPU使用情况暴露出来。
启动Prometheus服务器(容器)

# 命令
docker run -d --net=host \-v /root/prometheus.yml:/etc/prometheus/prometheus.yml \--name prometheus-server \prom/prometheus
# 效果
[root@host01 ~]# docker run -d --net=host \
>     -v /root/prometheus.yml:/etc/prometheus/prometheus.yml \
>     --name prometheus-server \
>     prom/prometheus
Unable to find image 'prom/prometheus:latest' locally
latest: Pulling from prom/prometheus
e5d9363303dd: Pull complete 
3430c2c42129: Pull complete 
7631b5d56c90: Pull complete 
343e06690c48: Pull complete 
dc32e90574e9: Pull complete 
a6d5d01cd646: Pull complete 
832428480103: Pull complete 
83e775ff1768: Pull complete 
1ec97f567836: Pull complete 
0cdf5b797911: Pull complete 
eb7d1f2acc9f: Pull complete 
541ffe559bd5: Pull complete 
Digest: sha256:38d40a760569b1c5aec4a36e8a7f11e86299e9191b9233672a5d41296d8fa74e
Status: Downloaded newer image for prom/prometheus:latest
c3634d4be256865795a70406e0e989db1e071278e7717f67291e9695ab97a089
[root@host01 ~]# 
[root@host01 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
c3634d4be256        prom/prometheus     "/bin/prometheus --c…"   3 minutes ago       Up 3 minutes                            prometheus-server
[root@host01 ~]# 

浏览器访问9090端口

步骤2 - 启动Node Exporter(容器)
Node Exporter可以收集一个node的相关指标信息。

# 命令
docker run -d \-v "/proc:/host/proc" \-v "/sys:/host/sys" \-v "/:/rootfs" \--net="host" \--name=prometheus \quay.io/prometheus/node-exporter:v0.13.0 \-collector.procfs /host/proc \-collector.sysfs /host/sys \-collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
# 效果
[root@host01 ~]# docker run -d \
>   -v "/proc:/host/proc" \
>   -v "/sys:/host/sys" \
>   -v "/:/rootfs" \
>   --net="host" \
>   --name=prometheus \
>   quay.io/prometheus/node-exporter:v0.13.0 \
>     -collector.procfs /host/proc \
>     -collector.sysfs /host/sys \
>     -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
Unable to find image 'quay.io/prometheus/node-exporter:v0.13.0' locally
v0.13.0: Pulling from prometheus/node-exporter
8ddc19f16526: Pull complete 
a3ed95caeb02: Pull complete 
8279f336cdd3: Pull complete 
81998f54d5a6: Pull complete 
Digest: sha256:8f083b308a39bdd5bd42759b67e20e19398e98b291648f397d98ef4b99d9a318
Status: Downloaded newer image for quay.io/prometheus/node-exporter:v0.13.0
3c4b8dafb9775611260174e9249519aee2319fbdce71fa7d095a26037d9b4ac7
[root@host01 ~]# docker ps 
CONTAINER ID        IMAGE                                      COMMAND                  CREATED              STATUS              PORTS               NAMES
3c4b8dafb977        quay.io/prometheus/node-exporter:v0.13.0   "/bin/node_exporter …"   About a minute ago   Up About a minute                       prometheus
c3634d4be256        prom/prometheus                            "/bin/prometheus --c…"   12 minutes ago       Up 12 minutes                           prometheus-server
[root@host01 ~]# curl localhost:9100/metrics| less


步骤3 - 看指标
浏览器访问127.0.0.1:9090/targets

可以看到有两个target,是我们在前面配置文件中定义好的两个target。运行在生产环境时,你可能需要Grafana或Weave Cortex。
查询特定指标,打开自动补全功能,输入会有相似匹配。

我们选择node_cpu并执行
可以看到一系列的数值,每个数值都是一个不同的mode。上面这个是Table,我们也可以将其转换为Graph来看,更直观

查看所有的指标

本文标签: 监控