Skip to content

Commit

Permalink
Fixed issue librato#20 - Support multiple TypesDB
Browse files Browse the repository at this point in the history
  • Loading branch information
akerekes committed Dec 4, 2014
1 parent 98af2c4 commit 76c2212
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions lib/collectd-librato.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# NOTE: This version is grepped from the Makefile, so don't change the
# format of this line.
version = "0.0.10"
version = "0.0.11"

config = { 'api_path' : '/v1/metrics',
'api' : 'https://metrics-api.librato.com',
Expand Down Expand Up @@ -80,34 +80,35 @@ def sanitize_field(field):
def librato_parse_types_file(path):
global types

f = open(path, 'r')

for line in f:
fields = line.split()
if len(fields) < 2:
continue

type_name = fields[0]

if type_name[0] == '#':
continue

v = []
for ds in fields[1:]:
ds = ds.rstrip(',')
ds_fields = ds.split(':')

if len(ds_fields) != 4:
collectd.warning('%s: cannot parse data source ' \
'%s on type %s' %
(plugin_name, ds, type_name))
for p in path.split():
f = open(p, 'r')

for line in f:
fields = line.split()
if len(fields) < 2:
continue

v.append(ds_fields)

types[type_name] = v

f.close()

type_name = fields[0]

if type_name[0] == '#':
continue

v = []
for ds in fields[1:]:
ds = ds.rstrip(',')
ds_fields = ds.split(':')

if len(ds_fields) != 4:
collectd.warning('%s: cannot parse data source ' \
'%s on type %s' %
(plugin_name, ds, type_name))
continue

v.append(ds_fields)

types[type_name] = v

f.close()

def build_user_agent():
try:
Expand Down Expand Up @@ -142,7 +143,7 @@ def librato_config(c):
elif child.key == 'Api':
config['api'] = val
elif child.key == 'TypesDB':
config['types_db'] = val
config['types_db'] = " ".join(child.values)
elif child.key == 'MetricPrefix':
config['metric_prefix'] = val
elif child.key == 'MetricSeparator':
Expand Down

0 comments on commit 76c2212

Please sign in to comment.