Class MetricMangler


  • public class MetricMangler
    extends Object
    Handles updating the metric and source names by extracting components from the metric name. There are several options considered:
    • source name:
      • extracted from one or more components of the metric name (where each component is separated by a '.')
      • allow characters to be optionally replaced in the components extracted as source name with '.'
    • metric name:
      • remove components (in addition to the source name) (this allows things like 'hosts.sjc1234.cpu.loadavg.1m' to get changed to cpu.loadavg.1m after extracting sjc1234)
    This code was originally mostly contained in GraphiteFormatter class and moved into a single re-usable class.
    Author:
    Mike McLaughlin (mike@wavefront.com)
    • Constructor Detail

      • MetricMangler

        public MetricMangler​(@Nullable
                             String sourceFields,
                             @Nullable
                             String delimiters,
                             @Nullable
                             String removeFields)
        Constructor.
        Parameters:
        sourceFields - comma separated field index(es) (1-based) where the source name will be extracted
        delimiters - characters to be interpreted as dots
        removeFields - comma separated field index(es) (1-based) of fields to remove from the metric name
        Throws:
        IllegalArgumentException - when one of the field index is <= 0
    • Method Detail

      • extractComponents

        public MetricMangler.MetricComponents extractComponents​(String metric)
        Extracts the source from the metric name and returns the new metric name and the source name.
        Parameters:
        metric - the metric name
        Returns:
        the updated metric name and the extracted source
        Throws:
        IllegalArgumentException - when the number of segments (split on '.') is less than the maximum source component index