#!/bin/bash
#cpu占用
#CPU=$(sar -P 0 -u 1 1|awk 'NR==5{printf("%.2f",$3+$5)}')
#CPU温度
CPU_TP=$(echo $[$(cat /sys/class/thermal/thermal_zone0/temp)/1000]°)
#内存
MEMORY=$(free -m|awk 'NR==2{printf ("%.2f",$3/$2)}')
#电流_电压_功率_温度
IVPT1=$(/opt/tool/saturn-get-ivpt.sh |cut -f 1 -d ' ')
IVPT2=$(/opt/tool/saturn-get-ivpt.sh |cut -f 2 -d ' ')
IVPT3=$(/opt/tool/saturn-get-ivpt.sh |cut -f 3 -d ' ')
IVPT4=$(/opt/tool/saturn-get-ivpt.sh |cut -f 4 -d ' ')
#IP
IP=$(ifconfig eth0|grep inet|awk 'NR==1{print $2}')
#MAC
MAC=$(ifconfig eth0|grep ether|awk '{print $2}')
#路由网关
GATEWAY=$(route -n|head -n3|tail -n1|tr -s ' '|cut -f 2 -d " ")
#运行时间
SYSTEM_T=$(cat /proc/uptime | awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}')
#系统版本
SYSTEM_V=$(cat /etc/os-release |tail -n 1|cut -f 2 -d '=')
#根目录容量
SYSTEM_C=$(df -m |grep -Ew '/'|tr -s ' '|cut -f 5 -d ' ')
#当前时间
TIME=$(export TZ=Asia/Shanghai && date +%Y-%m-%d/%H:%M:%S)
wait
json='{"cpu_tem":"'"$CPU_TP"'","memory_use_rate":'"$MEMORY"',"electric_current":'"$IVPT1"',"voltage":'"$IVPT2"',"power":'"$IVPT3"',"temperature":'"$IVPT4"',"ip":"'"$IP"'","mac_add_str":"'"$MAC"'","gateway_ip":"'"$GATEWAY"'","system_running_time":"'"$SYSTEM_T"'","system_version":'"$SYSTEM_V"',"system_disk_use":"'"$SYSTEM_C"'","time_string":"'"$TIME"'"}'
echo -e $json