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 修改系统时间的两种方式

    我们一般使用“date -s”命令来修改系统时间。比如将系统时间设定成2010年4月5日的命令如下。 [root@rhel ~]# date -s 20100405 Mon Apr  5 00:00:00 CST 2010 将系统时间设定成14点31分0秒的命令如下 [root@rhel ~]# date -s 14:31:00 Mon Apr&n…

    2023年7月27日
    1.2K00
  • 开源网站监控利器:Utime Kuma部署指南

    🔍 Uptime Kuma 简介 GitHub 项目地址:https://github.com/louislam/uptime-kuma 一款开源自托管监控工具,支持多种协议检测(HTTP/TCP/Ping/DNS 等)和实时告警(飞书/钉钉/邮件等) 核心优势: 🚀 部署教程 Docker 部署 验证:访问 http://服务器IP:3001​ 完成初始化…

    2025年6月14日
    1.1K00
  • VMware vSphere中三种磁盘规格(厚置备延迟置零\厚置备置零\Thin Provision)

    在VMware vSphere中,不管是以前的5.1版本,或者是现在的6.5版本,创建虚拟机时,在创建磁盘时,都会让选择磁盘的置备类型,如下图所示,分为: (1)厚置备延迟置零; (2)厚置备置零; (3)Thin Provision(精简置备)。 在创建虚拟机时,可以选择这三种类型的其中一种,如下图所示 这三种类型的磁盘,每一种类型的磁…

    2023年8月11日
    90600
  • find命令排除某些目录或文件

    使用-prune开关。例如,如果要排除misc目录,只需将a添加-path ./misc -prune -o到您的find命令中: find . -path ./misc -prune -false -o -name ‘*.txt’ 这是带有多个目录的示例: find . -type d \( -path dir1 -o -path dir2 -o -pat…

    2023年6月16日
    1.5K00
  • Ubuntu系统如何配置镜像源

    我们在使用Linux系统时,一般来说都是需要配置一个源地址才能直接使用下载的命令来安装软件的,若你购买的是云服务器,正常来讲是服务器厂商配置好了源的,但是也不缺乏有少量的机器源会出现问题,导致安装软件不成功,如下图所示,那么我们就需要手动去配置了 第一步:替换原有的源 第二步:安装证书 如果安装失败,重新安装即可

    2022年6月14日
    1.5K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信