Difference between revisions of "Home Assistant"
From My Wiki
(Created page with "Here will be some interesting stuff related to Home assistant (hassio)") |
|||
| Line 1: | Line 1: | ||
| − | + | Send VPS statistics to HA | |
| + | |||
| + | Update token ($apitoken), address ($apiaddr) and disk device ($disk) | ||
| + | |||
| + | #!/bin/bash | ||
| + | |||
| + | apitoken="xxxxxx" | ||
| + | apiaddr="https://ha.myhome:8123/api/states/" | ||
| + | apiheaders=" -H \"Authorization: Bearer $apitoken\" -H \"Content-Type: application/json\" " | ||
| + | apihost=`hostname|sed "s/\./_/g"` | ||
| + | apiurl="sensor.$apihost" | ||
| + | |||
| + | disk="/dev/vda" | ||
| + | |||
| + | srvuptime=`uptime -p` | ||
| + | srvmem=`free -m |grep "Mem"|awk '{print ($4+$7)"M"}'` | ||
| + | srvprocs=`ps -ef|wc -l` | ||
| + | diskuse=`df -h $disk |grep "/$"|awk '{print $5}'` | ||
| + | diskio=`df -ih $disk |grep "/$"|awk '{print $5}'` | ||
| + | netcons=`netstat -ant|grep ESTA|wc -l` | ||
| + | mailqu=`exim -bpc` | ||
| + | |||
| + | srvtmp=`cat /proc/loadavg` | ||
| + | read -r -a srvla <<< "$srvtmp" | ||
| + | |||
| + | apidata=" -d '{\"state\":\"$srvuptime\", \"attributes\": {\"friendly_name\":\"$apihost\",\"uptime\":\"$srvuptime\",\"freemem\":\"$srvmem\",\"load\":\"${srvla[0]} ${srvla[1]} ${srvla[2]}\",\"procs\":$srvprocs,\"disk_use_$disk\":\"$diskuse\",\"disk_io_use_$disk\":\"$diskio\",\"connections\":$netcons,\"mail_queue\":$mailqu}}'" | ||
| + | |||
| + | bash -c "curl $apiaddr$apiurl $apiheaders -X POST $apidata -k" | ||
Revision as of 11:16, 11 June 2020
Send VPS statistics to HA
Update token ($apitoken), address ($apiaddr) and disk device ($disk)
#!/bin/bash apitoken="xxxxxx" apiaddr="https://ha.myhome:8123/api/states/" apiheaders=" -H \"Authorization: Bearer $apitoken\" -H \"Content-Type: application/json\" " apihost=`hostname|sed "s/\./_/g"` apiurl="sensor.$apihost" disk="/dev/vda" srvuptime=`uptime -p` srvmem=`free -m |grep "Mem"|awk '{print ($4+$7)"M"}'` srvprocs=`ps -ef|wc -l` diskuse=`df -h $disk |grep "/$"|awk '{print $5}'` diskio=`df -ih $disk |grep "/$"|awk '{print $5}'` netcons=`netstat -ant|grep ESTA|wc -l` mailqu=`exim -bpc` srvtmp=`cat /proc/loadavg` read -r -a srvla <<< "$srvtmp" apidata=" -d '{\"state\":\"$srvuptime\", \"attributes\": {\"friendly_name\":\"$apihost\",\"uptime\":\"$srvuptime\",\"freemem\":\"$srvmem\",\"load\":\"${srvla[0]} ${srvla[1]} ${srvla[2]}\",\"procs\":$srvprocs,\"disk_use_$disk\":\"$diskuse\",\"disk_io_use_$disk\":\"$diskio\",\"connections\":$netcons,\"mail_queue\":$mailqu}}'" bash -c "curl $apiaddr$apiurl $apiheaders -X POST $apidata -k"