66import time
77from string import Template
88import itertools
9+ import threading
910
1011global url , descriptors , last_update , vhost , username , password , url_template , result , result_dict , keyToPath
11- INTERVAL = 20
12+ INTERVAL = 10
1213descriptors = list ()
1314username , password = "guest" , "guest"
1415stats = {}
6364NODE_METRICS = ['rmq_disk_free' , 'rmq_mem_used' , 'rmq_disk_free_alarm' , 'rmq_running' , 'rmq_proc_used' , 'rmq_mem_proc_used' , 'rmq_fd_used' , 'rmq_mem_alarm' , 'rmq_mem_code' , 'rmq_mem_binary' , 'rmq_sockets_used' ]
6465
6566
67+
68+
6669def metric_cleanup ():
6770 pass
6871
@@ -123,6 +126,7 @@ def list_nodes():
123126 return nodes
124127
125128def getQueueStat (name ):
129+ refreshStats (stats = STATS , vhosts = vhosts )
126130 #Split a name like "rmq_backing_queue_ack_egress_rate.access"
127131
128132 #handle queue names with . in them
@@ -147,6 +151,7 @@ def getQueueStat(name):
147151 return float (value )
148152
149153def getNodeStat (name ):
154+ refreshStats (stats = STATS , vhosts = vhosts )
150155 #Split a name like "rmq_backing_queue_ack_egress_rate.access"
151156 stat_name = name .split ("." )[0 ]
152157 node_name , vhost = name .split ("." )[1 ].split ("#" )
@@ -174,7 +179,7 @@ def product(*args, **kwds):
174179
175180def metric_init (params ):
176181 ''' Create the metric definition object '''
177- global descriptors , stats , vhost , username , password , urlstring , url_template , compiled_results , STATS
182+ global descriptors , stats , vhost , username , password , urlstring , url_template , compiled_results , STATS , vhosts
178183 print 'received the following params:'
179184 #Set this globally so we can refresh stats
180185 if 'host' not in params :
@@ -191,6 +196,13 @@ def metric_init(params):
191196
192197 refreshStats (stats = STATS , vhosts = vhosts )
193198
199+ def metric_handler (name ):
200+ if 15 < time .time () - metric_handler .timestamp :
201+ metric_handler .timestamp = time .time ()
202+ return refreshStats (stats = STATS , vhosts = vhosts )
203+
204+
205+
194206 def create_desc (prop ):
195207 d = {
196208 'name' : 'XXX' ,
@@ -259,6 +271,6 @@ def metric_cleanup():
259271 metric_init (parameters )
260272 result = refreshStats (stats = ('queues' , 'nodes' ), vhosts = ('/' ))
261273 print '***' * 10
262- getQueueStat ('rmq_backing_queue_ack_egress_rate.gelf_client_three #/' )
274+ getQueueStat ('rmq_backing_queue_ack_egress_rate.nfl_client #/' )
263275 getNodeStat ('rmq_disk_free.rmqtwo@inrmq02d1#/' )
264276 getNodeStat ('rmq_mem_used.rmqtwo@inrmq02d1#/' )
0 commit comments