Skip to content

Commit 25523ec

Browse files
committed
pep8: tabs and trailing whitespace
1 parent 79a8648 commit 25523ec

1 file changed

Lines changed: 67 additions & 67 deletions

File tree

rabbit/python_modules/rabbitmq.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
JSON_PATH_SEPARATOR = "?"
2121
METRIC_TOKEN_SEPARATOR = "___"
22-
22+
2323
INTERVAL = 10
2424
descriptors = list()
2525
username, password = "guest", "guest"
@@ -57,15 +57,15 @@
5757
]
5858

5959
QUEUE_METRICS = ['rmq_messages_ready',
60-
'rmq_messages_unacknowledged',
61-
'rmq_backing_queue_ack_egress_rate',
62-
'rmq_backing_queue_ack_ingress_rate',
63-
'rmq_backing_queue_egress_rate',
64-
'rmq_backing_queue_ingress_rate',
65-
'rmq_backing_queue_mirror_senders',
66-
'rmq_memory',
60+
'rmq_messages_unacknowledged',
61+
'rmq_backing_queue_ack_egress_rate',
62+
'rmq_backing_queue_ack_ingress_rate',
63+
'rmq_backing_queue_egress_rate',
64+
'rmq_backing_queue_ingress_rate',
65+
'rmq_backing_queue_mirror_senders',
66+
'rmq_memory',
6767
'rmq_consumers',
68-
'rmq_messages']
68+
'rmq_messages']
6969

7070
# NODE METRICS #
7171
keyToPath['rmq_disk_free'] = "%s{0}disk_free".format(JSON_PATH_SEPARATOR)
@@ -96,7 +96,7 @@ def metric_cleanup():
9696

9797
def dig_it_up(obj,path):
9898
try:
99-
path = path.split(JSON_PATH_SEPARATOR)
99+
path = path.split(JSON_PATH_SEPARATOR)
100100
return reduce(lambda x,y:x[y],path,obj)
101101
except Exception, e:
102102
# not WARN because the False return is used for control flow
@@ -117,22 +117,22 @@ def refreshStats(stats = ('nodes', 'queues'), vhosts = ['/']):
117117
diff = now - last_update
118118

119119
if diff >= INTERVAL or not last_update:
120-
log.debug("Fetching Results after %d seconds" % INTERVAL)
121-
last_update = now
120+
log.debug("Fetching Results after %d seconds" % INTERVAL)
121+
last_update = now
122122
for stat in stats:
123123
for vhost in vhosts:
124124
if stat in ('nodes'):
125125
vhost = '/'
126-
result_dict = {}
126+
result_dict = {}
127127
urlstring = url_template.safe_substitute(stats = stat, vhost = vhost)
128128
log.debug('urlspring: %s' % urlstring)
129129
result = json.load(urllib2.urlopen(urlstring))
130-
# Rearrange results so entry is held in a dict keyed by name - queue name, host name, etc.
131-
if stat in ("queues", "nodes", "exchanges"):
132-
for entry in result:
133-
name = entry['name']
134-
result_dict[name] = entry
135-
compiled_results[(stat, vhost)] = result_dict
130+
# Rearrange results so entry is held in a dict keyed by name - queue name, host name, etc.
131+
if stat in ("queues", "nodes", "exchanges"):
132+
for entry in result:
133+
name = entry['name']
134+
result_dict[name] = entry
135+
compiled_results[(stat, vhost)] = result_dict
136136

137137
return compiled_results
138138

@@ -206,18 +206,18 @@ def getNodeStat(name):
206206
def getExchangeStat(name):
207207
refreshStats(stats = STATS, vhosts = vhosts)
208208
#Split a name like "rmq_backing_queue_ack_egress_rate.access"
209-
209+
210210
#handle queue names with . in them
211-
211+
212212
log.debug(name)
213213
stat_name, exchange_name, vhost = name.split(METRIC_TOKEN_SEPARATOR)
214-
214+
215215
vhost = vhost.replace('-', '/') #decoding vhost from metric name
216216
# Run refreshStats to get the result object
217217
result = compiled_results[('exchanges', vhost)]
218218

219219
value = dig_it_up(result, keyToPath[stat_name] % exchange_name)
220-
220+
221221
if zero_rates_when_idle and stat_name in RATE_METRICS and 'idle_since' in result[exchange_name].keys():
222222
value = 0
223223

@@ -246,7 +246,7 @@ def str2bool(string):
246246
if string.lower() in ("no", "false"):
247247
return False
248248
raise Exception("Invalid value of the 'zero_rates_when_idle' param, use one of the ('true', 'yes', 'false', 'no')")
249-
249+
250250
def metric_init(params):
251251
''' Create the metric definition object '''
252252
global descriptors, stats, vhost, username, password, urlstring, url_template, compiled_results, STATS, vhosts, zero_rates_when_idle
@@ -267,7 +267,7 @@ def metric_init(params):
267267
STATS = params['stats']
268268

