{"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":"<p>ThingSpeak can be used to easily monitor CPU usage %, memory usage %, and disk usage % on any Linux machine connected to the internet.<\/p>\n<p>First, create\u00a0a new Channel, and fill out the field names as follows: Field 1 = &#8220;CPU Usage (%)&#8221;, Field2 = &#8220;Memory Usage (%)&#8221;, Field 3 = &#8220;Disk Usage (%)&#8221;.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1245\" src=\"https:\/\/blogs.mathworks.com\/iot\/wp-content\/blogs.dir\/15\/files\/2014\/05\/channel.png\" alt=\"ThingSpeak Channel Settings\" width=\"298\" height=\"250\" \/><\/p>\n<p>Next, add the open-source server statistics script to your server, which can be found at:\u00a0<a title=\"https:\/\/raw.githubusercontent.com\/iobridge\/thingspeak\/master\/lib\/server_stats.sh\" href=\"https:\/\/raw.githubusercontent.com\/iobridge\/thingspeak\/master\/lib\/server_stats.sh\">https:\/\/raw.githubusercontent.com\/iobridge\/thingspeak\/master\/lib\/server_stats.sh<\/a><\/p>\n<p>Inside the script\u00a0there&#8217;s\u00a0an\u00a0API Key variable, which should be\u00a0replaced with your specific Channel&#8217;s API Key (leave the single quotes, and only replace the X&#8217;s):\u00a0<code>api_key='XXXXXXXXXXXXXXXX'<\/code><\/p>\n<p>For the script to work properly, install the &#8220;bc&#8221; package via: <code>sudo apt-get install bc<\/code><\/p>\n<p>Then make the script executable:\u00a0<code>chmod +x server_stats.sh<\/code><\/p>\n<p>Finally, edit\u00a0your crontab file: <code>crontab -e<\/code><\/p>\n<p>Make the script execute every minute by adding this line to your crontab (make sure you use the proper path to the script):\u00a0<code>* * * * * \/path\/to\/server_stats.sh<\/code><\/p>\n<p>The script will then automatically POST server stats to the Channel specified by the API Key every minute.<\/p>\n<p style=\"text-align: center;\"><script type='text\/javascript'>  \nwindow.onload = document.write(\"<iframe width='600' height='240' marginwidth='0' marginheight='0' scrolling='auto' frameborder='0'  src='http:\/\/api.thingspeak.com\/channels\/12370\/charts\/1?width=auto&amp;height=auto&amp;results=30&amp;dynamic=true' ><\/iframe> \"); \n <\/script><\/p>\n<p>You can see some of the ThingSpeak server statistics here:<\/p>\n<ul>\n<li><a title=\"https:\/\/thingspeak.com\/channels\/12370\" href=\"https:\/\/thingspeak.com\/channels\/12370\" target=\"_blank\">https:\/\/thingspeak.com\/channels\/12370<\/a><\/li>\n<li><a title=\"https:\/\/thingspeak.com\/channels\/12371\" href=\"https:\/\/thingspeak.com\/channels\/12371\" target=\"_blank\">https:\/\/thingspeak.com\/channels\/12371<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/iot\/wp-content\/blogs.dir\/15\/files\/2014\/05\/channel.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>ThingSpeak can be used to easily monitor CPU usage %, memory usage %, and disk usage % on any Linux machine connected to the internet.<br \/>\nFirst, create\u00a0a new Channel, and fill out the field names as&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/iot\/2014\/05\/20\/official-tutorial-monitoring-linux-server-statistics\/\">read more >><\/a><\/p>\n","protected":false},"author":148,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[30,17,49,60,50],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1244"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/users\/148"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/comments?post=1244"}],"version-history":[{"count":18,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1244\/revisions"}],"predecessor-version":[{"id":1290,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/posts\/1244\/revisions\/1290"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/media?parent=1244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/categories?post=1244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/iot\/wp-json\/wp\/v2\/tags?post=1244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}