Skip to content
Permalink
Browse files
[IOTDB-3214] Refact predefined metrics in metric framework. (#5930)
  • Loading branch information
SpriCoder committed May 19, 2022
1 parent b724afb commit dd1a28c58d7718fb1372b5e5a44e8d79057ecdbe
Show file tree
Hide file tree
Showing 44 changed files with 1,364 additions and 541 deletions.
18 LICENSE
@@ -257,4 +257,20 @@ The following files include code modified from Eclipse Collections project.

Copyright: 2021 Goldman Sachs
Project page: https://www.eclipse.org/collections
License: https://github.com/eclipse/eclipse-collections/blob/master/LICENSE-EDL-1.0.txt
License: https://github.com/eclipse/eclipse-collections/blob/master/LICENSE-EDL-1.0.txt

--------------------------------------------------------------------------------

The following files include code modified from Micrometer project.

./metrics/interface/src/main/java/org/apache/iotdb/metrics/predefined/jvm/JvmClassLoaderMetrics
./metrics/interface/src/main/java/org/apache/iotdb/metrics/predefined/jvm/JvmCompileMetrics
./metrics/interface/src/main/java/org/apache/iotdb/metrics/predefined/jvm/JvmGcMetrics
./metrics/interface/src/main/java/org/apache/iotdb/metrics/predefined/jvm/JvmMemoryMetrics
./metrics/interface/src/main/java/org/apache/iotdb/metrics/predefined/jvm/JvmThreadMetrics
./metrics/interface/src/main/java/org/apache/iotdb/metrics/predefined/logback/LogbackMetrics
./metrics/interface/src/main/java/org/apache/iotdb/metrics/utils/JvmUtils

Copyright: 2017 VMware
Project page: https://github.com/micrometer-metrics/micrometer
License: https://github.com/micrometer-metrics/micrometer/blob/main/LICENSE
@@ -31,9 +31,9 @@
import org.apache.iotdb.cluster.server.member.DataGroupMember;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.db.service.IoTDB;
import org.apache.iotdb.db.service.metrics.Metric;
import org.apache.iotdb.db.service.metrics.MetricsService;
import org.apache.iotdb.db.service.metrics.Tag;
import org.apache.iotdb.db.service.metrics.enums.Metric;
import org.apache.iotdb.db.service.metrics.enums.Tag;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.tsfile.write.schema.TimeseriesSchema;
@@ -21,9 +21,9 @@

import org.apache.iotdb.cluster.rpc.thrift.Node;
import org.apache.iotdb.cluster.server.member.RaftMember;
import org.apache.iotdb.db.service.metrics.Metric;
import org.apache.iotdb.db.service.metrics.MetricsService;
import org.apache.iotdb.db.service.metrics.Tag;
import org.apache.iotdb.db.service.metrics.enums.Metric;
import org.apache.iotdb.db.service.metrics.enums.Tag;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.utils.MetricLevel;

@@ -42,9 +42,9 @@
import org.apache.iotdb.commons.service.IService;
import org.apache.iotdb.commons.service.JMXService;
import org.apache.iotdb.commons.service.ServiceType;
import org.apache.iotdb.db.service.metrics.Metric;
import org.apache.iotdb.db.service.metrics.MetricsService;
import org.apache.iotdb.db.service.metrics.Tag;
import org.apache.iotdb.db.service.metrics.enums.Metric;
import org.apache.iotdb.db.service.metrics.enums.Tag;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.tsfile.utils.Pair;

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -36,20 +36,13 @@
import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.PredefinedMetric;

import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.UniformReservoir;
import com.codahale.metrics.jvm.BufferPoolMetricSet;
import com.codahale.metrics.jvm.CachedThreadStatesGaugeSet;
import com.codahale.metrics.jvm.ClassLoadingGaugeSet;
import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
import com.codahale.metrics.jvm.JvmAttributeGaugeSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -415,31 +408,6 @@ public MetricRegistry getMetricRegistry() {
return metricRegistry;
}

@Override
public void enablePredefinedMetric(PredefinedMetric metric) {
if (!isEnable()) {
return;
}
switch (metric) {
case JVM:
enableJvmMetrics();
break;
default:
logger.warn("Unsupported metric type {}", metric);
}
}

private void enableJvmMetrics() {
if (!isEnable()) {
return;
}
metricRegistry.registerAll(new JvmAttributeGaugeSet());
metricRegistry.registerAll(new GarbageCollectorMetricSet());
metricRegistry.registerAll(new ClassLoadingGaugeSet());
metricRegistry.registerAll(new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
metricRegistry.registerAll(new CachedThreadStatesGaugeSet(5, TimeUnit.MILLISECONDS));
}

@Override
public boolean init() {
// init something
@@ -20,7 +20,7 @@
# whether enable the module
enableMetric: false

# Is stat performance of sub-module enable
# Is stat performance of operation latency
enablePerformanceStat: false

# Multiple reporter, options: [JMX, PROMETHEUS, IOTDB], IOTDB is off by default
@@ -34,9 +34,10 @@ monitorType: MICROMETER
# Level of metric level, options: [CORE, IMPORTANT, NORMAL, ALL]
metricLevel: IMPORTANT

# Predefined metric, options: [JVM, LOGBACK], LOGBACK are not supported in dropwizard
# Predefined metric, options: [JVM, LOGBACK, FILE, PROCESS, SYSTEM]
predefinedMetrics:
- JVM
- FILE

# The http server's port for prometheus exporter to get metric data.
prometheusExporterPort: 9091
@@ -20,22 +20,12 @@
package org.apache.iotdb.metrics;

import org.apache.iotdb.metrics.config.ReloadLevel;
import org.apache.iotdb.metrics.utils.PredefinedMetric;

public class DoNothingMetricService extends MetricService {
@Override
protected void collectFileSystemInfo() {
// do nothing
}

@Override
protected void collectProcessInfo() {
// do nothing
}

@Override
protected void collectSystemInfo() {
// do nothing
}
public void enablePredefinedMetric(PredefinedMetric metric) {}

@Override
protected void reloadProperties(ReloadLevel reloadLevel) {
@@ -25,7 +25,6 @@
import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.PredefinedMetric;

import java.util.List;
import java.util.Map;
@@ -159,13 +158,6 @@ <T> Gauge getOrCreateAutoGauge(
/** whether is enabled monitor in specific level */
boolean isEnable(MetricLevel metricLevel);

/**
* enable pre-defined metric set.
*
* @param metric which metric set we want to collect
*/
void enablePredefinedMetric(PredefinedMetric metric);

/**
* init something.
*
@@ -71,14 +71,6 @@ public void startService() {
enablePredefinedMetric(predefinedMetric);
}
logger.info("Start metric at level: " + metricConfig.getMetricLevel().name());

collectFileSystemInfo();

// Collect process monitoring information
collectProcessInfo();

// Collect system monitoring information
collectSystemInfo();
}

/** Stop metric service. if is disabled, do nothing */
@@ -156,18 +148,7 @@ public void stop(ReporterType reporter) {
* Enable some predefined metric, now support jvm, logback. Notice: In dropwizard mode, logback
* metrics are not supported
*/
public void enablePredefinedMetric(PredefinedMetric metric) {
metricManager.enablePredefinedMetric(metric);
}

/** collect file system info in metric way */
protected abstract void collectFileSystemInfo();

/** collect process info in metric way */
protected abstract void collectProcessInfo();

/** collect system hardware info in metric way */
protected abstract void collectSystemInfo();
public abstract void enablePredefinedMetric(PredefinedMetric metric);

/**
* support hot load of some properties
@@ -25,7 +25,6 @@
import org.apache.iotdb.metrics.utils.ReporterType;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@@ -46,7 +45,7 @@ public class MetricConfig {
private MetricLevel metricLevel = MetricLevel.IMPORTANT;

private List<PredefinedMetric> predefinedMetrics =
Collections.singletonList(PredefinedMetric.JVM);
Arrays.asList(PredefinedMetric.JVM, PredefinedMetric.FILE);

/** the http server's port for prometheus exporter to get metric data. */
private String prometheusExporterPort = "9091";
@@ -26,7 +26,6 @@
import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.PredefinedMetric;

import java.util.Collections;
import java.util.List;
@@ -139,9 +138,6 @@ public boolean isEnable(MetricLevel metricLevel) {
return false;
}

@Override
public void enablePredefinedMetric(PredefinedMetric metric) {}

@Override
public boolean init() {
return false;
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.metrics.predefined;

import org.apache.iotdb.metrics.MetricManager;
import org.apache.iotdb.metrics.utils.PredefinedMetric;

public interface IMetricSet {
/** bind related metric to metric manager */
void bindTo(MetricManager metricManager);

/** get type of metric set */
PredefinedMetric getType();
}
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.metrics.predefined.jvm;

import org.apache.iotdb.metrics.MetricManager;
import org.apache.iotdb.metrics.predefined.IMetricSet;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.PredefinedMetric;

import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;

/** This file is modified from io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics */
public class JvmClassLoaderMetrics implements IMetricSet {
@Override
public void bindTo(MetricManager metricManager) {
ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();

metricManager.getOrCreateAutoGauge(
"jvm.classes.loaded.classes",
MetricLevel.IMPORTANT,
classLoadingBean,
ClassLoadingMXBean::getLoadedClassCount);
metricManager.getOrCreateAutoGauge(
"jvm.classes.unloaded.classes",
MetricLevel.IMPORTANT,
classLoadingBean,
ClassLoadingMXBean::getUnloadedClassCount);
}

@Override
public PredefinedMetric getType() {
return PredefinedMetric.JVM;
}
}
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.metrics.predefined.jvm;

import org.apache.iotdb.metrics.MetricManager;
import org.apache.iotdb.metrics.predefined.IMetricSet;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.PredefinedMetric;

import java.lang.management.CompilationMXBean;
import java.lang.management.ManagementFactory;

/** This file is modified from io.micrometer.core.instrument.binder.jvm.JvmCompilationMetrics */
public class JvmCompileMetrics implements IMetricSet {
@Override
public void bindTo(MetricManager metricManager) {
CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean();
if (compilationBean != null && compilationBean.isCompilationTimeMonitoringSupported()) {
metricManager.getOrCreateAutoGauge(
"jvm.compilation.time.ms",
MetricLevel.IMPORTANT,
compilationBean,
CompilationMXBean::getTotalCompilationTime,
"compiler",
compilationBean.getName());
}
}

@Override
public PredefinedMetric getType() {
return PredefinedMetric.JVM;
}
}

0 comments on commit dd1a28c

Please sign in to comment.