Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #!/usr/bin/python
  2. """Copyright 2008 Orbitz WorldWide
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License."""
  12. import sys
  13. import time
  14. import os
  15. import platform
  16. import subprocess
  17. from socket import socket
  18. import elasticsearch
  19.  
  20. CARBON_SERVER = '127.0.0.1'
  21. CARBON_PORT = 2003
  22. delay = 60
  23.  
  24. if len(sys.argv) > 1:
  25. delay = int( sys.argv[1] )
  26.  
  27. def getElasticsearchInfo(elasticInstance, query):
  28. return elasticInstance.search(body={"query": query})
  29.  
  30.  
  31. sock = socket()
  32. try:
  33. sock.connect( (CARBON_SERVER,CARBON_PORT) )
  34. except:
  35. print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }
  36. sys.exit(1)
  37.  
  38. try:
  39. es = elasticsearch.Elasticsearch()
  40. except:
  41. print "Couldn't connect to localhost as a elasticsearch server. check if elasticsearch running HERE"
  42. sys.exit(1)
  43.  
  44. while True:
  45. now = int( time.time() )
  46. lines = getElasticsearchInfo(es, '{"term" : { "plugin" : "statsd" } }')
  47. #We're gonna report all three loadavg values
  48. #loadavg = get_loadavg()
  49. #lines.append("system.loadavg_1min %s %d" % (loadavg[0],now))
  50. #lines.append("system.loadavg_5min %s %d" % (loadavg[1],now))
  51. #lines.append("system.loadavg_15min %s %d" % (loadavg[2],now))
  52. message = '\n'.join(lines) + '\n' #all lines must end in a newline
  53. print("sending message\n")
  54. print('-' * 80)
  55. print(message)
  56. print
  57. #sock.sendall(message)
  58. print(lines)
  59. time.sleep(delay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement