Saturday, April 9th, 2011

View Django uptime on your Chumby

This post is from my old blog. The exact publishing date has been preserved for archival reasons.

Here is the code you can use in a Django view to be compatible with your Chumby uptime widget:

def uptime(req):
  if 'pass' not in req.REQUEST or req.REQUEST['pass']!='pass':
    raise Http404
  uptime = open('/proc/uptime','r').read()[:-1].split(' ')
  load = open('/proc/loadavg','r').read()[:-1].split(' ')
  json = "uptime=%d&load0=%s&load1=%s&load2=%s&" % (int(uptime[0][:-3]), load[0], load[1], load[2])
  return HttpResponse(json)

About Me

My Photo
Names Kevin, hugely into UNIX technologies, not just Linux. I've dabbled with the demons, played with the Sun, and now with the Penguins.

Kevin Veroneau Consulting Services
Do you require the services of a Django contractor? Do you need both a website and hosting services? Perhaps I can help.

This Month

If you like what you read, please consider donating to help with hosting costs, and to fund future books to review.

Python Powered | © 2012-2019 Kevin Veroneau