DerEddy

cosm.vps

Apr 21st, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # cosm.py Copyrigth 2012 Itxaka Serrano Garcia <[email protected]>  
  3. # licensed under the GPL2  
  4. # see the full license at http://www.gnu.org/licenses/gpl-2.0.txt  
  5. # edited by Der-Eddy from elitepvpers
  6.  
  7. import json, subprocess, os, time, re
  8.  
  9. #add your privat stuff here
  10. feed = "feed"
  11. apikey = "api_key"
  12.  
  13. hdd = subprocess.check_output(["df | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $3 }'"], shell=True)
  14. hdd = hdd.split()
  15. hdd = int(hdd[1]) / 1024
  16.  
  17. cpu = subprocess.check_output(["vmstat | awk '{print $13}'"], shell=True)
  18. cpu = cpu.split()[1]
  19.  
  20. mem = subprocess.check_output(["cat /proc/meminfo | grep Mem | awk '{print $2}'"], shell=True)
  21. mem = mem.split()
  22. mem_total = int(mem[0]) / 1024
  23. mem_free = int(mem[1]) / 1024
  24. mem_used = mem_total - mem_free
  25.  
  26. up = float(subprocess.check_output(["cat /proc/uptime | cut -d'.' -f1-1"], shell=True))
  27. up = round(up / 60 / 60, 3)
  28.  
  29. ps = subprocess.check_output(["ps -A | awk '{print $1}'"], shell=True)
  30. ps = len(ps) - 1
  31.  
  32. 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},]})
  33. with open("temp.json", "w") as f:
  34.     f.write(data)
  35. 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)
  36.  
  37. os.remove("temp.json")
Advertisement
Add Comment
Please, Sign In to add comment