Skip to content

Commit

Permalink
Use automatic formatters (py2.7+)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 15, 2018
1 parent ca8b73d commit 20c7903
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bin/diamond
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def main():
# join() on each of them. This guarantees that the
# SyncManager is terminated last (implicitly as a result of
# us exiting).
child_debug = "Terminating and joining on: {0} ({1})"
child_debug = "Terminating and joining on: {} ({})"
log.debug(child_debug.format(child.name, child.pid))
child.terminate()
child.join()
Expand Down
2 changes: 1 addition & 1 deletion bin/diamond-setup
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ if __name__ == "__main__":
config_file.write()

except IOError, (errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)
print "I/O error({}): {}".format(errno, strerror)
except KeyboardInterrupt:
print
sys.exit()
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/amavis/amavis.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def collect(self):
if metric in ('count', 'time'):
mtype = 'COUNTER'
precision = 0
self.publish("{0}.{1}".format(name, metric),
self.publish("{}.{}".format(name, metric),
value, metric_type=mtype,
precision=precision)

Expand Down
2 changes: 1 addition & 1 deletion src/collectors/docker_collector/docker_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_value(self, path, dictionary):
cur = dictionary
for key in keys:
if not isinstance(cur, dict):
raise Exception("metric '{0}' does not exist".format(path))
raise Exception("metric '{}' does not exist".format(path))
cur = cur.get(key)
if cur is None:
break
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/drbd/drbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def collect(self):
continue
statusfile.close()
except IOError, errormsg:
self.log.error("Can't read DRBD status file: {0}".format(errormsg))
self.log.error("Can't read DRBD status file: {}".format(errormsg))
return

for resource in results.keys():
Expand Down
6 changes: 3 additions & 3 deletions src/collectors/flume/flume.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_default_config(self):
return default_config

def collect(self):
url = 'http://{0}:{1}{2}'.format(
url = 'http://{}:{}{}'.format(
self.config['req_host'],
self.config['req_port'],
self.config['req_path']
Expand Down Expand Up @@ -101,11 +101,11 @@ def collect(self):

for item in self._metrics_collect[comp_type]:
if item.endswith('Count'):
metric_name = '{0}.{1}'.format(comp_name, item[:-5])
metric_name = '{}.{}'.format(comp_name, item[:-5])
metric_value = int(comp_items[item])
self.publish_counter(metric_name, metric_value)
elif item.endswith('Percentage'):
metric_name = '{0}.{1}'.format(comp_name, item)
metric_name = '{}.{}'.format(comp_name, item)
metric_value = float(comp_items[item])
self.publish_gauge(metric_name, metric_value)
else:
Expand Down
12 changes: 6 additions & 6 deletions src/collectors/jcollectd/jcollectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(self, host, port, log, poll_interval=0.4):
self.queue = Queue.Queue()

def run(self):
self.log.info('ListenerThread started on {0}:{1}(udp)'.format(
self.log.info('ListenerThread started on {}:{}(udp)'.format(
self.host, self.port))

rdr = collectd_network.Reader(self.host, self.port)
Expand All @@ -132,10 +132,10 @@ def run(self):
items = rdr.interpret(poll_interval=self.poll_interval)
self.send_to_collector(items)
except ValueError, e:
self.log.warn('Dropping bad packet: {0}'.format(e))
self.log.warn('Dropping bad packet: {}'.format(e))
except Exception, e:
self.log.error('caught exception: type={0}, exc={1}'.format(type(e),
e))
self.log.error('caught exception: type={}, exc={}'.format(
type(e), e))

self.log.info('ListenerThread - stop')

Expand All @@ -150,8 +150,8 @@ def send_to_collector(self, items):
except Queue.Full:
self.log.error('Queue to collector is FULL')
except Exception, e:
self.log.error('B00M! type={0}, exception={1}'.format(type(e),
e))
self.log.error('B00M! type={}, exception={}'.format(
type(e), e))

def transform(self, item):

Expand Down
6 changes: 3 additions & 3 deletions src/collectors/rabbitmq/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def collect_health(self):
node_name = client.get_overview()['node']
node_data = client.get_node(node_name)
for metric in health_metrics:
self.publish('health.{0}'.format(metric), node_data[metric])
self.publish('health.{}'.format(metric), node_data[metric])
if self.config['cluster']:
self.publish('cluster.partitions',
len(node_data['partitions']))
Expand Down Expand Up @@ -270,7 +270,7 @@ def collect(self):
queue_name = queue_name.replace(
'/', self.config['replace_slash'])

name = '{0}.{1}'.format(prefix, queue_name)
name = '{}.{}'.format(prefix, queue_name)

self._publish_metrics(name, [], key, queue)

Expand All @@ -291,7 +291,7 @@ def _publish_metrics(self, name, prev_keys, key, data):
elif isinstance(value, (float, int, long)):
joined_keys = '.'.join(keys)
if name:
publish_key = '{0}.{1}'.format(name, joined_keys)
publish_key = '{}.{}'.format(name, joined_keys)
else:
publish_key = joined_keys
if isinstance(value, bool):
Expand Down
4 changes: 2 additions & 2 deletions src/collectors/snmp/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get(self, oid, host, port, community):

# Assemble SNMP Auth Data
snmpAuthData = cmdgen.CommunityData(
'agent-{0}'.format(community),
'agent-{}'.format(community),
community)

# Assemble SNMP Transport Data
Expand Down Expand Up @@ -124,7 +124,7 @@ def walk(self, oid, host, port, community):

# Assemble SNMP Auth Data
snmpAuthData = cmdgen.CommunityData(
'agent-{0}'.format(community),
'agent-{}'.format(community),
community)

# Assemble SNMP Transport Data
Expand Down
14 changes: 7 additions & 7 deletions src/collectors/snmpraw/snmpraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _precision(self, value):
def _skip(self, device, oid, reason=None):
self.skip_list.append((device, oid))
if reason is not None:
self.log.warn('Muted \'{0}\' on \'{1}\', because: {2}'.format(
self.log.warn('Muted \'{}\' on \'{}\', because: {}'.format(
oid, device, reason))

def _get_value_walk(self, device, oid, host, port, community):
Expand All @@ -108,14 +108,14 @@ def _get_value_walk(self, device, oid, host, port, community):
self._skip(device, oid, 'device down (#2)')
return

self.log.debug('Data received from WALK \'{0}\': [{1}]'.format(
self.log.debug('Data received from WALK \'{}\': [{}]'.format(
device, data))

if len(data) != 1:
self._skip(
device,
oid,
'unexpected response, data has {0} entries'.format(
'unexpected response, data has {} entries'.format(
len(data)))
return

Expand All @@ -130,7 +130,7 @@ def _get_value(self, device, oid, host, port, community):
self._skip(device, oid, 'device down (#1)')
return

self.log.debug('Data received from GET \'{0}\': [{1}]'.format(
self.log.debug('Data received from GET \'{}\': [{}]'.format(
device, data))

if len(data) == 0:
Expand Down Expand Up @@ -158,15 +158,15 @@ def collect_snmp(self, device, host, port, community):
Collect SNMP interface data from device
"""
self.log.debug(
'Collecting raw SNMP statistics from device \'{0}\''.format(device))
'Collecting raw SNMP statistics from device \'{}\''.format(device))

dev_config = self.config['devices'][device]
if 'oids' in dev_config:
for oid, metricName in dev_config['oids'].items():

if (device, oid) in self.skip_list:
self.log.debug(
'Skipping OID \'{0}\' ({1}) on device \'{2}\''.format(
'Skipping OID \'{}\' ({}) on device \'{}\''.format(
oid, metricName, device))
continue

Expand All @@ -176,7 +176,7 @@ def collect_snmp(self, device, host, port, community):
continue

self.log.debug(
'\'{0}\' ({1}) on device \'{2}\' - value=[{3}]'.format(
'\'{}\' ({}) on device \'{}\' - value=[{}]'.format(
oid, metricName, device, value))

path = '.'.join([self.config['path_prefix'], device,
Expand Down
24 changes: 12 additions & 12 deletions src/collectors/solr/solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,27 @@ def collect(self):
metrics = {}
for core in cores:
if core:
path = "{0}.".format(core)
path = "{}.".format(core)
else:
path = ""

ping_url = posixpath.normpath(
"/solr/{0}/admin/ping?wt=json".format(core))
"/solr/{}/admin/ping?wt=json".format(core))

if 'response' in self.config['stats']:
result = self._get(ping_url)
if not result:
continue

metrics.update({
"{0}response.QueryTime".format(path):
"{}response.QueryTime".format(path):
result["responseHeader"]["QTime"],
"{0}response.Status".format(path):
"{}response.Status".format(path):
result["responseHeader"]["status"],
})

stats_url = posixpath.normpath(
"/solr/{0}/admin/mbeans?stats=true&wt=json".format(core))
"/solr/{}/admin/mbeans?stats=true&wt=json".format(core))

result = self._get(stats_url)
if not result:
Expand All @@ -137,7 +137,7 @@ def collect(self):
core_searcher = stats["CORE"]["searcher"]["stats"]

metrics.update([
("{0}core.{1}".format(path, key),
("{}core.{}".format(path, key),
core_searcher[key])
for key in ("maxDoc", "numDocs", "warmupTime")
])
Expand All @@ -147,14 +147,14 @@ def collect(self):
update = stats["QUERYHANDLER"]["/update"]["stats"]

metrics.update([
("{0}queryhandler.standard.{1}".format(path, key),
("{}queryhandler.standard.{}".format(path, key),
standard[key])
for key in ("requests", "errors", "timeouts", "totalTime",
"avgTimePerRequest", "avgRequestsPerSecond")
])

metrics.update([
("{0}queryhandler.update.{1}".format(path, key),
("{}queryhandler.update.{}".format(path, key),
update[key])
for key in ("requests", "errors", "timeouts", "totalTime",
"avgTimePerRequest", "avgRequestsPerSecond")
Expand All @@ -166,7 +166,7 @@ def collect(self):
stats["UPDATEHANDLER"]["updateHandler"]["stats"]

metrics.update([
("{0}updatehandler.{1}".format(path, key),
("{}updatehandler.{}".format(path, key),
updatehandler[key])
for key in (
"commits", "autocommits", "optimizes",
Expand All @@ -178,7 +178,7 @@ def collect(self):
cache = stats["CACHE"]

metrics.update([
("{0}cache.{1}.{2}".format(path, cache_type, key),
("{}cache.{}.{}".format(path, cache_type, key),
self._try_convert(cache[cache_type]['stats'][key]))
for cache_type in (
'fieldValueCache', 'filterCache',
Expand All @@ -193,15 +193,15 @@ def collect(self):

if 'jvm' in self.config['stats']:
system_url = posixpath.normpath(
"/solr/{0}/admin/system?stats=true&wt=json".format(core))
"/solr/{}/admin/system?stats=true&wt=json".format(core))

result = self._get(system_url)
if not result:
continue

mem = result['jvm']['memory']
metrics.update([
('{0}jvm.mem.{1}'.format(path, key),
('{}jvm.mem.{}'.format(path, key),
self._try_convert(mem[key].split()[0]))
for key in ('free', 'total', 'max', 'used')
])
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/supervisord/supervisord.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def getAllProcessInfo(self):
server = None
protocol = self.config['xmlrpc_server_protocol']
path = self.config['xmlrpc_server_path']
uri = '{0}://{1}'.format(protocol, path)
uri = '{}://{}'.format(protocol, path)

self.log.debug(
'Attempting to connect to XML-RPC server "%s"', uri)
Expand Down

0 comments on commit 20c7903

Please sign in to comment.