Class MetricsManager

  • All Implemented Interfaces:
    MetricsService

    public class MetricsManager
    extends java.lang.Object
    implements MetricsService
    This class holds the Metrics registry for ONOS. All metrics (Counter, Histogram, Timer, Meter, Gauge) use a hierarchical string-based naming scheme: COMPONENT.FEATURE.NAME. Example: "Topology.Counters.TopologyUpdates". The COMPONENT and FEATURE names have to be registered in advance before a metric can be created. Example:
       
         private final MetricsManager.MetricsComponent COMPONENT =
             MetricsManager.registerComponent("Topology");
         private final MetricsManager.MetricsFeature FEATURE =
             COMPONENT.registerFeature("Counters");
         private final Counter counterTopologyUpdates =
             MetricsManager.createCounter(COMPONENT, FEATURE, "TopologyUpdates");
       
     
    Gauges are slightly different because they are not created directly in this class, but are allocated by the caller and passed in for registration:
       
         private final Gauge<Long> gauge =
             new Gauge&lt;Long&gt() {
                 @Override
                 public Long getValue() {
                     return gaugeValue;
                 }
             };
         MetricsManager.registerMetric(COMPONENT, FEATURE, GAUGE_NAME, gauge);
       
     
    • Constructor Summary

      Constructors 
      Constructor Description
      MetricsManager()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void clear()
      Clears the internal state.
      com.codahale.metrics.Counter createCounter​(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
      Creates a Counter metric.
      com.codahale.metrics.Histogram createHistogram​(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
      Creates a Histogram metric.
      com.codahale.metrics.Meter createMeter​(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
      Creates a Meter metric.
      com.codahale.metrics.Timer createTimer​(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
      Creates a Timer metric.
      java.util.Map<java.lang.String,​com.codahale.metrics.Counter> getCounters​(com.codahale.metrics.MetricFilter filter)
      Fetches the existing Counters.
      java.util.Map<java.lang.String,​com.codahale.metrics.Gauge> getGauges​(com.codahale.metrics.MetricFilter filter)
      Fetches the existing Gauges.
      java.util.Map<java.lang.String,​com.codahale.metrics.Histogram> getHistograms​(com.codahale.metrics.MetricFilter filter)
      Fetches the existing Histograms.
      java.util.Map<java.lang.String,​com.codahale.metrics.Meter> getMeters​(com.codahale.metrics.MetricFilter filter)
      Fetches the existing Meters.
      com.codahale.metrics.MetricRegistry getMetricRegistry()
      Fetches existing metric registry.
      java.util.Map<java.lang.String,​com.codahale.metrics.Metric> getMetrics()
      Fetches the existing Meters.
      java.util.Map<java.lang.String,​com.codahale.metrics.Timer> getTimers​(com.codahale.metrics.MetricFilter filter)
      Fetches the existing Timers.
      void notifyReporters()
      Notifies the changes on metric registry to all registered reporters.
      MetricsComponent registerComponent​(java.lang.String name)
      Registers a component.
      <T extends com.codahale.metrics.Metric>
      T
      registerMetric​(MetricsComponent component, MetricsFeature feature, java.lang.String metricName, T metric)
      Registers an already created Metric.
      void registerReporter​(MetricsReporter reporter)
      Registers a reporter to receive any changes on metric registry.
      void removeMatching​(com.codahale.metrics.MetricFilter filter)
      Removes all Metrics that match a given filter.
      boolean removeMetric​(MetricsComponent component, MetricsFeature feature, java.lang.String metricName)
      Removes the metric with the given name.
      void unregisterReporter​(MetricsReporter reporter)
      Unregisters the given metric reporter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MetricsManager

        public MetricsManager()
    • Method Detail

      • clear

        protected void clear()
        Clears the internal state.
      • registerComponent

        public MetricsComponent registerComponent​(java.lang.String name)
        Registers a component.
        Specified by:
        registerComponent in interface MetricsService
        Parameters:
        name - name of the Component to register
        Returns:
        MetricsComponent object that can be used to create Metrics.
      • getMetricRegistry

        public com.codahale.metrics.MetricRegistry getMetricRegistry()
        Fetches existing metric registry.
        Specified by:
        getMetricRegistry in interface MetricsService
        Returns:
        metric registry
      • createCounter

        public com.codahale.metrics.Counter createCounter​(MetricsComponent component,
                                                          MetricsFeature feature,
                                                          java.lang.String metricName)
        Creates a Counter metric.
        Specified by:
        createCounter in interface MetricsService
        Parameters:
        component - component the Counter is defined in
        feature - feature the Counter is defined in
        metricName - local name of the metric
        Returns:
        the created Counter Meteric
      • createHistogram

        public com.codahale.metrics.Histogram createHistogram​(MetricsComponent component,
                                                              MetricsFeature feature,
                                                              java.lang.String metricName)
        Creates a Histogram metric.
        Specified by:
        createHistogram in interface MetricsService
        Parameters:
        component - component the Histogram is defined in
        feature - feature the Histogram is defined in
        metricName - local name of the metric
        Returns:
        the created Histogram Metric
      • createTimer

        public com.codahale.metrics.Timer createTimer​(MetricsComponent component,
                                                      MetricsFeature feature,
                                                      java.lang.String metricName)
        Creates a Timer metric.
        Specified by:
        createTimer in interface MetricsService
        Parameters:
        component - component the Timer is defined in
        feature - feature the Timer is defined in
        metricName - local name of the metric
        Returns:
        the created Timer Metric
      • createMeter

        public com.codahale.metrics.Meter createMeter​(MetricsComponent component,
                                                      MetricsFeature feature,
                                                      java.lang.String metricName)
        Creates a Meter metric.
        Specified by:
        createMeter in interface MetricsService
        Parameters:
        component - component the Meter is defined in
        feature - feature the Meter is defined in
        metricName - local name of the metric
        Returns:
        the created Meter Metric
      • registerMetric

        public <T extends com.codahale.metrics.Metric> T registerMetric​(MetricsComponent component,
                                                                        MetricsFeature feature,
                                                                        java.lang.String metricName,
                                                                        T metric)
        Registers an already created Metric. This is used for situation where a caller needs to allocate its own Metric, but still register it with the system.
        Specified by:
        registerMetric in interface MetricsService
        Type Parameters:
        T - Metric type
        Parameters:
        component - component the Metric is defined in
        feature - feature the Metric is defined in
        metricName - local name of the metric
        metric - Metric to register
        Returns:
        the registered Metric
      • registerReporter

        public void registerReporter​(MetricsReporter reporter)
        Registers a reporter to receive any changes on metric registry.
        Specified by:
        registerReporter in interface MetricsService
        Parameters:
        reporter - metric reporter
      • notifyReporters

        public void notifyReporters()
        Notifies the changes on metric registry to all registered reporters.
        Specified by:
        notifyReporters in interface MetricsService
      • removeMetric

        public boolean removeMetric​(MetricsComponent component,
                                    MetricsFeature feature,
                                    java.lang.String metricName)
        Removes the metric with the given name.
        Specified by:
        removeMetric in interface MetricsService
        Parameters:
        component - component the Metric is defined in
        feature - feature the Metric is defined in
        metricName - local name of the metric
        Returns:
        true if the metric existed and was removed, otherwise false
      • getTimers

        public java.util.Map<java.lang.String,​com.codahale.metrics.Timer> getTimers​(com.codahale.metrics.MetricFilter filter)
        Fetches the existing Timers.
        Specified by:
        getTimers in interface MetricsService
        Parameters:
        filter - filter to use to select Timers
        Returns:
        a map of the Timers that match the filter, with the key as the name String to the Timer.
      • getGauges

        public java.util.Map<java.lang.String,​com.codahale.metrics.Gauge> getGauges​(com.codahale.metrics.MetricFilter filter)
        Fetches the existing Gauges.
        Specified by:
        getGauges in interface MetricsService
        Parameters:
        filter - filter to use to select Gauges
        Returns:
        a map of the Gauges that match the filter, with the key as the name String to the Gauge.
      • getCounters

        public java.util.Map<java.lang.String,​com.codahale.metrics.Counter> getCounters​(com.codahale.metrics.MetricFilter filter)
        Fetches the existing Counters.
        Specified by:
        getCounters in interface MetricsService
        Parameters:
        filter - filter to use to select Counters
        Returns:
        a map of the Counters that match the filter, with the key as the name String to the Counter.
      • getMeters

        public java.util.Map<java.lang.String,​com.codahale.metrics.Meter> getMeters​(com.codahale.metrics.MetricFilter filter)
        Fetches the existing Meters.
        Specified by:
        getMeters in interface MetricsService
        Parameters:
        filter - filter to use to select Meters
        Returns:
        a map of the Meters that match the filter, with the key as the name String to the Meter.
      • getHistograms

        public java.util.Map<java.lang.String,​com.codahale.metrics.Histogram> getHistograms​(com.codahale.metrics.MetricFilter filter)
        Fetches the existing Histograms.
        Specified by:
        getHistograms in interface MetricsService
        Parameters:
        filter - filter to use to select Histograms
        Returns:
        a map of the Histograms that match the filter, with the key as the name String to the Histogram.
      • removeMatching

        public void removeMatching​(com.codahale.metrics.MetricFilter filter)
        Removes all Metrics that match a given filter.
        Specified by:
        removeMatching in interface MetricsService
        Parameters:
        filter - filter to use to select the Metrics to remove.
      • getMetrics

        public java.util.Map<java.lang.String,​com.codahale.metrics.Metric> getMetrics()
        Fetches the existing Meters.
        Specified by:
        getMetrics in interface MetricsService
        Returns:
        a map of all metrics with the key as the name String to the Meter.