Prometheus监控Linux

Prometheus监控Linux

Linux 客户端安装docker 

export DOWNLOAD_URL="http://mirrors.163.com/docker-ce"
curl -fsSl https://get.docker.com/ |sh
apt install docker-compose -y

创建node-exporter

mkdir -p /data/docker-compose
cd /data/docker-compose
 
cat >docker-compose.yaml <<'EOF'
version: '3.3'
networks:
  monitoring:
    driver: bridge
 
services:
  node_exporter:
    image: prom/node-exporter:v1.5.0
    container_name: node-exporter
    restart: always
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command: 
      - '--path.procfs=/host/proc' 
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc|rootfs/var/lib/docker)($$|/)'
    networks:
      - monitoring
    ports:
      - '9100:9100'
EOF

启动docker

docker-compose up -d

浏览器验证

http://ip:9100/metrics

 prometheus节点操作

配置prometheeus/prometheus.yaml

  - job_name: 'node-exporter'
    scrape_interval: 15s
    static_configs:
    - targets: ['node_exporter:9100']
      labels:
        instance: Prometheus服务器 
    - targets: ['10.19.1.206:9100']
      labels:
        instance: 10.19.1.206服务器 
    - targets: ['10.19.1.220:9100']
      labels:
        instance: 10.19.1.220服务器

配置加载
curl -X POST http://localhost:9090/-/reload
检查容器状态
docker ps -a
docker logs -f node-exporter

CPU采集
node_cpu_seconds_total
node_cpu_seconds_total{ instance=”10.19.1.220服务器”}
node_load1
node_load5
node_load15

内存采集
node_memory_MemTotal_bytes
node_memory_MemAvailable_bytes (free+buffer+cache)
node_memory_MemFree_bytes
node_memory_SwapFree_bytes
node_memory_SwapTotal_bytes

磁盘采集
node_disk_

文件系统采集
node_filesystem_

网络采集
node_network_
node_network_transmit_drop_total
增加触发器配置

cat >> prometheus/alert.yml <<'EOF'
- name: node-exporter
  rules:
  - alerts: HostOutOfMemory
    expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10
	for: 2m
	labels:
	  severity: warning
	annotations:
	  summary: "主机内存不足,实例:{{ $labels.instance }}"
	  description: "内存可用率<10%,当前值:{{ $value }}"	  
  - alerts: HostMemoryUnderMemoryPressure
    expr: rate(node_vmstat_pgmajfault[1m]) > 1000
	for: 2m
	labels:
	  severity: warning
	annotations:
	  summary: "主机压力不足,实例:{{ $labels.instance }}"
	  description: "节点内存压力大,重大页面错误率高,当前值:{{ $value }}"   
  - alerts: HostUnusualNetworkThroughputIn
    expr: sum by (instance) (rate(node_network_receive_bytes_total[2m])) / 1024 / 1024 > 100
	for: 5m
	labels: 
	  severiry: warning
	annotations: 
	  summary: "异常流出网络吞吐量,实例: {{ $labels.instance }}"
	  description: "网络流入量 > 100 MB/s,当前值: {{ $value }}"  
  - alerts: HostUnusualDiskReadRate
    expr: sum by (instance) (rate(node_disk_read_bytes_total[2m])) / 1024 /1024 > 50
	for: 5m
	labels:
	  severity: warning
	annotations:
	  summary: "异常流出网络吞吐量,实例:{{ $labels.instance }}"
	  description: "网络流出流量 > 100 MB/s,当前值: {{ $value }}"
EOF
  1. 检查配置
  2. docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml

grafana展示node-exporter的数据

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/10810

(0)
凯影的头像凯影
上一篇 2023年12月29日 下午4:01
下一篇 2024年1月4日 下午3:10

相关推荐

  • Expect解决shell脚本的交互需求

    在linux系统中,shell脚本可以大大提高我们的工作效率。但遇到需要交互的场景时,shell脚本却无法解决。 简介 Expect语言是基于Tcl的。Tcl实际上是一个子程序库,这些子程序库可以嵌入到程序里从而提供语言服务。 最终的语言有点象一个典型的 Shell语言。里面有给变量赋值的set命令,控制程序执行的if,for,continue等命令,还能进…

    2022年11月15日
    1.2K00
  • Hyper上虚拟服务器Windows系统C盘不够,如何扩容?

    问题 客户需要将C盘设置成60G,原先35G,不够使用 解决方式 首先关闭该虚拟机 关机后右击设置,点击”硬盘驱动器“,点击“编辑” 选择配置磁盘,点击“扩展” 输入磁盘大小 重启虚拟机,打开计算机管理。选择磁盘管理,右击进行扩展卷 点击下一步,最终完成C盘扩容

    2022年6月16日
    1.6K00
  • Linux实验案例:构建DHCP服务器

    公司要求将闲置的一台Linux主机配置为DHCP服务器,以便为局域网内员工的办公用机提供自动分配IP地址服务,提高网络管理和维护的效率。 需求描述 给局域网内各主机自动分配的IP地址范围为192.168.10.20~192.168.10.30 局域网内各主机使用的默认网关地址为192.168.10.2 局域网内各主机使用的DNS服务器地址分别为202.96.…

    2024年6月24日
    1.6K00
  • win10 22H2 更新后不能联网

    今天我的WIN10主机自动更新了,更新后就出现了显示无网络连接的问题,同一网络环境下其他主机正常,重装网卡驱动,更换USB有线,PCIE,USB无线网卡使用后均无法上网。 上网搜索后发现微软社区有多人反应此问题,大家谨慎更新。 首先查看更新记录 卸载更新 卸载最近安装时间的应用程序 卸载完成后window 10 就可以正常访问网络了。

    2024年6月5日
    1.5K00
  • Linux系统VPS云服务器网络速度性能测试一键脚本分享

    收集的一些常用的测试脚本部分经过实际测试,基本可以正常使用,关于脚本测试出来数据的准确性,需要自行甄别,仅供参考。 本站所收集的一键脚本均来自网络,不对其收集的脚本负责,请注意保管并备份资料,建议多尝试几个脚本进行测试。 附件下载测试 秋水逸冰硬件信息/带宽测试 测试VPS基础信息,以及下载速度,来自秋水逸冰:https://bench.sh/ 老鬼硬件信息…

    2022年6月8日
    3.1K00

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信