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

相关推荐

  • Windows下安装Nginx错误总结

    别问我为啥非要在Windows上按照Nginx,问的话,回答就是:有这个需求 1:CreateFile()“xxxxx” failed (3: The system cannot find the path specified) 产生原因:创建文件xxxx异常了。大多数情况就是因为:安装目录中存在中文或者是空格 比如凯哥的就是因为存在空格。凯哥第一…

    2024年5月11日
    87600
  • 实验案例:日志分析及系统故障修复

    公司使用的Linux服务器越来越多,经常会有个别服务器出现启动引导、文件系统等故障。为了避免出现上述故障时,无法快速定位故障原因与及时处理故障,公司新招的运维人员小王需要提前进行排障演练并熟悉系统内各种日志文件,以便在需要时能够及时修复系统故障。 日志文件分析 在终端tty3中尝试以不存在的用户账号Administrator进行登录 新建用户账号admin并…

    2024年6月25日
    1.6K00
  • centos7 丢失grub无法启动

    1、使用CentOS7的原版镜像开机从光驱启动 当然你也可以做成启动U盘,从U盘启动 2、选择Troubleshooting->Rescue a CentOS system 3、根据提示先选择1 提示没有找到任何Linux分区,这时会进入shell 4、发现LVM逻辑卷 可以看到/dev/sda2为LVM2_member 5、挂载故障根分区到/mnt/sys…

    2023年7月20日
    1.0K00
  • Windows 添加新用户,并授予该用户远程登录权限

    首先添加新用户: 以管理员身份登录,选择“更改账户设置”:  选择 “其他用户” –> “将其他人添加到这台电脑”: 选择  “用户”: 单击鼠标右键,选择  “新用户”: 选择新建用户,单击鼠标右键,选择 “属性”: 接下来授予远程登陆权限: ——只需要将该用户加入 “Remote Desktop Users” 组即可。

    2023年6月29日
    1.2K00
  • Ansible修改Windows系统的环境变量

    使用Ansible修改Windows系统的环境变量,包括tmp环境变量,可以按照以下步骤进行操作: 主要目的用于修改下载文件的临时缓存目录 这样设置过后就可以使用ansible批量下载大文件了。

    2024年3月21日
    96800

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信