#!/bin/bash
#################################################
#
#      Filename: monitor_softirp_usagecount.sh
#
#        Author: scott.liu@ucloud.cn
#   Description: ---
#        Create: 2019-04-03 11:52:11
# Last Modified: 2019-04-03 15:14:46
#################################################
#监控软中断大于某阈值的核数
THRESHOLD1=50
THRESHOLD2=85

ret=`mpstat -P ALL 1 1 | grep "Average:"| grep -v CPU|sed '1d'|awk '{print $8}'`

usage=($ret)
count1=0
count2=0
for u in ${usage[@]}
do
    if [ `printf "%.0f" "$u"` -ge $THRESHOLD1 ];then
        count1=$(($count1+1))
    fi
    if [ `printf "%.0f" "$u"` -ge $THRESHOLD2 ];then
        count2=$(($count2+1))
    fi
done
echo "[{\"value\":$count1,\"tags\":\"threshold=$THRESHOLD1\"},{\"value\":$count2,\"tags\":\"threshold=$THRESHOLD2\"}]"
