Skip to content

Commit

Permalink
sanitize metric names before submitting them to ganglia. ganglia#36
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Hartshorne committed Apr 8, 2014
1 parent b9c9b7b commit 63be548
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ganglia-logtailer/src/ganglia-logtailer
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ def submit_stats( parser, missing_as_zero_state_file, missing_as_zero, metric_pr
logger.debug(e)
pass
for m in metrics:

m.sanitize_metric_name()
if ( metric_prefix != "" ):
m.name = metric_prefix + "_" + m.name

logger.debug( "Submitting gmetric: %s %s --name %s --value %s --type %s --units %s --tmax %s --dmax %s" %
(gmetric, gmetric_options, m.name, m.value, m.type, m.units, m.tmax, m.dmax) )
gmetric_call = [
Expand Down
4 changes: 4 additions & 0 deletions ganglia-logtailer/src/ganglia_logtailer_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python
"""class for ganglia metric objects to be passed around"""
import re

class GangliaMetricObject(object):
def __init__(self, name, value, units='', type='float', tmax=60, dmax=0):
Expand All @@ -22,6 +23,9 @@ def set_from_dict(self, hashed_object):
self.type = hashed_object["type"]
self.tmax = hashed_object["tmax"]
self.dmax = hashed_object["dmax"]
def sanitize_metric_name(self):
"""sanitize metric names by translating all non alphanumerics to underscore"""
self.name = re.sub("[^A-Za-z0-9._-]", "_", self.name)
def __eq__(self, other):
"""A ganglia metric object is equivalent if the name is the same."""
return self.name == other.name
Expand Down

0 comments on commit 63be548

Please sign in to comment.