<div class="cs-rating pd-rating" id="pd_rating_holder_1819065_post_415"></div>
<p>Your windows “TaskManager” just went LIVE!</p>
<p>Imagine being able to broadcast your <a href="
https://www.thingspeak.com/channels/681/charts/1?round=2&timescale=2&yaxis=CPU&xaxis=Time&title=Laptop%20CPU-MEM">CPU</a>/<a href="
https://www.thingspeak.com/channels/681/charts/2?round=2&timescale=2&yaxis=Memory&xaxis=Time">MEM</a>/Disk capacity data or data from a hardware device or appliance (Arduino based sensor) to a service. Now imagine being able to view this data in a live graphical manner and being able to share it with the rest of the world (power to correlate data sets).</p>
<p>This well written article at <a href="
http://www.australianrobotics.com.au/content/how-talk-thingspeak-python-memorycpu-monitor">
http://www.australianrobotics.com.au/content/how-talk-thingspeak-python-memorycpu-monitor</a> inspired me to test out this capability and this post is a testament to the ease with which it can be done and a log of some minor modifications I had to make to make the example work with the latest version of Python (3.2).</p>
<p><a title="Things Speak" href="www.thingspeak.com">Thingsspeak</a> provides a data logging webservice with RESTful APIs to update the data. I outline the steps on how to use this service and provide links to live feed from my machine.</p>
<p>Steps:</p>
<ul>
<li style="list-style-type:none;">
<ul>
<li>You will need a <a href="
http://thingsspeak.com">Thingsspeak.com</a> account – Signup if you haven’t already</li>
<li>Create a channel at Thingsspeak [<a href="
https://www.thingspeak.com/channels/">https://www.thingspeak.com/channels/</a>]</li>
<li>Install Python – I got <a href="
http://www.python.org/getit/">version 3.2</a> and the code below uses this version</li>
<li>Download <a title="psutil" href="
http://code.google.com/p/psutil/">psutil </a>– install psutil for python version 3.2. You will need this python utility to monitor your processes on your computer [CPU, Memory etc]</li>
<li>Test your Thingsspeak REST call [ For example:
http://api.thingspeak.com/update?key=<your_api_key_here>&field1=0&field2&….]</li>
<li>Test Python http.client and urllib.parse and then run the code below [see <a href="
http://docs.python.org/py3k/library/http.client.html">http://docs.python.org/py3k/library/http.client.html</a>]</li>
<li>Result: You can see the graphs below, they represent the updates from my machine ….</li>
</ul>
</li>
</ul>
<p><strong>CPU</strong></p>
<p><a href="
https://www.thingspeak.com/channels/681/charts/1?round=2×cale=2&yaxis=CPU&xaxis=Time&title=Laptop%20CPU-MEM"><img class="aligncenter size-full wp-image-437" title="cpu" src="
http://alok-mishra.com/wp-content/uploads/2011/05/cpu.jpg" alt="" width="480" height="268" /></a></p>
<p><strong>Memory</strong><br />
<a href="
https://www.thingspeak.com/channels/681/charts/2?round=2×cale=2&yaxis=Memory&xaxis=Time"><img class="aligncenter size-full wp-image-438" title="mem" src="
http://alok-mishra.com/wp-content/uploads/2011/05/mem.jpg" alt="" width="475" height="264" /></a></p>
<p>The following code was obtain from <a href="
https://github.com/sirleech/thingspeak">https://github.com/sirleech/thingspeak</a> and modified to use the python 3.2 libraries</p>
<pre> #--------------------------------------------------------------------
#
# Original Source:
https://github.com/sirleech/thingspeak
#--------------------------------------------------------------------
import http.client, urllib.parse
from time import localtime, strftime
# download from
http://code.google.com/p/psutil/
import psutil
import time
def doit():
cpu_pc = psutil.cpu_percent()
mem_avail_mb = psutil.avail_phymem()/1000000
params = urllib.parse.urlencode({'field1': cpu_pc, 'field2': mem_avail_mb,'key':'XBYEL45GOXF7F760'})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = http.client.HTTPConnection("api.thingspeak.com:80")
try:
conn.request("POST", "/update", params, headers)
response = conn.getresponse()
print (cpu_pc)
print (mem_avail_mb)
print (strftime("%a, %d %b %Y %H:%M:%S", localtime()))
print (response.status, response.reason)
data = response.read()
conn.close()
except:
print ("connection failed")
print (response.status, response.reason)
#sleep for 16 seconds (api limit of 15 secs)
if __name__ == "__main__":
while True:
doit()
time.sleep(16)</pre>
Your windows “TaskManager” just went LIVE!
Imagine being able to broadcast your CPU/MEM/Disk capacity data or data from a hardware device or appliance (Arduino based sensor) to a service. Now imagine being able to view this data in a live graphical manner and being able to share it with the rest of the world (power to correlate data sets).
This well written article at http://www.australianrobotics.com.au/content/how-talk-thingspeak-python-memorycpu-monitor inspired me to test out this capability and this post is a testament to the ease with which it can be done and a log of some minor modifications I had to make to make the example work with the latest version of Python (3.2).
Thingsspeak provides a data logging webservice with RESTful APIs to update the data. I outline the steps on how to use this service and provide links to live feed from my machine.
Steps:
CPU

Memory

The following code was obtain from https://github.com/sirleech/thingspeak and modified to use the python 3.2 libraries
#--------------------------------------------------------------------
#
# Original Source: https://github.com/sirleech/thingspeak
#--------------------------------------------------------------------
import http.client, urllib.parse
from time import localtime, strftime
# download from http://code.google.com/p/psutil/
import psutil
import time
def doit():
cpu_pc = psutil.cpu_percent()
mem_avail_mb = psutil.avail_phymem()/1000000
params = urllib.parse.urlencode({'field1': cpu_pc, 'field2': mem_avail_mb,'key':'XBYEL45GOXF7F760'})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = http.client.HTTPConnection("api.thingspeak.com:80")
try:
conn.request("POST", "/update", params, headers)
response = conn.getresponse()
print (cpu_pc)
print (mem_avail_mb)
print (strftime("%a, %d %b %Y %H:%M:%S", localtime()))
print (response.status, response.reason)
data = response.read()
conn.close()
except:
print ("connection failed")
print (response.status, response.reason)
#sleep for 16 seconds (api limit of 15 secs)
if __name__ == "__main__":
while True:
doit()
time.sleep(16)