Package org.apache.iotdb.metrics
Class AbstractMetricManager
- java.lang.Object
-
- org.apache.iotdb.metrics.AbstractMetricManager
-
- Direct Known Subclasses:
DoNothingMetricManager
public abstract class AbstractMetricManager extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected JmxReporterbindJmxReporterThe bind IoTDBJmxReporterprotected static MetricConfigMETRIC_CONFIGprotected Map<MetricInfo,IMetric>metricsThe map from metricInfo to metric.protected Map<String,MetricInfo.MetaInfo>nameToMetaInfoThe map from metric name to metric metaInfo.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMetricManager()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Countercount(long delta, String name, MetricLevel metricLevel, String... tags)Update counter.<T> AutoGaugecreateAutoGauge(String name, MetricLevel metricLevel, T obj, ToDoubleFunction<T> mapper, String... tags)Create autoGaugeprotected abstract <T> AutoGaugecreateAutoGauge(T obj, ToDoubleFunction<T> mapper)Create autoGauge according to metric framework.protected abstract CountercreateCounter()protected abstract GaugecreateGauge()Create gauge according to metric framework.protected abstract HistogramcreateHistogram(MetricInfo metricInfo)Create histogram according to metric framework.protected abstract RatecreateRate()Create rate according to metric framework.protected abstract TimercreateTimer()Create timer according to metric framework.booleanequals(Object o)Gaugegauge(long value, String name, MetricLevel metricLevel, String... tags)Set value of gauge.List<Pair<String,String[]>>getAllMetricKeys()Get all metric keys.Map<MetricInfo,IMetric>getAllMetrics()Get all metrics.AutoGaugegetAutoGauge(String name, MetricLevel metricLevel, String... tags)Get autoGauge.Map<MetricInfo,IMetric>getMetricsByType(MetricType metricType)Get metrics by type.CountergetOrCreateCounter(String name, MetricLevel metricLevel, String... tags)Get counter.GaugegetOrCreateGauge(String name, MetricLevel metricLevel, String... tags)Get counter.HistogramgetOrCreateHistogram(String name, MetricLevel metricLevel, String... tags)Get histogram.RategetOrCreateRate(String name, MetricLevel metricLevel, String... tags)Get rate.TimergetOrCreateTimer(String name, MetricLevel metricLevel, String... tags)Get timer.inthashCode()Histogramhistogram(long value, String name, MetricLevel metricLevel, String... tags)Update histogram.booleanisEnableMetricInGivenLevel(MetricLevel metricLevel)Is metric service enabled in specific level.Raterate(long value, String name, MetricLevel metricLevel, String... tags)Mark rate.voidremove(MetricType type, String name, String... tags)remove name.protected abstract voidremoveMetric(MetricType type, MetricInfo metricInfo)voidsetBindJmxReporter(JmxReporter reporter)protected booleanstop()Stop and clear metric manager.protected abstract booleanstopFramework()Timertimer(long delta, TimeUnit timeUnit, String name, MetricLevel metricLevel, String... tags)Update timer.
-
-
-
Field Detail
-
METRIC_CONFIG
protected static final MetricConfig METRIC_CONFIG
-
nameToMetaInfo
protected Map<String,MetricInfo.MetaInfo> nameToMetaInfo
The map from metric name to metric metaInfo.
-
metrics
protected Map<MetricInfo,IMetric> metrics
The map from metricInfo to metric.
-
bindJmxReporter
protected JmxReporter bindJmxReporter
The bind IoTDBJmxReporter
-
-
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 namemetricLevel- the level of nametags- 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 autoGaugeAutoGauge 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 namemetricLevel- the level of nameobj- which will be monitored automaticallymapper- 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 automaticallymapper- use which to map the obj to a double value
-
getAutoGauge
public AutoGauge getAutoGauge(String name, MetricLevel metricLevel, String... tags)
Get autoGauge.- Parameters:
name- the name of namemetricLevel- the level of name- Throws:
IllegalArgumentException- when there has different type metric with same name
-
getOrCreateGauge
public Gauge getOrCreateGauge(String name, MetricLevel metricLevel, String... tags)
Get counter. return if exists, create if not.- Parameters:
name- the name of namemetricLevel- the level of nametags- 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 namemetricLevel- the level of nametags- 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 namemetricLevel- the level of nametags- 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 namemetricLevel- the level of nametags- 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 updatename- the name of namemetricLevel- the level of nametags- 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 gaugename- the name of namemetricLevel- the level of nametags- 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 markname- the name of namemetricLevel- the level of nametags- 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 updatename- the name of namemetricLevel- the level of nametags- 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 updatetimeUnit- the unit of deltaname- the name of namemetricLevel- the level of nametags- 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 namename- the name of nametags- string pairs, like sg="ln" will be "sg", "ln"- Throws:
IllegalArgumentException- when there has different type metric with same name
-
removeMetric
protected abstract void removeMetric(MetricType type, MetricInfo metricInfo)
-
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()
-
-