Metric Module
-
In this project, we provide interface and two implementations
- metrics-interface
- dropwizard metric
- micrometer metric
-
In each implementation, you can use many types of reporter to report the details of metric
- Jmx Reporter
- Prometheus Reporter
- IoTDB Reporter
- The acquisition system consists of following four parts.
- Metrics:Provide tools for collecting metric in different scenarios, including Counter, Gauge, Meter, Histogram, Timer, each with tags.
- MetricManager
- Provide functions such as creating, finding, updating, and deleting metrics.
- Provide the ability to introduce default metrics(Known Metric).
- Provide its own start and stop methods.
- CompositeReporter
- Provide management of reporter, including starting and stopping reporter.
- Push the collector's data to other systems, such as Prometheus, JMX, etc.
- Provide its own start and stop methods.
- MetricService
- Provide the start and stop method of metric module.
- Provide the ability to hot load some properties.
- Provide the access of metricManager and the control of reporters.
- The structure of acquisition system
We implemented the monitoring framework using Dropwizard and Micrometer respectively, and tested the results as follows:
- Processor:Inter(R) Core(TM) i7-1065G7 CPU
- RAM: 32G
- We use a single thread to create counter and run the test cases separately in two frameworks of Micrometer and Dropwizard. The test metrics as follows:
- memory : Memory usage in MB.
- create : The time required to create, in ms.
- searchInorder : The time required for the sequential query, in ms.
- searchDisorder : The time required for random queries in ms.
- metric : test metric
- name : The name of the test metric, unify to one length.
- tag : The tag of the test metric, unify to one length.
- metricNumberTotal:The number of metrics tested.
- tagSingleNumber:Number of tags of the test metric.
- tagTotalNumber:The number of tag pools, the default is 1000, all
- tags are taken out of the tag pool.
- searchNumber:The number of queries, the default is 1000000.
- loop:The number of query loops, the default is 10.
- firstly, you need to set up some system property, for example:
System.setProperty("line.separator", "\n");
System.setProperty("IOTDB_CONF", "metrics/dropwizard-metrics/src/test/resources");
- Then, you can modify
iotdb-metric.yml
as you like, some details:
properties | meaning | example |
---|---|---|
enableMetric | whether enable the module | true |
metricReporterList | the list of reporter | JMX, PROMETHEUS |
predefinedMetrics | predefined set of metrics | JMX, LOGBACK |
metricLevel | the init level of metrics | ALL, NORMAL, IMPORTANT, CORE |
monitorType | The type of monitor manager | DROPWIZARD, MICROMETER |
pushPeriodInSecond | the period time of push(used for prometheus, unit: s) | 5 |
- After all above, you can use it in the following way
- use
startService
method to load manager and reporters. - use
MetricService.getMetricManager()
to get metric manager. - use the method in metric manager, method details in
metrics/interface/src/main/java/org/apache/iotdb/metrics/MetricManager
- use
- example code
public class PrometheusRunTest {
static MetricConfig metricConfig = MetricConfigDescriptor.getInstance().getMetricConfig();
static MetricService metricService = new DoNothingMetricService();
static MetricManager metricManager;
public static void main(String[] args) throws InterruptedException {
metricConfig.setMonitorType(MonitorType.dropwizard);
metricConfig.setPredefinedMetrics(new ArrayList<>());
metricService.startService();
metricManager = metricService.getMetricManager();
Counter counter = metricManager.getOrCreateCounter("counter", MetricLevel.IMPORTANT);
while (true) {
counter.inc();
TimeUnit.SECONDS.sleep(1);
}
}
}
- Now, MetricsService is registered as IService in server module, you can simple set properties:
enableMetric: true
to get a instance of MetricsService. - In server module you can easily use these metric by
MetricsService.getInstance().getMetricManager()
, for example:
MetricsService.getInstance()
.count(1, "operation_count", MetricLevel.IMPORTANT, "name", operation.getName());
- implement your MetricService
- You need to implement
collectFileSystemInfo
to collect file system info as you like. - You need to implement
reloadProperties
to support hot load.
- You need to implement
- implement your MetricManager
- The name of MetricManager should start with
monitorType
, MetricService will init manager according to the prefix of class name. - You need to create
src/main/resources/META-INF/services/org.apache.iotdb.metrics.MetricManager
,and record your MetricManager class name in this file, such asorg.apache.iotdb.metrics.dropwizard.DropwizardMetricManager
- The name of MetricManager should start with
- implement your reporter
- You need to implement jmx reporter and prometheus reporter, notice that your jmx bean name should be unified as
org.apache.iotdb.metrics
- The name of your reporter should also start with
monitorType
- You need to create
src/main/resources/META-INF/services/org.apache.iotdb.metrics.Reporter
,and record your MetricManager class name in this file, such asorg.apache.iotdb.metrics.dropwizard.reporter.DropwizardPrometheusReporter
- You need to implement jmx reporter and prometheus reporter, notice that your jmx bean name should be unified as
- implement your specific metric
- They are counter, gauge, histogram, histogramSnapshot, rate and timer.
- These metrics will be managed by your MetricManager, and reported by your reporter.
- extends preDefinedMetric module:
- you can add value into
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/PredefinedMetric
, such asSystem
andThread
. - then you need to fix the implementation of
enablePredefinedMetric(PredefinedMetric metric)
in your manager.
- you can add value into