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:

@csrf_exempt
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)

Python Powered | © 2012-2014 Kevin Veroneau