监控 - Prometheus监控

Prometheus监控

架构
在这里插入图片描述

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

global:
  scrape_interval:     15s
  evaluation_interval: 15s

scrape_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来看,更直观
在这里插入图片描述
查看所有的指标
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王万林 Ben

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值