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

相关推荐

  • 在 Linux 上以 All-in-One 模式安装 KubeSphere

    步骤 1:准备 Linux 机器 若要以 All-in-One 模式进行安装,您仅需参考以下对机器硬件和操作系统的要求准备一台主机。 硬件推荐配置 操作系统 最低配置 Ubuntu 16.04, 18.04, 20.04, 22.04 2 核 CPU,4 GB 内存,40 GB 磁盘空间 Debian Bus…

    2023年4月18日
    1.2K00
  • 可以ping通Windows server 2003服务器,无法使用远程桌面登录的解决方法

    Windows系统远程不上有很多种问题,我们最常见的问题就是远程端口访问权限没打开、远程端口防火墙没放行等,所以我们在解决这类问题时,首先就需要查看访问权限、防火墙这两项是否设置正常 如何查看或者修改远程端口 有关于查看和修改远程端口的问题,大家可以去看我们的另外一篇文章,还有一点就是Windows系统更改端口的方法基本都是一致,都是通过修改注册表来实现的:…

    2022年6月20日
    3.0K00
  • pve系统崩溃,ceph集群节点不能加入问题处理

    本次故障缘起,pve系统盘突然坏了,导致ceph集群降级,重装pve系统后,发现ceph不能加入原有的集群,需要清除所有配置才可完成 首先需要从集群中删除故障ceph ceph的配置文件路径 /etc/ceph/ceph.conf 此次故障的节点是pve3,在一个正常的节点配置文件中删除故障的节点 同时需要在web页面 监视器中销毁之前故障的节点 osd销毁…

    2024年4月2日
    1.5K00
  • Cisco交换机密码忘记重置

          原理:进入交换机底层,通过修改交换机原始配置文件名字,重启交换机后,交换机找不到原来配置文件情况下,就会加载默认系统文件(即:交换机出厂配置),以达到清除交换机密码的目的。 步骤一:用笔记本通过控制线连接到交换机com口,打开超级终端调试窗 步骤二:交换机重新上电,上电过程中,按住交换机正面”m…

    2024年6月18日
    1.7K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信