Metric Module
1. Design
The acquisition system consists of following four parts.
- Metrics:Provide tools for collecting metric in different scenarios, including Counter, Gauge, Histogram, Timer and Rate, each with tags.
 - MetricManager
- Provide functions such as create, query, update and remove metrics.
 - Provide its own start and stop methods.
 
 - CompositeReporter
- Provide management of reporter.
 - Provide metric value to other systems, such as Jmx, Prometheus, IoTDB, etc.
 - Provide its own start and stop methods.
 
 - MetricService
- Provide the start and stop method of metric service.
 - Provide the ability to reload properties when running.
 - Provide the ability to load predefined metric sets.
 - Provide the access of metricManager and CompositeReporter.
 
 
2. Test Report
We implemented the monitoring framework using Dropwizard and Micrometer respectively, and tested the results as follows:
2.1. Test Environment
- Processor:Inter(R) Core(TM) i7-1065G7 CPU
 - RAM: 32G
 
2.2. Test Metrics
- 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.
 
 
2.3. Test parameters
- 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.
 
2.4. Test Result

3. How to use?
3.1. Configuration
- 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 | 
| enablePerformanceStat | Is stat performance of operation latency | true | 
| metricReporterList | the list of reporter | JMX, PROMETHEUS, IOTDB | 
| monitorType | The type of metric manager | DROPWIZARD, MICROMETER | 
| metricLevel | the init level of metrics | ALL, NORMAL, IMPORTANT, CORE | 
| predefinedMetrics | predefined set of metrics | JVM, LOGBACK, FILE, PROCESS, SYSTEM | 
| asyncCollectPeriodInSecond | The period of the collection of some metrics in asynchronous way, such as tsfile size. | 5 | 
| pushPeriodInSecond | the period time of push(used for prometheus, unit: s) | 5 | 
3.2. Use Guide in IoTDB Server Module
- Now, MetricService is registered as IService in server and confignode module, you can simple set properties: 
enableMetric: true to use metric service. - In server module you can easily use these metric by 
MetricService.getInstance(), for example: 
MetricService.getInstance().count(1, "operation_count", MetricLevel.IMPORTANT, "name", operation.getName());
4. How to implement your own metric framework?
- implement your MetricService
- You need to implement 
enablePredefinedMetrics to load predefined metrics. - You need to implement 
reloadProperties to reload properties when running. 
 - 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.AbstractMetricManager,and record your MetricManager class name in this file, such as org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager 
 - 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 as org.apache.iotdb.metrics.dropwizard.reporter.DropwizardPrometheusReporter 
 - 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 as System and Thread. - then you need to fix the implementation of 
enablePredefinedMetric(PredefinedMetric metric) in your manager. 
 
5. Some docs
- Metric Tool
 - Metric Tool(zh)