Skip to content

Instantly share code, notes, and snippets.

@Tryum
Created January 27, 2017 15:42
Show Gist options
  • Save Tryum/7da65a44283332dc115d67dde3fff8d3 to your computer and use it in GitHub Desktop.
Save Tryum/7da65a44283332dc115d67dde3fff8d3 to your computer and use it in GitHub Desktop.
output raspberry pi stats as json.
import json
import subprocess
temp = subprocess.check_output('cat /sys/class/thermal/thermal_zone0/temp | cut -c1-2', shell=True)
load = subprocess.check_output("uptime | awk '{print $10}' | head -c-2", shell=True)
mem_total = subprocess.check_output("free |grep 'Mem:' | awk '{print $2}'", shell=True)
mem_used = subprocess.check_output("free |grep 'Mem:' | awk '{print $3}'", shell=True)
disk_total = subprocess.check_output("df | grep '/' | awk '{print $2}'", shell=True)
disk_used = subprocess.check_output("df | grep '/' | awk '{print $3}'", shell=True)
out = {}
out["temp"] = int(temp)
out["mem"] = {}
out["mem"]["total"] = int(mem_total)
out["mem"]["used"] = int(mem_used)
out["disk"] = {}
out["disk"]["total"] = int(disk_total)
out["disk"]["used"] = int(disk_used)
print json.dumps(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment