Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # cosm.py Copyrigth 2012 Itxaka Serrano Garcia <[email protected]>
- # licensed under the GPL2
- # see the full license at http://www.gnu.org/licenses/gpl-2.0.txt
- # edited by Der-Eddy from elitepvpers
- import json, subprocess, os, time
- #add your privat stuff here
- feed = "FEED"
- apikey = "API_KEY"
- hdd = subprocess.check_output(["df | grep rootfs | awk '{print $2,$4,$5}'"], shell=True)
- hdd = hdd.split()
- hdd = int(hdd[1]) / 1024
- cpu = subprocess.check_output(["vmstat | awk '{print $13}'"], shell=True)
- cpu = cpu.split()[1]
- cpu_temp = subprocess.check_output(["sudo /opt/vc/bin/vcgencmd measure_temp | cut -c6-9"], shell=True)
- mem = subprocess.check_output(["cat /proc/meminfo | grep Mem | awk '{print $2}'"], shell=True)
- mem = mem.split()
- mem_total = int(mem[0]) / 1024
- mem_free = int(mem[1]) / 1024
- mem_used = mem_total - mem_free
- mhz = subprocess.check_output(["vcgencmd measure_clock arm | cut -d'=' -f2-"], shell=True)
- mhz = int(mhz) / 1000000
- mhz = int(round(mhz, -2))
- volts = subprocess.check_output(["vcgencmd measure_volts | cut -c6-9"], shell=True)
- up = float(subprocess.check_output(["cat /proc/uptime | cut -d'.' -f1-1"], shell=True))
- up = round(up / 60 / 60, 3)
- ps = subprocess.check_output(["ps -A | awk '{print $1}'"], shell=True)
- ps = len(ps) - 1
- data = json.dumps({"version":"1.0.0", "datastreams":[{"id":"hdd","current_value":hdd },{"id":"cpu","current_value":cpu},{"id":"free_mem","current_value":mem_free},{"id":"used_mem","current_value":mem_used},{"id":"cpu_temp","current_value":cpu_temp},{"id":"cpu_frequency","current_value":mhz},{"id":"uptime","current_value":up},{"id":"processes","current_value":ps},{"id":"volts_core","current_value":volts},]})
- with open("temp.json", "w") as f:
- f.write(data)
- subprocess.call(['curl --request PUT --data-binary @temp.json --header "X-ApiKey: {0}" --verbose http://api.cosm.com/v2/feeds/{1}'.format(apikey, feed)], shell=True)
- os.remove("temp.json")
Advertisement
Add Comment
Please, Sign In to add comment