Skip to content

Commit

Permalink
Rewrite dict creation with dict literals
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 15, 2018
1 parent bc75167 commit 4dd0b10
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/collectors/cpu/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ def cpu_delta_time(interval):
# Close File
file.close()

metrics = {}
metrics['cpu_count'] = ncpus
metrics = {'cpu_count': ncpus}

for cpu in results.keys():
stats = results[cpu]
Expand Down
3 changes: 1 addition & 2 deletions src/collectors/memcached_slab/memcached_slab.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def parse_slab_stats(slab_stats):
'total_malloced': 1048512,
}
"""
stats_dict = {}
stats_dict['slabs'] = defaultdict(lambda: {})
stats_dict = {'slabs': defaultdict(lambda: {})}

for line in slab_stats.splitlines():
if line == 'END':
Expand Down
3 changes: 1 addition & 2 deletions src/collectors/mysqlstat/mysql55.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ def collect(self):
if not matches:
continue

params = {}
params = {'host': matches.group(3)}

params['host'] = matches.group(3)
try:
params['port'] = int(matches.group(4))
except ValueError:
Expand Down
3 changes: 1 addition & 2 deletions src/collectors/mysqlstat/mysqlstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,8 @@ def collect(self):
host)
continue

params = {}
params = {'host': matches.group(3)}

params['host'] = matches.group(3)
try:
params['port'] = int(matches.group(4))
except ValueError:
Expand Down
3 changes: 1 addition & 2 deletions src/collectors/ntp/ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def get_default_config(self):
def get_ntpdate_stats(self):
output = self.run_command(['-q', self.config['ntp_pool']])

data = {}
data['server.count'] = {'val': 0, 'precision': 0}
data = {'server.count': {'val': 0, 'precision': 0}}

for line in output[0].splitlines():
# Only care about best choice not all servers
Expand Down
3 changes: 1 addition & 2 deletions src/collectors/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def collect(self):
self.log.error('Unable to import either pyutmp or python-utmp')
return False

metrics = {}
metrics['total'] = 0
metrics = {'total': 0}

if UtmpFile:
for utmp in UtmpFile(path=self.config['utmp']):
Expand Down
23 changes: 9 additions & 14 deletions src/diamond/handler/tsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def __init__(self, config=None):
self.tags.append([key, value])

# headers
self.httpheader = {}
self.httpheader["Content-Type"] = "application/json"
self.httpheader = {"Content-Type": "application/json"}
# Authorization
if self.user != "":
self.httpheader["Authorization"] = "Basic " +\
Expand Down Expand Up @@ -191,10 +190,8 @@ def process(self, metric):
"""
Process a metric by sending it to TSDB
"""
entry = {}
entry['timestamp'] = metric.timestamp
entry['value'] = metric.value
entry["tags"] = {}
entry = {'timestamp': metric.timestamp, 'value': metric.value,
"tags": {}}
entry["tags"]["hostname"] = metric.host

if self.cleanMetrics:
Expand Down Expand Up @@ -362,14 +359,12 @@ def processMattermostMetric(self):
self.path = self.path.replace("."+team+".", ".")
self.path = self.path.replace("."+channel+".", ".")

handlers = {}
handlers['cpu'] = processCpuMetric
handlers['haproxy'] = processHaProxyMetric
handlers['mattermost'] = processMattermostMetric
handlers['diskspace'] = processDiskspaceMetric
handlers['iostat'] = processDiskusageMetric
handlers['network'] = processNetworkMetric
handlers['default'] = processDefaultMetric
handlers = {'cpu': processCpuMetric, 'haproxy': processHaProxyMetric,
'mattermost': processMattermostMetric,
'diskspace': processDiskspaceMetric,
'iostat': processDiskusageMetric,
'network': processNetworkMetric,
'default': processDefaultMetric}

def __init__(self, delegate, logger):
self.path = delegate.path
Expand Down

0 comments on commit 4dd0b10

Please sign in to comment.