Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # cosm.py Copyrigth 2012 Itxaka Serrano Garcia <itxakaserrano@gmail.com>
- # licensed under the GPL2
- # see the full license at http://www.gnu.org/licenses/gpl-2.0.txt
- #
- # You only need to add 2 things, YOUR_API KEY HERE and YOUR_FEED_NUMBER_HERE
- # also, you can change your stream ids, in that case change the id names in the "data = json.dumps..." line
- import json, subprocess, os
- 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]
- 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
- 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}]})
- with open("temp.tmp", "w") as f:
- f.write(data)
- subprocess.call(['curl --request PUT --data-binary @temp.tmp --header "X-ApiKey: YOUR_IP_KEY_HERE" http://api.cosm.com/v2/feeds/YOUR_FEED_NUMBER_HERE'], shell=True)
- os.remove("temp.tmp")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement