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, re
- #add your privat stuff here
- feed = "feed"
- apikey = "api_key"
- hdd = subprocess.check_output(["df | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $3 }'"], 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
- 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":"mem_free","current_value":mem_free},{"id":"mem_used","current_value":mem_used},{"id":"uptime","current_value":up},{"id":"processes","current_value":ps},]})
- 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