Class AbstractMetricManager

  • Direct Known Subclasses:
    DoNothingMetricManager

    public abstract class AbstractMetricManager
    extends java.lang.Object
    • Field Detail

      • METRIC_CONFIG

        protected static final MetricConfig METRIC_CONFIG
      • nameToMetaInfo

        protected java.util.Map<java.lang.String,​MetricInfo.MetaInfo> nameToMetaInfo
        The map from metric name to metric metaInfo.
      • metrics

        protected java.util.Map<MetricInfo,​IMetric> metrics
        The map from metricInfo to metric.
    • Constructor Detail

      • AbstractMetricManager

        public AbstractMetricManager()
    • Method Detail

      • getOrCreateCounter

        public Counter getOrCreateCounter​(java.lang.String name,
                                          MetricLevel metricLevel,
                                          java.lang.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:
        java.lang.IllegalArgumentException - when there has different type metric with same name
      • createCounter

        protected abstract Counter createCounter​(MetricInfo metricInfo)
      • createAutoGauge

        public <T> AutoGauge createAutoGauge​(java.lang.String name,
                                             MetricLevel metricLevel,
                                             T obj,
                                             java.util.function.ToDoubleFunction<T> mapper,
                                             java.lang.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​(MetricInfo metricInfo,
                                                         T obj,
                                                         java.util.function.ToDoubleFunction<T> mapper)
        Create autoGauge according to metric framework.
        Parameters:
        metricInfo - the metricInfo of autoGauge
        obj - which will be monitored automatically
        mapper - use which to map the obj to a double value
      • getAutoGauge

        public AutoGauge getAutoGauge​(java.lang.String name,
                                      MetricLevel metricLevel,
                                      java.lang.String... tags)
        Get autoGauge.
        Parameters:
        name - the name of name
        metricLevel - the level of name
        Throws:
        java.lang.IllegalArgumentException - when there has different type metric with same name
      • getOrCreateGauge

        public Gauge getOrCreateGauge​(java.lang.String name,
                                      MetricLevel metricLevel,
                                      java.lang.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:
        java.lang.IllegalArgumentException - when there has different type metric with same name
      • createGauge

        protected abstract Gauge createGauge​(MetricInfo metricInfo)
        Create gauge according to metric framework.
        Parameters:
        metricInfo - the metricInfo of gauge
      • getOrCreateRate

        public Rate getOrCreateRate​(java.lang.String name,
                                    MetricLevel metricLevel,
                                    java.lang.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:
        java.lang.IllegalArgumentException - when there has different type metric with same name
      • createRate

        protected abstract Rate createRate​(MetricInfo metricInfo)
        Create rate according to metric framework.
        Parameters:
        metricInfo - the metricInfo of rate
      • getOrCreateHistogram

        public Histogram getOrCreateHistogram​(java.lang.String name,
                                              MetricLevel metricLevel,
                                              java.lang.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:
        java.lang.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​(java.lang.String name,
                                      MetricLevel metricLevel,
                                      java.lang.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:
        java.lang.IllegalArgumentException - when there has different type metric with same name
      • createTimer

        protected abstract Timer createTimer​(MetricInfo metricInfo)
        Create timer according to metric framework.
        Parameters:
        metricInfo - the metricInfo of metric
      • count

        public Counter count​(long delta,
                             java.lang.String name,
                             MetricLevel metricLevel,
                             java.lang.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,
                           java.lang.String name,
                           MetricLevel metricLevel,
                           java.lang.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,
                         java.lang.String name,
                         MetricLevel metricLevel,
                         java.lang.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,
                                   java.lang.String name,
                                   MetricLevel metricLevel,
                                   java.lang.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,
                           java.util.concurrent.TimeUnit timeUnit,
                           java.lang.String name,
                           MetricLevel metricLevel,
                           java.lang.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 java.util.List<org.apache.iotdb.tsfile.utils.Pair<java.lang.String,​java.lang.String[]>> getAllMetricKeys()
        Get all metric keys.
        Returns:
        [[name, [tags...]], ..., [name, [tags...]]]
      • getAllMetrics

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

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

        public void remove​(MetricType type,
                           java.lang.String name,
                           java.lang.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:
        java.lang.IllegalArgumentException - when there has different type metric with same name
      • isEnableMetricInGivenLevel

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

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

        protected abstract boolean stopFramework()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object