You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

60_plugin_status.py 935 B

6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # author: ulric.qin@gmail.com
  4. import time
  5. import commands
  6. import json
  7. import sys
  8. import os
  9. items = []
  10. def collect_myself_status():
  11. item = {}
  12. item["metric"] = "plugin.myself.status"
  13. item["value"] = 1
  14. item["tags"] = ""
  15. items.append(item)
  16. def main():
  17. code, endpoint = commands.getstatusoutput(
  18. "timeout 1 /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1")
  19. if code != 0:
  20. sys.stderr.write('cannot get local ip')
  21. return
  22. timestamp = int("%d" % time.time())
  23. plugin_name = os.path.basename(sys.argv[0])
  24. step = int(plugin_name.split("_", 1)[0])
  25. collect_myself_status()
  26. for item in items:
  27. item["endpoint"] = endpoint
  28. item["timestamp"] = timestamp
  29. item["step"] = step
  30. print json.dumps(items)
  31. if __name__ == "__main__":
  32. main()