269269
zero_rates_when_idle = str2bool(params['zero_rates_when_idle'])
270-
270+
271271
url = 'http://%s:%s/api/$stats/$vhost' % (host,port)
272272
base_url = 'http://%s:%s/api' % (host,port)
273273
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
@@ -285,24 +285,24 @@ def metric_handler(name):
285285
metric_handler.timestamp = time.time()
286286
return refreshStats(stats = STATS, vhosts = vhosts)
287287

288-
288+
289289

290290
def create_desc(prop):
291-
d = {
292-
'name' : 'XXX',
293-
'call_back' : getQueueStat,
294-
'time_max' : 60,
295-
'value_type' : 'uint',
296-
'units' : 'units',
297-
'slope' : 'both',
298-
'format' : '%d',
299-
'description' : 'XXX',
300-
'groups' : params["metric_group"],
301-
}
302-
303-
for k,v in prop.iteritems():
304-
d[k] = v
305-
return d
291+
d = {
292+
'name' : 'XXX',
293+
'call_back' : getQueueStat,
294+
'time_max' : 60,
295+
'value_type' : 'uint',
296+
'units' : 'units',
297+
'slope' : 'both',
298+
'format' : '%d',
299+
'description' : 'XXX',
300+
'groups' : params["metric_group"],
301+
}
302+
303+
for k,v in prop.iteritems():
304+
d[k] = v
305+
return d
306306

307307

308308
def buildQueueDescriptors():
@@ -311,30 +311,30 @@ def buildQueueDescriptors():
311311
for queue in queues:
312312
name = "{1}{0}{2}{0}{3}".format(METRIC_TOKEN_SEPARATOR, metric, queue, vhost.replace('/', '-'))
313313
log.debug(name)
314-
d1 = create_desc({'name': name.encode('ascii','ignore'),
315-
'call_back': getQueueStat,
314+
d1 = create_desc({'name': name.encode('ascii','ignore'),
315+
'call_back': getQueueStat,
316316
'value_type': 'float',
317-
'units': 'N',
318-
'slope': 'both',
319-
'format': '%f',
320-
'description': 'Queue_Metric',
321-
'groups' : 'rabbitmq,queue'})
322-
log.debug(d1)
323-
descriptors.append(d1)
324-
317+
'units': 'N',
318+
'slope': 'both',
319+
'format': '%f',
320+
'description': 'Queue_Metric',
321+
'groups' : 'rabbitmq,queue'})
322+
log.debug(d1)
323+
descriptors.append(d1)
324+
325325
def buildNodeDescriptors():
326326
for metric in NODE_METRICS:
327327
for node in list_nodes():
328328
name = "{1}{0}{2}{0}-".format(METRIC_TOKEN_SEPARATOR, metric, node)
329329
log.debug(name)
330330
d2 = create_desc({'name': name.encode('ascii','ignore'),
331-
'call_back': getNodeStat,
331+
'call_back': getNodeStat,
332332
'value_type': 'float',
333-
'units': 'N',
334-
'slope': 'both',
335-
'format': '%f',
336-
'description': 'Node_Metric',
337-
'groups' : 'rabbitmq,node'})
333+
'units': 'N',
334+
'slope': 'both',
335+
'format': '%f',
336+
'description': 'Node_Metric',
337+
'groups' : 'rabbitmq,node'})
338338
log.debug(d2)
339339
descriptors.append(d2)
340340

@@ -344,16 +344,16 @@ def buildExchangeDescriptors():
344344
for exchange in exchanges:
345345
name = "{1}{0}{2}{0}{3}".format(METRIC_TOKEN_SEPARATOR, metric, exchange, vhost.replace('/', '-'))
346346
log.debug(name)
347-
d1 = create_desc({'name': name.encode('ascii','ignore'),
348-
'call_back': getExchangeStat,
347+
d1 = create_desc({'name': name.encode('ascii','ignore'),
348+
'call_back': getExchangeStat,
349349
'value_type': 'float',
350-
'units': 'N',
351-
'slope': 'both',
352-
'format': '%f',
353-
'description': 'Exchange_Metric',
354-
'groups' : 'rabbitmq,exchange'})
355-
log.debug(d1)
356-
descriptors.append(d1)
350+
'units': 'N',
351+
'slope': 'both',
352+
'format': '%f',
353+
'description': 'Exchange_Metric',
354+
'groups' : 'rabbitmq,exchange'})
355+
log.debug(d1)
356+
descriptors.append(d1)
357357

358358
if 'queues' in STATS:
359359
buildQueueDescriptors()
@@ -362,7 +362,7 @@ def buildExchangeDescriptors():
362362
if 'exchanges' in STATS:
363363
buildExchangeDescriptors()
364364
# buildTestNodeStat()
365-
365+
366366
return descriptors
367367

368368
def metric_cleanup():

0 commit comments

Comments
 (0)