Class AbstractMetricManager

    • Constructor Detail

      • AbstractMetricManager

        protected AbstractMetricManager()
    • Method Detail

      • getOrCreateCounter

        public Counter getOrCreateCounter​(String name,
                                          MetricLevel metricLevel,
                                          String... tags)
        Get counter. return if exists, create if not.
        Parameters:
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
        Throws:
        IllegalArgumentException - when there has different type metric with same name
      • createCounter

        protected abstract Counter createCounter()
      • createAutoGauge

        public <T> AutoGauge createAutoGauge​(String name,
                                             MetricLevel metricLevel,
                                             T obj,
                                             ToDoubleFunction<T> mapper,
                                             String... tags)
        Create autoGauge

        AutoGauge keep a weak reference of the obj, so it will not prevent gc of the obj. Notice: if you call this gauge's value() when the obj has already been cleared by gc, then you will get 0L.

        Parameters:
        name - the name of name
        metricLevel - the level of name
        obj - which will be monitored automatically
        mapper - use which to map the obj to a double value
      • createAutoGauge

        protected abstract <T> AutoGauge createAutoGauge​(T obj,
                                                         ToDoubleFunction<T> mapper)
        Create autoGauge according to metric framework.
        Parameters:
        obj - which will be monitored automatically
        mapper - use which to map the obj to a double value
      • getOrCreateGauge

        public Gauge getOrCreateGauge​(String name,
                                      MetricLevel metricLevel,
                                      String... tags)
        Get counter. return if exists, create if not.
        Parameters:
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
        Throws:
        IllegalArgumentException - when there has different type metric with same name
      • createGauge

        protected abstract Gauge createGauge()
        Create gauge according to metric framework.
      • getOrCreateRate

        public Rate getOrCreateRate​(String name,
                                    MetricLevel metricLevel,
                                    String... tags)
        Get rate. return if exists, create if not.
        Parameters:
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
        Throws:
        IllegalArgumentException - when there has different type metric with same name
      • createRate

        protected abstract Rate createRate()
        Create rate according to metric framework.
      • getOrCreateHistogram

        public Histogram getOrCreateHistogram​(String name,
                                              MetricLevel metricLevel,
                                              String... tags)
        Get histogram. return if exists, create if not.
        Parameters:
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
        Throws:
        IllegalArgumentException - when there has different type metric with same name
      • createHistogram

        protected abstract Histogram createHistogram​(MetricInfo metricInfo)
        Create histogram according to metric framework.
        Parameters:
        metricInfo - the metricInfo of metric
      • getOrCreateTimer

        public Timer getOrCreateTimer​(String name,
                                      MetricLevel metricLevel,
                                      String... tags)
        Get timer. return if exists, create if not.
        Parameters:
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
        Throws:
        IllegalArgumentException - when there has different type metric with same name
      • createTimer

        protected abstract Timer createTimer()
        Create timer according to metric framework.
      • count

        public Counter count​(long delta,
                             String name,
                             MetricLevel metricLevel,
                             String... tags)
        Update counter. if exists, then update counter by delta. if not, then create and update.
        Parameters:
        delta - the value to update
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
      • gauge

        public Gauge gauge​(long value,
                           String name,
                           MetricLevel metricLevel,
                           String... tags)
        Set value of gauge. if exists, then set gauge by value. if not, then create and set.
        Parameters:
        value - the value of gauge
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
      • rate

        public Rate rate​(long value,
                         String name,
                         MetricLevel metricLevel,
                         String... tags)
        Mark rate. if exists, then mark rate by value. if not, then create and mark.
        Parameters:
        value - the value to mark
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
      • histogram

        public Histogram histogram​(long value,
                                   String name,
                                   MetricLevel metricLevel,
                                   String... tags)
        Update histogram. if exists, then update histogram by value. if not, then create and update
        Parameters:
        value - the value to update
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
      • timer

        public Timer timer​(long delta,
                           TimeUnit timeUnit,
                           String name,
                           MetricLevel metricLevel,
                           String... tags)
        Update timer. if exists, then update timer by delta and timeUnit. if not, then create and update
        Parameters:
        delta - the value to update
        timeUnit - the unit of delta
        name - the name of name
        metricLevel - the level of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
      • getAllMetricKeys

        public List<Pair<String,​String[]>> getAllMetricKeys()
        Get all metric keys.
        Returns:
        [[name, [tags...]], ..., [name, [tags...]]]
      • getAllMetrics

        public Map<MetricInfo,​IMetric> getAllMetrics()
        Get all metrics.
        Returns:
        [name, [tags...]] -> metric
      • getMetricsByType

        public Map<MetricInfo,​IMetric> getMetricsByType​(MetricType metricType)
        Get metrics by type.
        Returns:
        [name, [tags...]] -> metric
      • remove

        public void remove​(MetricType type,
                           String name,
                           String... tags)
        remove name.
        Parameters:
        type - the type of name
        name - the name of name
        tags - string pairs, like sg="ln" will be "sg", "ln"
        Throws:
        IllegalArgumentException - when there has different type metric with same name
      • isEnableMetricInGivenLevel

        public boolean isEnableMetricInGivenLevel​(MetricLevel metricLevel)
        Is metric service enabled in specific level.
      • setBindJmxReporter

        public void setBindJmxReporter​(JmxReporter reporter)
      • stop

        protected boolean stop()
        Stop and clear metric manager.
      • stopFramework

        protected abstract boolean stopFramework()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object