前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Prometheus】4. 监控案例

【Prometheus】4. 监控案例

原创
作者头像
历久尝新
修改2021-05-08 20:41:04
1.2K0
修改2021-05-08 20:41:04
举报
文章被收录于专栏:学而时习之学而时习之

监控linux服务器

node_exporter 概述

node_exporter:用于*NIX系统监控,使用GO语言开发的收集器

使用文档:https://prometheus.io/docs/guides/node-exporter/

Github:https://github.com/prometheus/node_exporter

exprot列表:https://prometheus.io/docs/instrumenting/exporters/

下载并运行node_exporter:

  1. 下载:wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
  2. 解压:tar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz
  3. 移动到工作目录:mv node_exporter-1.1.2.linux-amd64 /usr/local/node_exporter
  4. 配置为系统服务:
    1. vim /usr/lib/systemd/system/node_exporter.service
    2. systemctl daemon-reload
    3. systemctl start node_exporter
    4. netstat -antp | grep 9100
/usr/lib/systemd/system/node_exporter.service
/usr/lib/systemd/system/node_exporter.service

通过服务发现配置node_exporter

1. 修改prometheus.yml

prometheus.yml
prometheus.yml

2. 增加服务发现配置文件

vim node.yml
vim node.yml

3. 检查配置文件并重启prometheus

  • ./promtool check config prometheus.yml
  • kill -hup [pid]

监控CPU,内存,硬盘

CPU使用率:

100 - (avg(irate(node_cpu_seconds_total{mode="idle"}[5m])) by (instance)*100)

内存使用率:

100 - (node_memory_MemFree_bytes+node_memory_Cached_bytes+node_memory_Buffers_bytes) / node_memory_MemTotal_bytes * 100

硬盘使用率:

100 - (node_filesystem_free_bytes{mountpoint="/", fstype=~"ext4|xfs"} /node_filesystem_size_bytes{mountpoint="/", fstype=~"ext4|xfs"} * 100)

监控服务状态

1. 启动 node_exporter 服务监控 vim /usr/lib/systemd/system/node_exporter.service

/usr/lib/systemd/system/node_exporter.service
/usr/lib/systemd/system/node_exporter.service

2. 重新加载配置文件 systemctl daemon-reload

3. 重启启动服务 systemctl restart node_exporter

4. 查看重启结果 ps -ef | grep node_exporter

5. 查看服务状态

node_systemd_unit_state{name="sshd.service"}
node_systemd_unit_state{name="sshd.service"}

使用grafana展示监控数据

grafana:开源的度量分析和可视化系统,初始密码admin

下载地址:https://grafana.com/grafana/download

更多看板:https://grafana.com/dashboards

使用方法

1. docker安装:docker run -d --name=grafana -p 3000:3000 grafana/grafana

2. 添加数据源

新增prometheus数据源
新增prometheus数据源
添加prometheus数据源
添加prometheus数据源
添加数据库地址
添加数据库地址

3. 创建仪表盘

新增空仪表盘
新增空仪表盘
编写sql
编写sql
多个仪表盘
多个仪表盘

4. 导入其他仪表盘

----

监控docker服务器

cAdvisor (Container Advisor) 用于收集正在运行的容器资源使用和性能信息,go语言开发

下载地址:https://github.com/google/cadvisor

更多看板:https://grafana.com/dashboards/193

使用方法:

1. 安装

代码语言:javascript
复制
docker run \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:ro \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  --volume=/dev/disk/:/dev/disk:ro \
  --publish=8080:8080 \
  --detach=true \
  --name=cadvisor \
  --privileged \
  --device=/dev/kmsg \
  gcr.io/cadvisor/cadvisor:$VERSION

2. 检查是否启动成功 docker ps -l

3. 加入到prometheus进行监控

  • 修改prometheus配置文件:
vim prometheus.yml
vim prometheus.yml
  • 检查prometheus配置文件修改:./promtool check config prometheus.yml
  • 重启prometheus
  • 导入docker grafana仪表盘 193
导入193视图
导入193视图

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 监控linux服务器
    • node_exporter 概述
      • 下载并运行node_exporter:
        • 通过服务发现配置node_exporter
        • 监控CPU,内存,硬盘
          • CPU使用率:
            • 内存使用率:
              • 硬盘使用率:
              • 监控服务状态
              • 使用grafana展示监控数据
                • 使用方法
                • 监控docker服务器
                相关产品与服务
                容器镜像服务
                容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
                http://www.vxiaotou.com