Class DefaultMetricCollector

  • All Implemented Interfaces:
    MetricCollector

    public final class DefaultMetricCollector
    extends AbstractMetricCollector
    A MetricCollector that uses the Codahale Metrics library. The following system properies can be used to customize the behavior of the collector during runtime:
     - net.spy.metrics.reporter.type = console (console/jmx/csv/slf4j)
     - net.spy.metrics.reporter.interval = 30 (time interval to log)
     - net.spy.metrics.reporter.outdir = ~/mydir (output dir for csv reporter)
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.ConcurrentHashMap<java.lang.String,​com.codahale.metrics.Counter> counters
      Contains all registered Counters.
      static java.lang.String DEFAULT_REPORTER_INTERVAL
      Log every 30 seconds to the console by default.
      static java.lang.String DEFAULT_REPORTER_OUTDIR
      Define an empty directory for the CSV exporter by default.
      static java.lang.String DEFAULT_REPORTER_TYPE
      Use the "console" reporter by default.
      private java.util.concurrent.ConcurrentHashMap<java.lang.String,​com.codahale.metrics.Histogram> histograms
      Contains all registered Histograms.
      private java.util.concurrent.ConcurrentHashMap<java.lang.String,​com.codahale.metrics.Meter> meters
      Contains all registered Meters.
      private com.codahale.metrics.MetricRegistry registry
      Holds the registry where all metrics are stored.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCounter​(java.lang.String name)
      Add a Counter to the collector.
      void addHistogram​(java.lang.String name)
      Add a Histogram to the Collector.
      void addMeter​(java.lang.String name)
      Add a Meter to the Collector.
      void decrementCounter​(java.lang.String name, int amount)
      Decrement a Counter by the given amount.
      void incrementCounter​(java.lang.String name, int amount)
      Increment a Counter by the given amount.
      private void initReporter()
      Initialize the proper metrics Reporter.
      void markMeter​(java.lang.String name)
      Mark a checkpoint in the Meter.
      void removeCounter​(java.lang.String name)
      Remove a Counter from the collector.
      void removeHistogram​(java.lang.String name)
      Remove a Histogram from the Collector.
      void removeMeter​(java.lang.String name)
      Remove a Meter from the Collector.
      void updateHistogram​(java.lang.String name, int amount)
      Update the Histogram with the given amount.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_REPORTER_TYPE

        public static final java.lang.String DEFAULT_REPORTER_TYPE
        Use the "console" reporter by default.
        See Also:
        Constant Field Values
      • DEFAULT_REPORTER_INTERVAL

        public static final java.lang.String DEFAULT_REPORTER_INTERVAL
        Log every 30 seconds to the console by default.
        See Also:
        Constant Field Values
      • DEFAULT_REPORTER_OUTDIR

        public static final java.lang.String DEFAULT_REPORTER_OUTDIR
        Define an empty directory for the CSV exporter by default.
        See Also:
        Constant Field Values
      • registry

        private com.codahale.metrics.MetricRegistry registry
        Holds the registry where all metrics are stored.
      • counters

        private java.util.concurrent.ConcurrentHashMap<java.lang.String,​com.codahale.metrics.Counter> counters
        Contains all registered Counters.
      • meters

        private java.util.concurrent.ConcurrentHashMap<java.lang.String,​com.codahale.metrics.Meter> meters
        Contains all registered Meters.
      • histograms

        private java.util.concurrent.ConcurrentHashMap<java.lang.String,​com.codahale.metrics.Histogram> histograms
        Contains all registered Histograms.
    • Constructor Detail

      • DefaultMetricCollector

        public DefaultMetricCollector()
        Create a new DefaultMetricCollector. Note that when this constructor is called, the reporter is also automatically established.
    • Method Detail

      • initReporter

        private void initReporter()
        Initialize the proper metrics Reporter.
      • addCounter

        public void addCounter​(java.lang.String name)
        Description copied from interface: MetricCollector
        Add a Counter to the collector.
        Parameters:
        name - the name of the counter.
      • removeCounter

        public void removeCounter​(java.lang.String name)
        Description copied from interface: MetricCollector
        Remove a Counter from the collector.
        Parameters:
        name - the name of the counter.
      • incrementCounter

        public void incrementCounter​(java.lang.String name,
                                     int amount)
        Description copied from interface: MetricCollector
        Increment a Counter by the given amount.
        Parameters:
        name - the name of the counter.
        amount - the amount to increase.
      • decrementCounter

        public void decrementCounter​(java.lang.String name,
                                     int amount)
        Description copied from interface: MetricCollector
        Decrement a Counter by the given amount.
        Parameters:
        name - the name of the counter.
        amount - the amount to decrease.
      • addMeter

        public void addMeter​(java.lang.String name)
        Description copied from interface: MetricCollector
        Add a Meter to the Collector.
        Parameters:
        name - the name of the counter.
      • removeMeter

        public void removeMeter​(java.lang.String name)
        Description copied from interface: MetricCollector
        Remove a Meter from the Collector.
        Parameters:
        name - the name of the counter.
      • markMeter

        public void markMeter​(java.lang.String name)
        Description copied from interface: MetricCollector
        Mark a checkpoint in the Meter.
        Parameters:
        name - the name of the counter.
      • addHistogram

        public void addHistogram​(java.lang.String name)
        Description copied from interface: MetricCollector
        Add a Histogram to the Collector.
        Parameters:
        name - the name of the counter.
      • removeHistogram

        public void removeHistogram​(java.lang.String name)
        Description copied from interface: MetricCollector
        Remove a Histogram from the Collector.
        Parameters:
        name - the name of the counter.
      • updateHistogram

        public void updateHistogram​(java.lang.String name,
                                    int amount)
        Description copied from interface: MetricCollector
        Update the Histogram with the given amount.
        Parameters:
        name - the name of the counter.
        amount - the amount to update.