{"id":1244,"date":"2014-05-20T15:32:23","date_gmt":"2014-05-20T19:32:23","guid":{"rendered":"https:\/\/blogs.mathworks.com\/iot\/?p=1244"},"modified":"2014-09-23T12:09:03","modified_gmt":"2014-09-23T16:09:03","slug":"official-tutorial-monitoring-linux-server-statistics","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/iot\/2014\/05\/20\/official-tutorial-monitoring-linux-server-statistics\/","title":{"rendered":"[Official Tutorial] Monitoring Linux Server Statistics"},"content":{"rendered":"

ThingSpeak can be used to easily monitor CPU usage %, memory usage %, and disk usage % on any Linux machine connected to the internet.<\/p>\n

First, create\u00a0a new Channel, and fill out the field names as follows: Field 1 = “CPU Usage (%)”, Field2 = “Memory Usage (%)”, Field 3 = “Disk Usage (%)”.<\/p>\n

\"ThingSpeak<\/p>\n

Next, add the open-source server statistics script to your server, which can be found at:\u00a0https:\/\/raw.githubusercontent.com\/iobridge\/thingspeak\/master\/lib\/server_stats.sh<\/a><\/p>\n

Inside the script\u00a0there’s\u00a0an\u00a0API Key variable, which should be\u00a0replaced with your specific Channel’s API Key (leave the single quotes, and only replace the X’s):\u00a0api_key='XXXXXXXXXXXXXXXX'<\/code><\/p>\n

For the script to work properly, install the “bc” package via: sudo apt-get install bc<\/code><\/p>\n

Then make the script executable:\u00a0chmod +x server_stats.sh<\/code><\/p>\n

Finally, edit\u00a0your crontab file: crontab -e<\/code><\/p>\n

Make the script execute every minute by adding this line to your crontab (make sure you use the proper path to the script):\u00a0* * * * * \/path\/to\/server_stats.sh<\/code><\/p>\n

The script will then automatically POST server stats to the Channel specified by the API Key every minute.<\/p>\n