2025/01/10

在PVE中撈出所有guest的 cpu使用率並在超過上限值時發出告警


#!/bin/bash

pvesh get /cluster/resources|awk '{print $2" "$33" "$8}'|grep -E "lxc|qemu"|sed 's/....$//' > /tmp/all_guest_cpu

cat /tmp/all_guest_cpu | awk  '$3 > 80 {print $0}' > /tmp/guest_cpu_high

if [ -s /tmp/guest_cpu_high ]; then

        sed -i '1i network guest cpu high' /tmp/guest_cpu_high
        sed -i '2i ==========' /tmp/guest_cpu_high
        cp /tmp/guest_cpu_high /tmp/guest_cpu_high_network
        /usr/bin/lftp ftp://user:pwd@10.0.0.1 -e "put /tmp/guest_cpu_high_network; bye"
        mutt -s guest_cpu_high user@abc.com < /tmp/guest_cpu_high

fi

沒有留言: