@@ -223,6 +223,7 @@ def flush(self, timestamp, interval):
223223
224224DEFAULT_HISTOGRAM_AGGREGATES = ['max' , 'median' , 'avg' , 'count' ]
225225DEFAULT_HISTOGRAM_PERCENTILES = [0.95 ]
226+ DEFAULT_HISTOGRAM_NAME_FORMAT = '%s.%spercentile'
226227
227228class Histogram (Metric ):
228229 """ A metric to track the distribution of a set of values. """
@@ -238,6 +239,9 @@ def __init__(self, formatter, name, tags, hostname, device_name, extra_config=No
238239 self .percentiles = extra_config ['percentiles' ] if \
239240 extra_config is not None and extra_config .get ('percentiles' ) is not None \
240241 else DEFAULT_HISTOGRAM_PERCENTILES
242+ self .name_format = extra_config ['name_format' ] if \
243+ extra_config is not None and extra_config .get ('name_format' ) is not None \
244+ else DEFAULT_HISTOGRAM_NAME_FORMAT
241245 self .tags = tags
242246 self .hostname = hostname
243247 self .device_name = device_name
@@ -287,7 +291,11 @@ def flush(self, ts, interval):
287291
288292 for p in self .percentiles :
289293 val = self .samples [int (round (p * length - 1 ))]
290- name = '%s.%spercentile' % (self .name , int (p * 100 ))
294+ try :
295+ name = self .name_format % (self .name , int (p * 100 ))
296+ except TypeError :
297+ log .warn ("Invalid histogram name format %s, defaulting to '%s'" % (self .name_format , DEFAULT_HISTOGRAM_NAME_FORMAT ))
298+ name = DEFAULT_HISTOGRAM_NAME_FORMAT % (self .name , int (p * 100 ))
291299 metrics .append (self .formatter (
292300 hostname = self .hostname ,
293301 tags = self .tags ,
@@ -401,6 +409,7 @@ class Aggregator(object):
401409 def __init__ (self , hostname , interval = 1.0 , expiry_seconds = 300 ,
402410 formatter = None , recent_point_threshold = None ,
403411 histogram_aggregates = None , histogram_percentiles = None ,
412+ histogram_name_format = None ,
404413 utf8_decoding = False ):
405414 self .events = []
406415 self .service_checks = []
@@ -421,7 +430,8 @@ def __init__(self, hostname, interval=1.0, expiry_seconds=300,
421430 self .metric_config = {
422431 Histogram : {
423432 'aggregates' : histogram_aggregates ,
424- 'percentiles' : histogram_percentiles
433+ 'percentiles' : histogram_percentiles ,
434+ 'name_format' : histogram_name_format
425435 }
426436 }
427437
@@ -723,6 +733,7 @@ class MetricsBucketAggregator(Aggregator):
723733 def __init__ (self , hostname , interval = 1.0 , expiry_seconds = 300 ,
724734 formatter = None , recent_point_threshold = None ,
725735 histogram_aggregates = None , histogram_percentiles = None ,
736+ histogram_name_format = None ,
726737 utf8_decoding = False ):
727738 super (MetricsBucketAggregator , self ).__init__ (
728739 hostname ,
@@ -732,6 +743,7 @@ def __init__(self, hostname, interval=1.0, expiry_seconds=300,
732743 recent_point_threshold ,
733744 histogram_aggregates ,
734745 histogram_percentiles ,
746+ histogram_name_format ,
735747 utf8_decoding
736748 )
737749 self .metric_by_bucket = {}
@@ -863,6 +875,7 @@ class MetricsAggregator(Aggregator):
863875 def __init__ (self , hostname , interval = 1.0 , expiry_seconds = 300 ,
864876 formatter = None , recent_point_threshold = None ,
865877 histogram_aggregates = None , histogram_percentiles = None ,
878+ histogram_name_format = None ,
866879 utf8_decoding = False ):
867880 super (MetricsAggregator , self ).__init__ (
868881 hostname ,
@@ -872,6 +885,7 @@ def __init__(self, hostname, interval=1.0, expiry_seconds=300,
872885 recent_point_threshold ,
873886 histogram_aggregates ,
874887 histogram_percentiles ,
888+ histogram_name_format ,
875889 utf8_decoding
876890 )
877891 self .metrics = {}
0 commit comments