We implemented the monitoring framework using Dropwizard and Micrometer respectively, and tested the results as follows:
System.setProperty("line.separator", "\n"); System.setProperty("IOTDB_CONF", "metrics/dropwizard-metrics/src/test/resources");
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 |
startService
method to load manager and reporters.MetricService.getMetricManager()
to get metric manager.metrics/interface/src/main/java/org/apache/iotdb/metrics/MetricManager
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); } } }
enableMetric: true
to get a instance of MetricsService.MetricsService.getInstance().getMetricManager()
, for example:MetricsService.getInstance() .count(1, "operation_count", MetricLevel.IMPORTANT, "name", operation.getName());
collectFileSystemInfo
to collect file system info as you like.reloadProperties
to support hot load.monitorType
, MetricService will init manager according to the prefix of class name.src/main/resources/META-INF/services/org.apache.iotdb.metrics.MetricManager
,and record your MetricManager class name in this file, such as org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager
org.apache.iotdb.metrics
monitorType
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
metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/PredefinedMetric
, such as System
and Thread
.enablePredefinedMetric(PredefinedMetric metric)
in your manager.