Linux

zabbix 前10 CPU占用

一个crontab 定时写 top.txt

 #!/bin/sh
 top -n -b 1 > /tmp/top.txt

分析脚本->zabbix自动发现规则数据格式

#!/bin/bash
    TABLESPACE=`tail -n +8 /tmp/top.txt|awk '{a[$NF]+=$6}END{for(k in a)print a[k]/1024,k}'|sort -gr|head -10|cut -d" " -f2`
        COUNT=`echo "$TABLESPACE" |wc -l`
    INDEX=0
    echo '{"data":['
    echo "$TABLESPACE" | while read LINE; do
        echo -n '{"{#PROCESSNAME}":"'$LINE'"}'
        INDEX=`expr $INDEX + 1`
        if [ $INDEX -lt $COUNT ]; then
            echo ','
        fi
    done
    echo ']}'

回复

This is just a placeholder img.