#!/bin/sh
. /usr/share/libubox/jshn.sh
#CPU_INFO=/tmp/cpu_info
rate_threshold=20

while true
do
	#curl -o $CPU_INFO -v -k -X GET "https://127.0.0.1:4430/api/sys/sys_info" -H "accept: */*" -H "Content-Type: application/json" -H "Authorization: Bearer " 2>/dev/null

	#cpu_info=$(cat $CPU_INFO)
	cpu_idle=$(top -n 1|grep idle |awk -F' ' '{print $8}')
	if [ "$cpu_idle" != "" ]; then
		#cat /tmp/cpu_info  |cut -d '{' -f3 |cut -d ':' -f6 |awk -F '"' '{print $2}'
		#info="{$(cat /tmp/cpu_info |cut -d '{' -f3)\"\"}"
		#echo $info >/dev/console
		#json_load "$info"
		#json_get_var cpu_loading			cpu_loading
		#echo "===========$cpu_loading" >/dev/console
		#echo "====$cpu_idle" >/dev/console
		cpu_idle_rate=`echo "$cpu_idle" |cut -d '%' -f1`
		#echo "====$cpu_idle_rate" >/dev/console
		if [ $cpu_idle_rate -lt $rate_threshold ]; then
			logger "cpu load rate is greater then 80%" -t cpu -p 5
			#echo "cpu load rate is greater then 80%" >/dev/console
		#else
			#logger "cpu load rate is less then 80%" -t cpu -p 5
		fi
	fi
	sleep 300;
done
