未验证 提交 91aa0341 编写于 作者: Z ZhangHongYin 提交者: GitHub

[IOTDB-4994] Unify reporter (#8144)

上级 9f12b58c
......@@ -1044,7 +1044,6 @@ public class ConfigManager implements IManager {
@Override
public void addMetrics() {
partitionManager.addMetrics();
nodeManager.addMetrics();
}
@Override
......
......@@ -41,6 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_CONFIG_NODE;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_DATA_NODE;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_STATUS_ONLINE;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_STATUS_REGISTER;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_STATUS_UNKNOWN;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_TAG_TOTAL;
......@@ -55,11 +56,26 @@ public class LoadManagerMetrics implements IMetricSet {
@Override
public void bindTo(AbstractMetricService metricService) {
addNodeMetrics(metricService);
addLeaderCount(metricService);
}
metricService.createAutoGauge(
Metric.CONFIG_NODE.toString(),
MetricLevel.CORE,
this,
o -> getRegisterConfigNodesNum(metricService),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
metricService.createAutoGauge(
Metric.DATA_NODE.toString(),
MetricLevel.CORE,
this,
o -> getRegisterDataNodesNum(metricService),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
private void addNodeMetrics(AbstractMetricService metricService) {
metricService.createAutoGauge(
Metric.CONFIG_NODE.toString(),
MetricLevel.CORE,
......@@ -101,40 +117,26 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_UNKNOWN);
}
/** Get the LeaderCount of Specific DataNodeId */
private Integer getLeadershipCountByDatanode(int dataNodeId) {
Map<Integer, Integer> idToCountMap = new ConcurrentHashMap<>();
getLoadManager()
.getLatestRegionLeaderMap()
.forEach((consensusGroupId, nodeId) -> idToCountMap.merge(nodeId, 1, Integer::sum));
return idToCountMap.get(dataNodeId);
}
private void addLeaderCount(AbstractMetricService metricService) {
getNodeManager()
.getRegisteredDataNodes()
.forEach(
dataNodeInfo -> {
TDataNodeLocation dataNodeLocation = dataNodeInfo.getLocation();
int dataNodeId = dataNodeLocation.getDataNodeId();
String name =
NodeUrlUtils.convertTEndPointUrl(dataNodeLocation.getClientRpcEndPoint());
metricService.createAutoGauge(
Metric.CLUSTER_NODE_LEADER_COUNT.toString(),
MetricLevel.IMPORTANT,
this,
o -> getLeadershipCountByDatanode(dataNodeId),
Tag.NAME.toString(),
name);
});
}
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.CONFIG_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
metricService.remove(
MetricType.AUTO_GAUGE,
Metric.DATA_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
metricService.remove(
MetricType.AUTO_GAUGE,
Metric.CONFIG_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
......@@ -142,7 +144,7 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_ONLINE);
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.DATA_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
......@@ -150,7 +152,7 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_ONLINE);
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.CONFIG_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
......@@ -158,7 +160,7 @@ public class LoadManagerMetrics implements IMetricSet {
METRIC_STATUS_UNKNOWN);
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.DATA_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
......@@ -193,6 +195,32 @@ public class LoadManagerMetrics implements IMetricSet {
return configManager.getLoadManager();
}
private int getRegisterConfigNodesNum(AbstractMetricService metricService) {
return getNodeManager().getRegisteredConfigNodes().size();
}
private int getRegisterDataNodesNum(AbstractMetricService metricService) {
List<TDataNodeConfiguration> dataNodeConfigurations = getNodeManager().getRegisteredDataNodes();
Map<Integer, Integer> idToCountMap = new ConcurrentHashMap<>();
getLoadManager()
.getLatestRegionLeaderMap()
.forEach((consensusGroupId, nodeId) -> idToCountMap.merge(nodeId, 1, Integer::sum));
for (TDataNodeConfiguration dataNodeInfo : dataNodeConfigurations) {
TDataNodeLocation dataNodeLocation = dataNodeInfo.getLocation();
int dataNodeId = dataNodeLocation.getDataNodeId();
String name = NodeUrlUtils.convertTEndPointUrl(dataNodeLocation.getClientRpcEndPoint());
metricService
.getOrCreateGauge(
Metric.CLUSTER_NODE_LEADER_COUNT.toString(),
MetricLevel.IMPORTANT,
Tag.NAME.toString(),
name)
.set(idToCountMap.getOrDefault(dataNodeId, 0));
}
return dataNodeConfigurations.size();
}
private int getRunningConfigNodesNum(AbstractMetricService metricService) {
List<TConfigNodeLocation> runningConfigNodes =
getNodeManager().filterConfigNodeThroughStatus(NodeStatus.Running);
......
......@@ -31,7 +31,6 @@ import org.apache.iotdb.commons.concurrent.threadpool.ScheduledExecutorUtil;
import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.consensus.ConsensusGroupId;
import org.apache.iotdb.commons.service.metric.MetricService;
import org.apache.iotdb.commons.utils.StatusUtils;
import org.apache.iotdb.confignode.client.DataNodeRequestType;
import org.apache.iotdb.confignode.client.async.AsyncConfigNodeHeartbeatClientPool;
......@@ -61,7 +60,6 @@ import org.apache.iotdb.confignode.manager.node.heartbeat.BaseNodeCache;
import org.apache.iotdb.confignode.manager.node.heartbeat.ConfigNodeHeartbeatCache;
import org.apache.iotdb.confignode.manager.node.heartbeat.DataNodeHeartbeatCache;
import org.apache.iotdb.confignode.manager.partition.PartitionManager;
import org.apache.iotdb.confignode.persistence.metric.NodeInfoMetrics;
import org.apache.iotdb.confignode.persistence.node.NodeInfo;
import org.apache.iotdb.confignode.procedure.env.DataNodeRemoveHandler;
import org.apache.iotdb.confignode.rpc.thrift.TCQConfig;
......@@ -550,10 +548,6 @@ public class NodeManager {
getConsensusManager().write(applyConfigNodePlan);
}
public void addMetrics() {
MetricService.getInstance().addMetricSet(new NodeInfoMetrics(nodeInfo));
}
/**
* Only leader use this interface, check the ConfigNode before remove it
*
......
/*
* 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.confignode.persistence.metric;
import org.apache.iotdb.commons.service.metric.enums.Metric;
import org.apache.iotdb.commons.service.metric.enums.Tag;
import org.apache.iotdb.confignode.persistence.node.NodeInfo;
import org.apache.iotdb.metrics.AbstractMetricService;
import org.apache.iotdb.metrics.metricsets.IMetricSet;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.MetricType;
import java.util.Objects;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_STATUS_REGISTER;
import static org.apache.iotdb.confignode.conf.ConfigNodeConstant.METRIC_TAG_TOTAL;
public class NodeInfoMetrics implements IMetricSet {
private final NodeInfo nodeInfo;
public NodeInfoMetrics(NodeInfo nodeInfo) {
this.nodeInfo = nodeInfo;
}
@Override
public void bindTo(AbstractMetricService metricService) {
metricService.createAutoGauge(
Metric.CONFIG_NODE.toString(),
MetricLevel.CORE,
this,
o -> nodeInfo.getRegisteredConfigNodeCount(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
metricService.createAutoGauge(
Metric.DATA_NODE.toString(),
MetricLevel.CORE,
this,
o -> nodeInfo.getRegisteredDataNodeCount(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
}
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
Metric.CONFIG_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
metricService.remove(
MetricType.GAUGE,
Metric.DATA_NODE.toString(),
Tag.NAME.toString(),
METRIC_TAG_TOTAL,
Tag.STATUS.toString(),
METRIC_STATUS_REGISTER);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeInfoMetrics that = (NodeInfoMetrics) o;
return Objects.equals(nodeInfo, that.nodeInfo);
}
@Override
public int hashCode() {
return Objects.hash(nodeInfo);
}
}
......@@ -70,16 +70,16 @@ public class PartitionInfoMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.QUANTITY.toString(), Tag.NAME.toString(), "storageGroup");
MetricType.AUTO_GAUGE, Metric.QUANTITY.toString(), Tag.NAME.toString(), "storageGroup");
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.REGION.toString(),
Tag.NAME.toString(),
"total",
Tag.TYPE.toString(),
TConsensusGroupType.SchemaRegion.toString());
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.REGION.toString(),
Tag.NAME.toString(),
"total",
......@@ -152,14 +152,14 @@ public class PartitionInfoMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.REGION.toString(),
Tag.NAME.toString(),
storageGroupPartitionTable.getStorageGroupName(),
Tag.TYPE.toString(),
TConsensusGroupType.SchemaRegion.toString());
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.REGION.toString(),
Tag.NAME.toString(),
storageGroupPartitionTable.getStorageGroupName(),
......@@ -167,14 +167,14 @@ public class PartitionInfoMetrics implements IMetricSet {
TConsensusGroupType.DataRegion.toString());
// TODO slot will be updated in the future
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.SLOT.toString(),
Tag.NAME.toString(),
storageGroupPartitionTable.getStorageGroupName(),
Tag.TYPE.toString(),
"schemaSlotNumber");
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.SLOT.toString(),
Tag.NAME.toString(),
storageGroupPartitionTable.getStorageGroupName(),
......
......@@ -48,7 +48,7 @@ public class ConfigNodeRPCServiceHandlerMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.THRIFT_CONNECTIONS.toString(),
Tag.NAME.toString(),
"ConfigNodeRPC");
......
......@@ -49,7 +49,7 @@ public class ConfigNodeRPCServiceMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.THRIFT_ACTIVE_THREADS.toString(),
Tag.NAME.toString(),
ThreadName.CONFIGNODE_RPC_SERVICE.getName());
......
......@@ -25,10 +25,9 @@ cn_system_dir=target/confignode1/system
cn_data_dirs=target/confignode1/data
cn_consensus_dir=target/confignode1/consensus
cn_enable_metric=true
cn_enable_performance_stat=false
cn_metric_reporter_list=PROMETHEUS
cn_metric_reporter_list=JMX,PROMETHEUS
cn_metric_frame_type=MICROMETER
cn_metric_level=CORE
cn_metric_level=IMPORTANT
cn_metric_async_collect_period=5
cn_metric_prometheus_reporter_port=9091
\ No newline at end of file
......@@ -25,10 +25,9 @@ cn_system_dir=target/confignode2/system
cn_data_dirs=target/confignode2/data
cn_consensus_dir=target/confignode2/consensus
cn_enable_metric=true
cn_enable_performance_stat=false
cn_metric_reporter_list=PROMETHEUS
cn_metric_frame_type=MICROMETER
cn_metric_level=CORE
cn_metric_level=IMPORTANT
cn_metric_async_collect_period=5
cn_metric_prometheus_reporter_port=9093
\ No newline at end of file
......@@ -25,10 +25,9 @@ cn_system_dir=target/confignode3/system
cn_data_dirs=target/confignode3/data
cn_consensus_dir=target/confignode3/consensus
cn_enable_metric=true
cn_enable_performance_stat=false
cn_metric_reporter_list=PROMETHEUS
cn_metric_frame_type=MICROMETER
cn_metric_level=CORE
cn_metric_level=IMPORTANT
cn_metric_async_collect_period=5
cn_metric_prometheus_reporter_port=9095
\ No newline at end of file
......@@ -66,7 +66,7 @@ public class MultiLeaderServerMetrics implements IMetricSet {
public void unbindFrom(AbstractMetricService metricService) {
MetricService.getInstance()
.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.MULTI_LEADER.toString(),
Tag.NAME.toString(),
"multiLeaderServerImpl",
......@@ -76,7 +76,7 @@ public class MultiLeaderServerMetrics implements IMetricSet {
"searchIndex");
MetricService.getInstance()
.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.MULTI_LEADER.toString(),
Tag.NAME.toString(),
"multiLeaderServerImpl",
......
......@@ -66,7 +66,7 @@ public class LogDispatcherThreadMetrics implements IMetricSet {
public void unbindFrom(AbstractMetricService metricService) {
MetricService.getInstance()
.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.MULTI_LEADER.toString(),
Tag.NAME.toString(),
formatName(),
......@@ -76,7 +76,7 @@ public class LogDispatcherThreadMetrics implements IMetricSet {
"currentSyncIndex");
MetricService.getInstance()
.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.MULTI_LEADER.toString(),
Tag.NAME.toString(),
formatName(),
......
......@@ -47,6 +47,6 @@ public class MultiLeaderMemoryManagerMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.MEM.toString(), Tag.NAME.toString(), "MultiLeaderConsensus");
MetricType.AUTO_GAUGE, Metric.MEM.toString(), Tag.NAME.toString(), "MultiLeaderConsensus");
}
}
......@@ -43,11 +43,6 @@
<artifactId>metrics-jmx</artifactId>
<version>${dropwizard.metrics.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-http</artifactId>
<version>${reactor-netty-http.version}</version>
</dependency>
</dependencies>
<properties>
<jersey-core.version>1.9</jersey-core.version>
......
/*
* 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.dropwizard.reporter;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.utils.ReporterType;
import com.codahale.metrics.MetricFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
public class DropwizardIoTDBReporter implements Reporter {
private static final Logger LOGGER = LoggerFactory.getLogger(DropwizardIoTDBReporter.class);
private AbstractMetricManager dropwizardMetricManager = null;
private IoTDBReporter reporter;
@Override
public boolean start() {
if (reporter != null) {
LOGGER.warn("Dropwizard IoTDBReporter already start!");
return false;
}
reporter =
IoTDBReporter.forRegistry(
((DropwizardMetricManager) dropwizardMetricManager).getMetricRegistry())
.prefixedWith("dropwizard:")
.filter(MetricFilter.ALL)
.build();
reporter.start(
MetricConfigDescriptor.getInstance()
.getMetricConfig()
.getIoTDBReporterConfig()
.getPushPeriodInSecond(),
TimeUnit.SECONDS);
return true;
}
@Override
public boolean stop() {
if (reporter != null) {
reporter.stop();
reporter = null;
}
return true;
}
@Override
public ReporterType getReporterType() {
return ReporterType.IOTDB;
}
@Override
public void setMetricManager(AbstractMetricManager metricManager) {
this.dropwizardMetricManager = metricManager;
}
}
......@@ -21,18 +21,17 @@ package org.apache.iotdb.metrics.dropwizard.reporter;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.reporter.JmxReporter;
import org.apache.iotdb.metrics.utils.ReporterType;
import com.codahale.metrics.jmx.JmxReporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DropwizardJmxReporter implements Reporter {
public class DropwizardJmxReporter implements JmxReporter {
private static final Logger LOGGER = LoggerFactory.getLogger(DropwizardJmxReporter.class);
private AbstractMetricManager dropwizardMetricManager = null;
private JmxReporter jmxReporter = null;
private com.codahale.metrics.jmx.JmxReporter jmxReporter = null;
@Override
public boolean start() {
......@@ -42,7 +41,7 @@ public class DropwizardJmxReporter implements Reporter {
}
try {
jmxReporter =
JmxReporter.forRegistry(
com.codahale.metrics.jmx.JmxReporter.forRegistry(
((DropwizardMetricManager) dropwizardMetricManager).getMetricRegistry())
.inDomain("org.apache.iotdb.metrics")
.build();
......
/*
* 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.dropwizard.reporter;
import org.apache.iotdb.metrics.dropwizard.DropwizardMetricNameTool;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.MetricType;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metered;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.Timer;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
class DropwizardMetricsExporter {
private final MetricRegistry metricRegistry;
private final PrometheusTextWriter writer;
public DropwizardMetricsExporter(MetricRegistry metricRegistry, PrometheusTextWriter writer) {
this.metricRegistry = metricRegistry;
this.writer = writer;
}
public void scrape() throws IOException {
for (Map.Entry<String, Gauge> entry : metricRegistry.getGauges().entrySet()) {
writeGauge(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Counter> entry : metricRegistry.getCounters().entrySet()) {
writeCounter(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Histogram> entry : metricRegistry.getHistograms().entrySet()) {
writeHistogram(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Meter> entry : metricRegistry.getMeters().entrySet()) {
writeMeter(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Timer> entry : metricRegistry.getTimers().entrySet()) {
writeTimer(entry.getKey(), entry.getValue());
}
}
/** Export Gauge as Prometheus Gauge */
public void writeGauge(String dropwizardName, Gauge<?> gauge) throws IOException {
MetricInfo metricInfo =
DropwizardMetricNameTool.transformFromString(MetricType.GAUGE, dropwizardName);
String sanitizeName = metricInfo.getName();
writer.writeHelp(sanitizeName, getHelpMessage(dropwizardName, gauge));
writer.writeType(sanitizeName, DropwizardMetricType.GAUGE);
Object obj = gauge.getValue();
double value;
if (obj instanceof Number) {
value = ((Number) obj).doubleValue();
} else if (obj instanceof Boolean) {
value = ((Boolean) obj) ? 1 : 0;
} else {
return;
}
writer.writeSample(sanitizeName, metricInfo.getTags(), value);
}
/** Export counter as Prometheus Gauge */
public void writeCounter(String dropwizardName, Counter counter) throws IOException {
MetricInfo metricInfo =
DropwizardMetricNameTool.transformFromString(MetricType.COUNTER, dropwizardName);
String sanitizeName = metricInfo.getName() + "_total";
writer.writeHelp(sanitizeName, getHelpMessage(dropwizardName, counter));
writer.writeType(sanitizeName, DropwizardMetricType.GAUGE);
writer.writeSample(sanitizeName, metricInfo.getTags(), counter.getCount());
}
/** Export histogram snapshot as Prometheus SUMMARY */
public void writeHistogram(String dropwizardName, Histogram histogram) throws IOException {
writeSnapshotAndCount(
DropwizardMetricNameTool.transformFromString(MetricType.HISTOGRAM, dropwizardName),
histogram.getSnapshot(),
histogram.getCount(),
1.0,
getHelpMessage(dropwizardName, histogram));
}
/** Export histogram snapshot */
private void writeSnapshotAndCount(
MetricInfo metricInfo, Snapshot snapshot, long count, double factor, String helpMessage)
throws IOException {
String sanitizeName = metricInfo.getName() + "_seconds";
writer.writeHelp(sanitizeName, helpMessage);
writer.writeType(sanitizeName, DropwizardMetricType.SUMMARY);
Map<String, String> tags = metricInfo.getTags();
writer.writeSample(sanitizeName + "_max", tags, snapshot.getMax() * factor);
writer.writeSample(
sanitizeName + "_sum", tags, Arrays.stream(snapshot.getValues()).sum() * factor);
writer.writeSample(sanitizeName + "_count", tags, count);
}
/** Export Timer as Prometheus Summary */
public void writeTimer(String dropwizardName, Timer timer) throws IOException {
writeSnapshotAndCount(
DropwizardMetricNameTool.transformFromString(MetricType.TIMER, dropwizardName),
timer.getSnapshot(),
timer.getCount(),
1.0D / TimeUnit.SECONDS.toNanos(1L),
getHelpMessage(dropwizardName, timer));
}
/** Export Meter as Prometheus Counter */
public void writeMeter(String dropwizardName, Meter meter) throws IOException {
MetricInfo metricInfo =
DropwizardMetricNameTool.transformFromString(MetricType.COUNTER, dropwizardName);
String sanitizeName = metricInfo.getName() + "_total";
writer.writeHelp(sanitizeName, getHelpMessage(dropwizardName, meter));
writer.writeType(sanitizeName, DropwizardMetricType.COUNTER);
writer.writeSample(sanitizeName, metricInfo.getTags(), meter.getCount());
writeMetered(metricInfo, meter);
}
/** Export meter for multi type */
private void writeMetered(MetricInfo metricInfo, Metered metered) throws IOException {
String sanitizeName = metricInfo.getName();
Map<String, String> tags = metricInfo.getTags();
writer.writeSample(sanitizeName, addTags(tags, "rate", "m1"), metered.getOneMinuteRate());
writer.writeSample(sanitizeName, addTags(tags, "rate", "m5"), metered.getFiveMinuteRate());
writer.writeSample(sanitizeName, addTags(tags, "rate", "m15"), metered.getFifteenMinuteRate());
writer.writeSample(sanitizeName, addTags(tags, "rate", "mean"), metered.getMeanRate());
}
private Map<String, String> addTags(Map<String, String> tags, String key, String value) {
HashMap<String, String> result = new HashMap<>(tags);
result.put(key, value);
return result;
}
private static String getHelpMessage(String metricName, Metric metric) {
return String.format(
"Generated from Dropwizard metric import (metric=%s, type=%s)",
metricName, metric.getClass().getName());
}
}
/*
* 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.dropwizard.reporter;
import org.apache.iotdb.metrics.config.MetricConfig;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.dropwizard.DropwizardMetricNameTool;
import org.apache.iotdb.metrics.utils.IoTDBMetricsUtils;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.MetricType;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.Timer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class IoTDBReporter extends ScheduledReporter {
private static final Logger logger = LoggerFactory.getLogger(IoTDBReporter.class);
private static final MetricConfig.IoTDBReporterConfig ioTDBReporterConfig =
MetricConfigDescriptor.getInstance().getMetricConfig().getIoTDBReporterConfig();
private static final TimeUnit DURATION_UNIT = TimeUnit.MILLISECONDS;
private static final TimeUnit RATE_UNIT = TimeUnit.SECONDS;
private final String prefix;
private final SessionPool sessionPool;
protected IoTDBReporter(
MetricRegistry registry,
String prefix,
MetricFilter filter,
ScheduledExecutorService executor,
boolean shutdownExecutorOnStop) {
super(
registry,
"iotdb-reporter",
filter,
RATE_UNIT,
DURATION_UNIT,
executor,
shutdownExecutorOnStop);
this.prefix = prefix;
this.sessionPool =
new SessionPool(
ioTDBReporterConfig.getHost(),
ioTDBReporterConfig.getPort(),
ioTDBReporterConfig.getUsername(),
ioTDBReporterConfig.getPassword(),
ioTDBReporterConfig.getMaxConnectionNumber());
IoTDBMetricsUtils.checkOrCreateStorageGroup(sessionPool);
}
@Override
public void stop() {
super.stop();
if (sessionPool != null) {
sessionPool.close();
}
}
public static class Builder {
private final MetricRegistry metricRegistry;
private String prefix;
private MetricFilter metricFilter;
private ScheduledExecutorService executorService;
private boolean shutdownExecutorOnStop;
private Builder(MetricRegistry metricRegistry) {
this.metricRegistry = metricRegistry;
this.prefix = null;
this.metricFilter = MetricFilter.ALL;
this.executorService = null;
this.shutdownExecutorOnStop = true;
}
public Builder shutdownExecutorOnStop(boolean shutdownExecutorOnStop) {
this.shutdownExecutorOnStop = shutdownExecutorOnStop;
return this;
}
public Builder scheduleOn(ScheduledExecutorService executorService) {
this.executorService = executorService;
return this;
}
public Builder prefixedWith(String prefix) {
this.prefix = prefix;
return this;
}
public Builder filter(MetricFilter metricFilter) {
this.metricFilter = metricFilter;
return this;
}
public IoTDBReporter build() {
return new IoTDBReporter(
metricRegistry, prefix, metricFilter, executorService, shutdownExecutorOnStop);
}
}
@Override
public void report(
SortedMap<String, Gauge> gauges,
SortedMap<String, Counter> counters,
SortedMap<String, Histogram> histograms,
SortedMap<String, Meter> meters,
SortedMap<String, Timer> timers) {
for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
sendGauge(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
sendCounter(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
sendHistogram(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Meter> entry : meters.entrySet()) {
sendMeter(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Timer> entry : timers.entrySet()) {
sendTimer(entry.getKey(), entry.getValue());
}
}
private void sendGauge(String name, Gauge gauge) {
if (null == gauge) {
return;
}
MetricInfo metricInfo = DropwizardMetricNameTool.transformFromString(MetricType.GAUGE, name);
Object obj = gauge.getValue();
double value;
if (obj instanceof Number) {
value = ((Number) obj).doubleValue();
updateValue(prefixed(metricInfo.getName()), metricInfo.getTags(), value);
} else if (obj instanceof Boolean) {
updateValue(prefixed(metricInfo.getName()), metricInfo.getTags(), obj);
}
}
private void sendCounter(String name, Counter counter) {
if (null == counter) {
return;
}
MetricInfo metricInfo = DropwizardMetricNameTool.transformFromString(MetricType.COUNTER, name);
double value = counter.getCount();
updateValue(prefixed(metricInfo.getName()), metricInfo.getTags(), value);
}
private void sendHistogram(String name, Histogram histogram) {
if (null == histogram) {
return;
}
MetricInfo metricInfo =
DropwizardMetricNameTool.transformFromString(MetricType.HISTOGRAM, name);
writeSnapshotAndCount(
prefixed(metricInfo.getName()),
metricInfo.getTags(),
histogram.getSnapshot(),
histogram.getCount(),
1.0);
}
private void sendMeter(String name, Meter meter) {
if (null == meter) {
return;
}
MetricInfo metricInfo = DropwizardMetricNameTool.transformFromString(MetricType.GAUGE, name);
double value = meter.getCount();
updateValue(prefixed(metricInfo.getName()), metricInfo.getTags(), value);
}
private void sendTimer(String name, Timer timer) {
if (null == timer) {
return;
}
MetricInfo metricInfo = DropwizardMetricNameTool.transformFromString(MetricType.GAUGE, name);
writeSnapshotAndCount(
prefixed(metricInfo.getName()),
metricInfo.getTags(),
timer.getSnapshot(),
timer.getCount(),
1.0D / TimeUnit.SECONDS.toNanos(1L));
}
private void writeSnapshotAndCount(
String name, Map<String, String> tags, Snapshot snapshot, long count, double factor) {
updateValue(name, addTags(tags, "quantile", "0.5"), snapshot.getMedian() * factor);
updateValue(name, addTags(tags, "quantile", "0.75"), snapshot.get75thPercentile() * factor);
updateValue(name, addTags(tags, "quantile", "0.95"), snapshot.get95thPercentile() * factor);
updateValue(name, addTags(tags, "quantile", "0.98"), snapshot.get98thPercentile() * factor);
updateValue(name, addTags(tags, "quantile", "0.99"), snapshot.get99thPercentile() * factor);
updateValue(name, addTags(tags, "quantile", "0.999"), snapshot.get999thPercentile() * factor);
updateValue(name + "_min", tags, snapshot.getMin());
updateValue(name + "_max", tags, snapshot.getMax());
updateValue(name + "_median", tags, snapshot.getMedian());
updateValue(name + "_mean", tags, snapshot.getMean());
updateValue(name + "_stddev", tags, snapshot.getStdDev());
updateValue(name + "_count", tags, count);
}
private void updateValue(String name, Map<String, String> labels, Object value) {
if (value != null) {
String deviceId = IoTDBMetricsUtils.generatePath(name, labels);
List<String> sensors = Collections.singletonList("value");
List<TSDataType> dataTypes = new ArrayList<>();
if (value instanceof Boolean) {
dataTypes.add(TSDataType.BOOLEAN);
} else if (value instanceof Integer) {
dataTypes.add(TSDataType.INT32);
} else if (value instanceof Long) {
dataTypes.add(TSDataType.INT64);
} else if (value instanceof Double) {
dataTypes.add(TSDataType.DOUBLE);
} else {
dataTypes.add(TSDataType.TEXT);
value = value.toString();
}
List<Object> values = Collections.singletonList(value);
try {
sessionPool.insertRecord(deviceId, System.currentTimeMillis(), sensors, dataTypes, values);
} catch (IoTDBConnectionException | StatementExecutionException e) {
logger.warn("Failed to insert record");
}
}
}
private String prefixed(String name) {
return prefix == null ? name : (prefix + name);
}
private Map<String, String> addTags(Map<String, String> tags, String key, String value) {
HashMap<String, String> result = new HashMap<>(tags);
result.put(key, value);
return result;
}
public static Builder forRegistry(MetricRegistry metricRegistry) {
return new Builder(metricRegistry);
}
}
......@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.dropwizard.type;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
import java.io.OutputStream;
public class DropwizardHistogramSnapshot implements HistogramSnapshot {
com.codahale.metrics.Snapshot snapshot;
......@@ -65,9 +63,4 @@ public class DropwizardHistogramSnapshot implements HistogramSnapshot {
public long getMin() {
return snapshot.getMin();
}
@Override
public void dump(OutputStream output) {
snapshot.dump(output);
}
}
......@@ -15,6 +15,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardJmxReporter
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardPrometheusReporter
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardIoTDBReporter
\ No newline at end of file
org.apache.iotdb.metrics.dropwizard.reporter.DropwizardJmxReporter
\ No newline at end of file
......@@ -23,6 +23,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<snakeyaml.version>1.31</snakeyaml.version>
<reactor-netty-http.version>1.0.24</reactor-netty-http.version>
</properties>
<parent>
<groupId>org.apache.iotdb</groupId>
......@@ -35,16 +36,16 @@
<description>Metrics interface for IoTDB</description>
<url>https://github.com/thulab/iotdb/tree/master/tsfile</url>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-http</artifactId>
<version>${reactor-netty-http.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -32,6 +32,7 @@ import org.apache.iotdb.metrics.type.Timer;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.MetricType;
import org.apache.iotdb.tsfile.utils.Pair;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -102,7 +103,7 @@ public abstract class AbstractMetricManager {
if (!isValid(metricLevel, name, tags)) {
return DoNothingMetricManager.doNothingAutoGauge;
}
MetricInfo metricInfo = new MetricInfo(MetricType.GAUGE, name, tags);
MetricInfo metricInfo = new MetricInfo(MetricType.AUTO_GAUGE, name, tags);
AutoGauge gauge = createAutoGauge(metricInfo, obj, mapper);
nameToMetaInfo.put(name, metricInfo.getMetaInfo());
metrics.put(metricInfo, gauge);
......@@ -119,7 +120,7 @@ public abstract class AbstractMetricManager {
if (!isValid(metricLevel, name, tags)) {
return DoNothingMetricManager.doNothingAutoGauge;
}
MetricInfo metricInfo = new MetricInfo(MetricType.GAUGE, name, tags);
MetricInfo metricInfo = new MetricInfo(MetricType.AUTO_GAUGE, name, tags);
IMetric metric = metrics.get(metricInfo);
if (metric == null) {
return DoNothingMetricManager.doNothingAutoGauge;
......@@ -360,102 +361,36 @@ public abstract class AbstractMetricManager {
/**
* Get all metric keys.
*
* @return [[name, tags...], ..., [name, tags...]]
* @return [[name, [tags...]], ..., [name, [tags...]]]
*/
protected List<String[]> getAllMetricKeys() {
List<String[]> keys = new ArrayList<>(metrics.size());
public List<Pair<String, String[]>> getAllMetricKeys() {
List<Pair<String, String[]>> keys = new ArrayList<>(metrics.size());
metrics.keySet().forEach(k -> keys.add(k.toStringArray()));
return keys;
}
/**
* Get all counters
*
* @return [name, tags...] -> counter
*/
protected Map<String[], Counter> getAllCounters() {
Map<String[], Counter> counterMap = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> entry : metrics.entrySet()) {
if (entry.getValue() instanceof Counter) {
counterMap.put(entry.getKey().toStringArray(), (Counter) entry.getValue());
}
}
return counterMap;
}
/**
* Get all gauges
* Get all metrics.
*
* @return [name, tags...] -> gauge
* @return [name, [tags...]] -> metric
*/
protected Map<String[], Gauge> getAllGauges() {
Map<String[], Gauge> gaugeMap = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> entry : metrics.entrySet()) {
if (entry.getValue() instanceof Gauge) {
gaugeMap.put(entry.getKey().toStringArray(), (Gauge) entry.getValue());
}
}
return gaugeMap;
}
/**
* Get all autoGauges
*
* @return [name, tags...] -> autoGauge
*/
protected Map<String[], AutoGauge> getAllAutoGauges() {
Map<String[], AutoGauge> gaugeMap = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> entry : metrics.entrySet()) {
if (entry.getValue() instanceof AutoGauge) {
gaugeMap.put(entry.getKey().toStringArray(), (AutoGauge) entry.getValue());
}
}
return gaugeMap;
}
/**
* Get all rates
*
* @return [name, tags...] -> rate
*/
protected Map<String[], Rate> getAllRates() {
Map<String[], Rate> rateMap = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> entry : metrics.entrySet()) {
if (entry.getValue() instanceof Rate) {
rateMap.put(entry.getKey().toStringArray(), (Rate) entry.getValue());
}
}
return rateMap;
}
/**
* Get all histograms
*
* @return [name, tags...] -> histogram
*/
protected Map<String[], Histogram> getAllHistograms() {
Map<String[], Histogram> histogramMap = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> entry : metrics.entrySet()) {
if (entry.getValue() instanceof Histogram) {
histogramMap.put(entry.getKey().toStringArray(), (Histogram) entry.getValue());
}
}
return histogramMap;
public Map<MetricInfo, IMetric> getAllMetrics() {
return metrics;
}
/**
* Get all timers
* Get metrics by type
*
* @return [name, tags...] -> timer
* @return [name, [tags...]] -> metric
*/
protected Map<String[], Timer> getAllTimers() {
Map<String[], Timer> timerMap = new HashMap<>();
public Map<MetricInfo, IMetric> getMetricsByType(MetricType metricType) {
Map<MetricInfo, IMetric> result = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> entry : metrics.entrySet()) {
if (entry.getValue() instanceof Timer) {
timerMap.put(entry.getKey().toStringArray(), (Timer) entry.getValue());
if (entry.getKey().getMetaInfo().getType() == metricType) {
result.put(entry.getKey(), entry.getValue());
}
}
return timerMap;
return result;
}
// endregion
......
......@@ -22,13 +22,14 @@ package org.apache.iotdb.metrics;
import org.apache.iotdb.metrics.config.MetricConfig;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.config.ReloadLevel;
import org.apache.iotdb.metrics.impl.DoNothingMetric;
import org.apache.iotdb.metrics.impl.DoNothingMetricManager;
import org.apache.iotdb.metrics.metricsets.IMetricSet;
import org.apache.iotdb.metrics.reporter.CompositeReporter;
import org.apache.iotdb.metrics.reporter.InternalReporter;
import org.apache.iotdb.metrics.reporter.MemoryInternalReporter;
import org.apache.iotdb.metrics.reporter.JmxReporter;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.reporter.iotdb.InternalIoTDBReporter;
import org.apache.iotdb.metrics.reporter.iotdb.MemoryInternalIoTDBReporter;
import org.apache.iotdb.metrics.reporter.iotdb.SessionIoTDBReporter;
import org.apache.iotdb.metrics.reporter.prometheus.PrometheusReporter;
import org.apache.iotdb.metrics.type.AutoGauge;
import org.apache.iotdb.metrics.type.Counter;
import org.apache.iotdb.metrics.type.Gauge;
......@@ -36,10 +37,11 @@ import org.apache.iotdb.metrics.type.Histogram;
import org.apache.iotdb.metrics.type.IMetric;
import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.MetricType;
import org.apache.iotdb.metrics.utils.ReporterType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.utils.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -62,7 +64,7 @@ public abstract class AbstractMetricService {
/** The metric reporter of metric service */
protected CompositeReporter compositeReporter = new CompositeReporter();
/** The internal reporter of metric service */
protected InternalReporter internalReporter = new MemoryInternalReporter();
protected InternalIoTDBReporter internalReporter = new MemoryInternalIoTDBReporter();
/** The list of metric sets */
protected List<IMetricSet> metricSets = new ArrayList<>();
......@@ -125,7 +127,7 @@ public abstract class AbstractMetricService {
if (size == 0 || metricManager == null) {
metricManager = new DoNothingMetricManager();
} else if (size > 1) {
logger.warn(
logger.info(
"Detect more than one MetricManager, will use {}", metricManager.getClass().getName());
}
}
......@@ -134,18 +136,39 @@ public abstract class AbstractMetricService {
protected void loadReporter() {
logger.info("Load metric reporters, type: {}", metricConfig.getMetricReporterList());
compositeReporter.clearReporter();
ServiceLoader<Reporter> reporters = ServiceLoader.load(Reporter.class);
for (Reporter reporter : reporters) {
if (metricConfig.getMetricReporterList() != null
&& metricConfig.getMetricReporterList().contains(reporter.getReporterType())
&& reporter
.getClass()
.getName()
.toLowerCase()
.contains(metricConfig.getMetricFrameType().name().toLowerCase())) {
reporter.setMetricManager(metricManager);
compositeReporter.addReporter(reporter);
if (metricConfig.getMetricReporterList() == null) {
return;
}
for (ReporterType reporterType : metricConfig.getMetricReporterList()) {
Reporter reporter = null;
switch (reporterType) {
case JMX:
ServiceLoader<JmxReporter> reporters = ServiceLoader.load(JmxReporter.class);
for (JmxReporter jmxReporter : reporters) {
if (jmxReporter
.getClass()
.getName()
.toLowerCase()
.contains(metricConfig.getMetricFrameType().name().toLowerCase())) {
jmxReporter.setMetricManager(metricManager);
reporter = jmxReporter;
}
}
break;
case PROMETHEUS:
reporter = new PrometheusReporter(metricManager);
break;
case IOTDB:
reporter = new SessionIoTDBReporter(metricManager);
break;
default:
continue;
}
if (reporter == null) {
logger.error("Failed to load reporter which type is {}", reporterType);
continue;
}
compositeReporter.addReporter(reporter);
}
}
......@@ -154,7 +177,7 @@ public abstract class AbstractMetricService {
*
* @param internalReporter the new internal reporter
*/
public abstract void reloadInternalReporter(InternalReporter internalReporter);
public abstract void reloadInternalReporter(InternalIoTDBReporter internalReporter);
/**
* Reload metric service
......@@ -243,7 +266,7 @@ public abstract class AbstractMetricService {
public Counter getOrCreateCounterWithInternalReport(
String metric, MetricLevel metricLevel, String... tags) {
Counter counter = metricManager.getOrCreateCounter(metric, metricLevel, tags);
report(counter, metric, tags);
internalReporter.writeMetricToIoTDB(counter, metric, tags);
return counter;
}
......@@ -251,7 +274,7 @@ public abstract class AbstractMetricService {
public <T> AutoGauge createAutoGaugeWithInternalReport(
String metric, MetricLevel metricLevel, T obj, ToLongFunction<T> mapper, String... tags) {
AutoGauge gauge = metricManager.createAutoGauge(metric, metricLevel, obj, mapper, tags);
report(gauge, metric, tags);
internalReporter.addAutoGauge(gauge, metric, tags);
return gauge;
}
......@@ -259,7 +282,7 @@ public abstract class AbstractMetricService {
public Gauge getOrCreateGaugeWithInternalReport(
String metric, MetricLevel metricLevel, String... tags) {
Gauge gauge = metricManager.getOrCreateGauge(metric, metricLevel, tags);
report(gauge, metric, tags);
internalReporter.writeMetricToIoTDB(gauge, metric, tags);
return gauge;
}
......@@ -267,7 +290,7 @@ public abstract class AbstractMetricService {
public Rate getOrCreateRateWithInternalReport(
String metric, MetricLevel metricLevel, String... tags) {
Rate rate = metricManager.getOrCreateRate(metric, metricLevel, tags);
report(rate, metric, tags);
internalReporter.writeMetricToIoTDB(rate, metric, tags);
return rate;
}
......@@ -275,7 +298,7 @@ public abstract class AbstractMetricService {
public Histogram getOrCreateHistogramWithInternalReport(
String metric, MetricLevel metricLevel, String... tags) {
Histogram histogram = metricManager.getOrCreateHistogram(metric, metricLevel, tags);
report(histogram, metric, tags);
internalReporter.writeMetricToIoTDB(histogram, metric, tags);
return histogram;
}
......@@ -283,105 +306,55 @@ public abstract class AbstractMetricService {
public Timer getOrCreateTimerWithInternalReport(
String metric, MetricLevel metricLevel, String... tags) {
Timer timer = metricManager.getOrCreateTimer(metric, metricLevel, tags);
report(timer, metric, tags);
internalReporter.writeMetricToIoTDB(timer, metric, tags);
return timer;
}
/** Count with internal report */
public void countWithInternalReport(
long delta, String metric, MetricLevel metricLevel, String... tags) {
report(metricManager.count(delta, metric, metricLevel, tags), metric, tags);
internalReporter.writeMetricToIoTDB(
metricManager.count(delta, metric, metricLevel, tags), metric, tags);
}
/** Gauge value with internal report */
public void gaugeWithInternalReport(
long value, String metric, MetricLevel metricLevel, String... tags) {
report(metricManager.gauge(value, metric, metricLevel, tags), metric, tags);
internalReporter.writeMetricToIoTDB(
metricManager.gauge(value, metric, metricLevel, tags), metric, tags);
}
/** Rate with internal report */
public void rateWithInternalReport(
long value, String metric, MetricLevel metricLevel, String... tags) {
report(metricManager.rate(value, metric, metricLevel, tags), metric, tags);
internalReporter.writeMetricToIoTDB(
metricManager.rate(value, metric, metricLevel, tags), metric, tags);
}
/** Histogram with internal report */
public void histogramWithInternalReport(
long value, String metric, MetricLevel metricLevel, String... tags) {
report(metricManager.histogram(value, metric, metricLevel, tags), metric, tags);
internalReporter.writeMetricToIoTDB(
metricManager.histogram(value, metric, metricLevel, tags), metric, tags);
}
/** Timer with internal report */
public void timerWithInternalReport(
long delta, TimeUnit timeUnit, String metric, MetricLevel metricLevel, String... tags) {
report(metricManager.timer(delta, timeUnit, metric, metricLevel, tags), metric, tags);
internalReporter.writeMetricToIoTDB(
metricManager.timer(delta, timeUnit, metric, metricLevel, tags), metric, tags);
}
/**
* Reporter metric internally
*
* @param metric the metric that need to report
* @param name the name of metric
* @param tags the tags of metric
*/
protected void report(IMetric metric, String name, String... tags) {
if (metric instanceof DoNothingMetric) {
return;
}
if (metric instanceof Counter) {
Counter counter = (Counter) metric;
internalReporter.updateValue(name, counter.count(), TSDataType.INT64, tags);
} else if (metric instanceof AutoGauge) {
internalReporter.addAutoGauge((AutoGauge) metric, name, tags);
} else if (metric instanceof Gauge) {
internalReporter.updateValue(name, ((Gauge) metric).value(), TSDataType.INT64, tags);
} else if (metric instanceof Rate) {
Rate rate = (Rate) metric;
Long time = System.currentTimeMillis();
internalReporter.updateValue(name + "_count", rate.getCount(), TSDataType.INT64, time, tags);
internalReporter.updateValue(
name + "_mean", rate.getMeanRate(), TSDataType.DOUBLE, time, tags);
internalReporter.updateValue(
name + "_1min", rate.getOneMinuteRate(), TSDataType.DOUBLE, time, tags);
internalReporter.updateValue(
name + "_5min", rate.getFiveMinuteRate(), TSDataType.DOUBLE, time, tags);
internalReporter.updateValue(
name + "_15min", rate.getFifteenMinuteRate(), TSDataType.DOUBLE, time, tags);
} else if (metric instanceof Histogram) {
Histogram histogram = (Histogram) metric;
internalReporter.writeSnapshotAndCount(name, histogram.takeSnapshot(), tags);
} else if (metric instanceof Timer) {
Timer timer = (Timer) metric;
internalReporter.writeSnapshotAndCount(name, timer.takeSnapshot(), tags);
}
}
public List<String[]> getAllMetricKeys() {
public List<Pair<String, String[]>> getAllMetricKeys() {
return metricManager.getAllMetricKeys();
}
public Map<String[], Counter> getAllCounters() {
return metricManager.getAllCounters();
}
public Map<String[], Gauge> getAllGauges() {
return metricManager.getAllGauges();
}
public Map<String[], AutoGauge> getAllAutoGauges() {
return metricManager.getAllAutoGauges();
}
public Map<String[], Rate> getAllRates() {
return metricManager.getAllRates();
}
public Map<String[], Histogram> getAllHistograms() {
return metricManager.getAllHistograms();
public Map<MetricInfo, IMetric> getAllMetrics() {
return metricManager.getAllMetrics();
}
public Map<String[], Timer> getAllTimers() {
return metricManager.getAllTimers();
public Map<MetricInfo, IMetric> getMetricsByType(MetricType metricType) {
return metricManager.getMetricsByType(metricType);
}
public void remove(MetricType type, String metric, String... tags) {
......
......@@ -17,8 +17,9 @@
* under the License.
*/
package org.apache.iotdb.metrics.reporter;
package org.apache.iotdb.metrics;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.utils.ReporterType;
import org.slf4j.Logger;
......
......@@ -20,12 +20,12 @@
package org.apache.iotdb.metrics;
import org.apache.iotdb.metrics.config.ReloadLevel;
import org.apache.iotdb.metrics.reporter.InternalReporter;
import org.apache.iotdb.metrics.reporter.iotdb.InternalIoTDBReporter;
public class DoNothingMetricService extends AbstractMetricService {
@Override
public void reloadInternalReporter(InternalReporter internalReporter) {
public void reloadInternalReporter(InternalIoTDBReporter internalReporter) {
// do nothing
}
......
......@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.impl;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
import java.io.OutputStream;
public class DoNothingHistogramSnapshot implements HistogramSnapshot, DoNothingMetric {
@Override
public double getValue(double quantile) {
......@@ -58,9 +56,4 @@ public class DoNothingHistogramSnapshot implements HistogramSnapshot, DoNothingM
public long getMin() {
return 0;
}
@Override
public void dump(OutputStream output) {
// do nothing
}
}
......@@ -46,7 +46,7 @@ public class JvmClassLoaderMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(MetricType.GAUGE, "jvm.classes.loaded.classes");
metricService.remove(MetricType.GAUGE, "jvm.classes.unloaded.classes");
metricService.remove(MetricType.AUTO_GAUGE, "jvm.classes.loaded.classes");
metricService.remove(MetricType.AUTO_GAUGE, "jvm.classes.unloaded.classes");
}
}
......@@ -48,7 +48,7 @@ public class JvmCompileMetrics implements IMetricSet {
CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean();
if (compilationBean != null && compilationBean.isCompilationTimeMonitoringSupported()) {
metricService.remove(
MetricType.GAUGE, "jvm.compilation.time.ms", "compiler", compilationBean.getName());
MetricType.AUTO_GAUGE, "jvm.compilation.time.ms", "compiler", compilationBean.getName());
}
}
}
......@@ -204,8 +204,8 @@ public class JvmGcMetrics implements IMetricSet, AutoCloseable {
return;
}
metricService.remove(MetricType.GAUGE, "jvm.gc.max.data.size.bytes");
metricService.remove(MetricType.GAUGE, "jvm.gc.live.data.size.bytes");
metricService.remove(MetricType.AUTO_GAUGE, "jvm.gc.max.data.size.bytes");
metricService.remove(MetricType.AUTO_GAUGE, "jvm.gc.live.data.size.bytes");
metricService.remove(MetricType.COUNTER, "jvm.gc.memory.allocated.bytes");
if (oldGenPoolName != null) {
......
......@@ -102,13 +102,13 @@ public class JvmMemoryMetrics implements IMetricSet {
for (BufferPoolMXBean bufferPoolBean :
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
metricService.remove(
MetricType.GAUGE, "jvm.buffer.count.buffers", "id", bufferPoolBean.getName());
MetricType.AUTO_GAUGE, "jvm.buffer.count.buffers", "id", bufferPoolBean.getName());
metricService.remove(
MetricType.GAUGE, "jvm.buffer.memory.used.bytes", "id", bufferPoolBean.getName());
MetricType.AUTO_GAUGE, "jvm.buffer.memory.used.bytes", "id", bufferPoolBean.getName());
metricService.remove(
MetricType.GAUGE, "jvm.buffer.total.capacity.bytes", "id", bufferPoolBean.getName());
MetricType.AUTO_GAUGE, "jvm.buffer.total.capacity.bytes", "id", bufferPoolBean.getName());
}
for (MemoryPoolMXBean memoryPoolBean :
......@@ -116,10 +116,15 @@ public class JvmMemoryMetrics implements IMetricSet {
String area = MemoryType.HEAP.equals(memoryPoolBean.getType()) ? "heap" : "nonheap";
metricService.remove(
MetricType.GAUGE, "jvm.memory.used.bytes", "id", memoryPoolBean.getName(), "area", area);
MetricType.AUTO_GAUGE,
"jvm.memory.used.bytes",
"id",
memoryPoolBean.getName(),
"area",
area);
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
"jvm.memory.committed.bytes",
"id",
memoryPoolBean.getName(),
......@@ -127,7 +132,12 @@ public class JvmMemoryMetrics implements IMetricSet {
area);
metricService.remove(
MetricType.GAUGE, "jvm.memory.max.bytes", "id", memoryPoolBean.getName(), "area", area);
MetricType.AUTO_GAUGE,
"jvm.memory.max.bytes",
"id",
memoryPoolBean.getName(),
"area",
area);
}
}
}
......@@ -73,15 +73,15 @@ public class JvmThreadMetrics implements IMetricSet {
public void unbindFrom(AbstractMetricService metricService) {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
metricService.remove(MetricType.GAUGE, "jvm.threads.peak.threads");
metricService.remove(MetricType.GAUGE, "jvm.threads.daemon.threads");
metricService.remove(MetricType.GAUGE, "jvm.threads.live.threads");
metricService.remove(MetricType.AUTO_GAUGE, "jvm.threads.peak.threads");
metricService.remove(MetricType.AUTO_GAUGE, "jvm.threads.daemon.threads");
metricService.remove(MetricType.AUTO_GAUGE, "jvm.threads.live.threads");
try {
threadBean.getAllThreadIds();
for (Thread.State state : Thread.State.values()) {
metricService.remove(
MetricType.GAUGE, "jvm.threads.states.threads", "state", getStateTagValue(state));
MetricType.AUTO_GAUGE, "jvm.threads.states.threads", "state", getStateTagValue(state));
}
} catch (Error error) {
// An error will be thrown for unsupported operations
......
......@@ -7,7 +7,7 @@
* "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
* 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
......@@ -17,22 +17,11 @@
* under the License.
*/
package org.apache.iotdb.metrics.dropwizard.reporter;
package org.apache.iotdb.metrics.reporter;
public enum DropwizardMetricType {
COUNTER("counter"),
GAUGE("gauge"),
SUMMARY("summary"),
HISTOGRAM("histogram"),
UNTYPED("untyped");
import org.apache.iotdb.metrics.AbstractMetricManager;
private final String text;
DropwizardMetricType(String text) {
this.text = text;
}
public String getText() {
return text;
}
public interface JmxReporter extends Reporter {
/** Set metric manager into reporter */
void setMetricManager(AbstractMetricManager metricManager);
}
......@@ -19,7 +19,6 @@
package org.apache.iotdb.metrics.reporter;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.utils.ReporterType;
public interface Reporter {
......@@ -31,7 +30,4 @@ public interface Reporter {
/** Get the type of reporter */
ReporterType getReporterType();
/** Set metric manager into reporter */
void setMetricManager(AbstractMetricManager metricManager);
}
......@@ -17,19 +17,19 @@
* under the License.
*/
package org.apache.iotdb.metrics.reporter;
package org.apache.iotdb.metrics.reporter.iotdb;
import org.apache.iotdb.metrics.type.AutoGauge;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
import org.apache.iotdb.metrics.type.IMetric;
import org.apache.iotdb.metrics.utils.InternalReporterType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.utils.Pair;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.MetricType;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class InternalReporter {
protected final Map<Pair<String, String[]>, AutoGauge> autoGauges = new ConcurrentHashMap<>();
public abstract class InternalIoTDBReporter extends IoTDBReporter {
protected final Map<MetricInfo, IMetric> autoGauges = new ConcurrentHashMap<>();
/**
* Add autoGauge into internal reporter
......@@ -39,7 +39,8 @@ public abstract class InternalReporter {
* @param tags the tags of autoGauge
*/
public void addAutoGauge(AutoGauge autoGauge, String name, String... tags) {
autoGauges.put(new Pair<>(name, tags), autoGauge);
MetricInfo metricInfo = new MetricInfo(MetricType.AUTO_GAUGE, name, tags);
autoGauges.put(metricInfo, autoGauge);
}
/**
......@@ -47,12 +48,12 @@ public abstract class InternalReporter {
*
* @param gauges the map of autoGauge
*/
public void addAutoGauge(Map<Pair<String, String[]>, AutoGauge> gauges) {
public void addAutoGauge(Map<MetricInfo, IMetric> gauges) {
autoGauges.putAll(gauges);
}
/** Get all autoGauges */
public Map<Pair<String, String[]>, AutoGauge> getAllAutoGauge() {
public Map<MetricInfo, IMetric> getAllAutoGauge() {
return autoGauges;
}
......@@ -61,44 +62,6 @@ public abstract class InternalReporter {
autoGauges.clear();
}
/**
* Update value of metric without specific time
*
* @param name the name of metric
* @param value the value of metric
* @param type the type of value
* @param tags the tags of metric
*/
public abstract void updateValue(String name, Object value, TSDataType type, String... tags);
/**
* Update value of metric with specific time
*
* @param name the name of metric
* @param value the value of metric
* @param type the type of value
* @param time the time of value
* @param tags the tags of metric
*/
public abstract void updateValue(
String name, Object value, TSDataType type, Long time, String... tags);
/**
* Update the value of HistogramSnapshot
*
* @param name the name of metric
* @param snapshot the snapshot of metric
* @param tags the tags of metric
*/
public abstract void writeSnapshotAndCount(
String name, HistogramSnapshot snapshot, String... tags);
/** Get the type of internal reporter */
public abstract InternalReporterType getType();
/** Start internal reporter */
public abstract void start();
/** Stop internal reporter */
public abstract void stop();
}
/*
* 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.reporter.iotdb;
import org.apache.iotdb.metrics.impl.DoNothingMetric;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.type.IMetric;
import org.apache.iotdb.metrics.utils.IoTDBMetricsUtils;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import java.util.HashMap;
import java.util.Map;
/** The reporter to IoTDB */
public abstract class IoTDBReporter implements Reporter {
/**
* Write metric into IoTDB
*
* @param metric the target metric
* @param name the name of metric
* @param tags the tags of metric
*/
public void writeMetricToIoTDB(IMetric metric, String name, String... tags) {
if (!(metric instanceof DoNothingMetric)) {
Map<String, Object> values = new HashMap<>();
metric.constructValueMap(values);
writeMetricToIoTDB(
values, IoTDBMetricsUtils.generatePath(name, tags), System.currentTimeMillis());
}
}
/**
* Write metric into IoTDB
*
* @param valueMap sensor -> value
* @param prefix device
* @param time write time
*/
protected abstract void writeMetricToIoTDB(
Map<String, Object> valueMap, String prefix, long time);
/**
* Write metrics into IoTDB
*
* @param metricMap metricInfo -> IMetric
*/
public void writeMetricToIoTDB(Map<MetricInfo, IMetric> metricMap) {
Map<String, Map<String, Object>> values = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> metricEntry : metricMap.entrySet()) {
String prefix = IoTDBMetricsUtils.generatePath(metricEntry.getKey());
IMetric metric = metricEntry.getValue();
if (!(metric instanceof DoNothingMetric)) {
Map<String, Object> value = new HashMap<>();
metric.constructValueMap(value);
values.put(prefix, value);
}
}
writeMetricsToIoTDB(values, System.currentTimeMillis());
}
/**
* Write metrics into IoTDB
*
* @param valueMap device -> sensor -> value
* @param time write time
*/
protected abstract void writeMetricsToIoTDB(Map<String, Map<String, Object>> valueMap, long time);
/** Infer type from object */
protected TSDataType inferType(Object value) {
TSDataType dataType;
if (value instanceof Boolean) {
dataType = TSDataType.BOOLEAN;
} else if (value instanceof Integer) {
dataType = TSDataType.INT32;
} else if (value instanceof Long) {
dataType = TSDataType.INT64;
} else if (value instanceof Double) {
dataType = TSDataType.DOUBLE;
} else {
dataType = TSDataType.TEXT;
}
return dataType;
}
}
......@@ -17,41 +17,41 @@
* under the License.
*/
package org.apache.iotdb.metrics.reporter;
package org.apache.iotdb.metrics.reporter.iotdb;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
import org.apache.iotdb.metrics.utils.InternalReporterType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.metrics.utils.ReporterType;
public class MemoryInternalReporter extends InternalReporter {
import java.util.Map;
public class MemoryInternalIoTDBReporter extends InternalIoTDBReporter {
@Override
public void updateValue(String name, Object value, TSDataType type, String... tags) {
// do nothing
public InternalReporterType getType() {
return InternalReporterType.MEMORY;
}
@Override
public void updateValue(String name, Object value, TSDataType type, Long time, String... tags) {
protected void writeMetricToIoTDB(Map<String, Object> valueMap, String prefix, long time) {
// do nothing
}
@Override
public void writeSnapshotAndCount(String name, HistogramSnapshot snapshot, String... tags) {
protected void writeMetricsToIoTDB(Map<String, Map<String, Object>> valueMap, long time) {
// do nothing
}
@Override
public InternalReporterType getType() {
return InternalReporterType.MEMORY;
public boolean start() {
return false;
}
@Override
public void start() {
// do nothing
public boolean stop() {
return false;
}
@Override
public void stop() {
clear();
public ReporterType getReporterType() {
return ReporterType.IOTDB;
}
}
/*
* 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.reporter.iotdb;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.config.MetricConfig;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.type.IMetric;
import org.apache.iotdb.metrics.utils.IoTDBMetricsUtils;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.ReporterType;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionDataSetWrapper;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class SessionIoTDBReporter extends IoTDBReporter {
private static final Logger LOGGER = LoggerFactory.getLogger(SessionIoTDBReporter.class);
private static final MetricConfig.IoTDBReporterConfig ioTDBReporterConfig =
MetricConfigDescriptor.getInstance().getMetricConfig().getIoTDBReporterConfig();
private Future<?> currentServiceFuture;
private final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
/** The manager of metrics */
protected AbstractMetricManager metricManager;
/** The session pool to write metrics */
protected SessionPool sessionPool;
public SessionIoTDBReporter(AbstractMetricManager metricManager) {
this.metricManager = metricManager;
this.sessionPool =
new SessionPool(
ioTDBReporterConfig.getHost(),
ioTDBReporterConfig.getPort(),
ioTDBReporterConfig.getUsername(),
ioTDBReporterConfig.getPassword(),
ioTDBReporterConfig.getMaxConnectionNumber());
try (SessionDataSetWrapper result =
this.sessionPool.executeQueryStatement("SHOW DATABASES " + IoTDBMetricsUtils.DATABASE)) {
if (!result.hasNext()) {
this.sessionPool.createDatabase(IoTDBMetricsUtils.DATABASE);
}
} catch (IoTDBConnectionException e) {
LOGGER.error("CheckOrCreateStorageGroup failed because ", e);
} catch (StatementExecutionException e) {
// do nothing
}
}
@Override
@SuppressWarnings("unsafeThreadSchedule")
public boolean start() {
if (currentServiceFuture == null) {
currentServiceFuture =
service.scheduleAtFixedRate(
() -> {
try {
Map<String, Map<String, Object>> values = new HashMap<>();
for (Map.Entry<MetricInfo, IMetric> metricEntry :
metricManager.getAllMetrics().entrySet()) {
String prefix = IoTDBMetricsUtils.generatePath(metricEntry.getKey());
Map<String, Object> value = new HashMap<>();
metricEntry.getValue().constructValueMap(value);
values.put(prefix, value);
}
writeMetricsToIoTDB(values, System.currentTimeMillis());
} catch (Throwable t) {
LOGGER.error("Schedule task failed", t);
}
},
1,
MetricConfigDescriptor.getInstance()
.getMetricConfig()
.getAsyncCollectPeriodInSecond(),
TimeUnit.SECONDS);
}
return true;
}
@Override
public boolean stop() {
if (currentServiceFuture != null) {
currentServiceFuture.cancel(true);
currentServiceFuture = null;
}
if (sessionPool != null) {
sessionPool.close();
}
return true;
}
@Override
public ReporterType getReporterType() {
return ReporterType.IOTDB;
}
@Override
protected void writeMetricToIoTDB(Map<String, Object> valueMap, String prefix, long time) {
List<String> sensors = new ArrayList<>();
List<TSDataType> dataTypes = new ArrayList<>();
List<Object> values = new ArrayList<>();
for (Map.Entry<String, Object> sensor : valueMap.entrySet()) {
sensors.add(sensor.getKey());
dataTypes.add(inferType(sensor.getValue()));
values.add(sensor.getValue());
}
try {
sessionPool.insertRecord(prefix, time, sensors, dataTypes, values);
} catch (IoTDBConnectionException | StatementExecutionException e) {
LOGGER.warn("Failed to insert record");
}
}
@Override
protected void writeMetricsToIoTDB(Map<String, Map<String, Object>> valueMap, long time) {
List<String> deviceIds = new ArrayList<>();
List<Long> times = new ArrayList<>();
List<List<String>> sensors = new ArrayList<>();
List<List<TSDataType>> dataTypes = new ArrayList<>();
List<List<Object>> values = new ArrayList<>();
for (Map.Entry<String, Map<String, Object>> metric : valueMap.entrySet()) {
deviceIds.add(metric.getKey());
times.add(time);
List<String> metricSensors = new ArrayList<>();
List<TSDataType> metricDataTypes = new ArrayList<>();
List<Object> metricValues = new ArrayList<>();
for (Map.Entry<String, Object> sensor : metric.getValue().entrySet()) {
metricSensors.add(sensor.getKey());
metricDataTypes.add(inferType(sensor.getValue()));
metricValues.add(sensor.getValue());
}
sensors.add(metricSensors);
dataTypes.add(metricDataTypes);
values.add(metricValues);
}
try {
sessionPool.insertRecords(deviceIds, times, sensors, dataTypes, values);
} catch (IoTDBConnectionException | StatementExecutionException e) {
LOGGER.warn("Failed to insert record");
}
}
}
......@@ -7,7 +7,7 @@
* "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
* 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
......@@ -17,15 +17,24 @@
* under the License.
*/
package org.apache.iotdb.metrics.dropwizard.reporter;
package org.apache.iotdb.metrics.reporter.prometheus;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.config.MetricConfig;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.dropwizard.DropwizardMetricManager;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.type.AutoGauge;
import org.apache.iotdb.metrics.type.Counter;
import org.apache.iotdb.metrics.type.Gauge;
import org.apache.iotdb.metrics.type.Histogram;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
import org.apache.iotdb.metrics.type.IMetric;
import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import org.apache.iotdb.metrics.utils.MetricInfo;
import org.apache.iotdb.metrics.utils.MetricType;
import org.apache.iotdb.metrics.utils.ReporterType;
import com.codahale.metrics.MetricRegistry;
import io.netty.channel.ChannelOption;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
......@@ -39,45 +48,107 @@ import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class DropwizardPrometheusReporter implements Reporter {
private static final Logger LOGGER = LoggerFactory.getLogger(DropwizardPrometheusReporter.class);
public class PrometheusReporter implements Reporter {
private static final Logger LOGGER = LoggerFactory.getLogger(PrometheusReporter.class);
private static final MetricConfig metricConfig =
MetricConfigDescriptor.getInstance().getMetricConfig();
private AbstractMetricManager metricManager;
private DisposableServer httpServer;
private AbstractMetricManager dropwizardMetricManager = null;
private DisposableServer httpServer = null;
public PrometheusReporter(AbstractMetricManager metricManager) {
this.metricManager = metricManager;
}
@Override
public boolean start() {
if (httpServer != null) {
return false;
}
int port = MetricConfigDescriptor.getInstance().getMetricConfig().getPrometheusReporterPort();
httpServer =
HttpServer.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000)
.channelGroup(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE))
.port(port)
.port(metricConfig.getPrometheusReporterPort())
.route(
routes ->
routes.get(
"/metrics",
(request, response) -> response.sendString(Mono.just(scrape()))))
.bindNow();
LOGGER.info("http server for metrics started, listen on {}", port);
LOGGER.info(
"http server for metrics started, listen on {}", metricConfig.getPrometheusReporterPort());
return true;
}
private String scrape() {
MetricRegistry metricRegistry =
((DropwizardMetricManager) dropwizardMetricManager).getMetricRegistry();
Writer writer = new StringWriter();
PrometheusTextWriter prometheusTextWriter = new PrometheusTextWriter(writer);
DropwizardMetricsExporter dropwizardMetricsExporter =
new DropwizardMetricsExporter(metricRegistry, prometheusTextWriter);
String result = "";
String result;
try {
dropwizardMetricsExporter.scrape();
for (Map.Entry<MetricInfo, IMetric> metricEntry : metricManager.getAllMetrics().entrySet()) {
MetricInfo metricInfo = metricEntry.getKey();
IMetric metric = metricEntry.getValue();
String name = metricInfo.getName().replaceAll("[^a-zA-Z0-9:_\\]\\[]", "_");
MetricType metricType = metricInfo.getMetaInfo().getType();
if (metric instanceof Counter) {
name += "_total";
prometheusTextWriter.writeHelp(name);
prometheusTextWriter.writeType(name, metricInfo.getMetaInfo().getType());
Counter counter = (Counter) metric;
prometheusTextWriter.writeSample(name, metricInfo.getTags(), counter.count());
} else if (metric instanceof Gauge) {
prometheusTextWriter.writeHelp(name);
prometheusTextWriter.writeType(name, metricInfo.getMetaInfo().getType());
Gauge gauge = (Gauge) metric;
prometheusTextWriter.writeSample(name, metricInfo.getTags(), gauge.value());
} else if (metric instanceof AutoGauge) {
prometheusTextWriter.writeHelp(name);
prometheusTextWriter.writeType(name, metricInfo.getMetaInfo().getType());
AutoGauge gauge = (AutoGauge) metric;
prometheusTextWriter.writeSample(name, metricInfo.getTags(), gauge.value());
} else if (metric instanceof Histogram) {
Histogram histogram = (Histogram) metric;
HistogramSnapshot snapshot = histogram.takeSnapshot();
writeSnapshotAndCount(
name,
metricInfo.getTags(),
metricType,
snapshot,
histogram.count(),
prometheusTextWriter);
} else if (metric instanceof Rate) {
name += "_total";
prometheusTextWriter.writeHelp(name);
prometheusTextWriter.writeType(name, metricInfo.getMetaInfo().getType());
Rate rate = (Rate) metric;
prometheusTextWriter.writeSample(name, metricInfo.getTags(), rate.getCount());
prometheusTextWriter.writeSample(
name, addTags(metricInfo.getTags(), "rate", "m1"), rate.getOneMinuteRate());
prometheusTextWriter.writeSample(
name, addTags(metricInfo.getTags(), "rate", "m5"), rate.getFiveMinuteRate());
prometheusTextWriter.writeSample(
name, addTags(metricInfo.getTags(), "rate", "m15"), rate.getFifteenMinuteRate());
prometheusTextWriter.writeSample(
name, addTags(metricInfo.getTags(), "rate", "mean"), rate.getMeanRate());
} else if (metric instanceof Timer) {
Timer timer = (Timer) metric;
HistogramSnapshot snapshot = timer.takeSnapshot();
name += "_seconds";
writeSnapshotAndCount(
name,
metricInfo.getTags(),
metricType,
snapshot,
timer.getImmutableRate().getCount(),
prometheusTextWriter);
}
}
result = writer.toString();
} catch (IOException e) {
// This actually never happens since StringWriter::write() doesn't throw any IOException
......@@ -92,6 +163,44 @@ public class DropwizardPrometheusReporter implements Reporter {
return result;
}
private void writeSnapshotAndCount(
String name,
Map<String, String> tags,
MetricType type,
HistogramSnapshot snapshot,
long count,
PrometheusTextWriter prometheusTextWriter)
throws IOException {
prometheusTextWriter.writeHelp(name);
prometheusTextWriter.writeType(name, type);
prometheusTextWriter.writeSample(name + "_max", tags, snapshot.getMax());
prometheusTextWriter.writeSample(
name + "_sum", tags, Arrays.stream(snapshot.getValues()).sum());
prometheusTextWriter.writeSample(name + "_count", tags, count);
prometheusTextWriter.writeSample(
name, addTags(tags, "quantile", "0.0"), snapshot.getValue(0.0));
prometheusTextWriter.writeSample(
name, addTags(tags, "quantile", "0.25"), snapshot.getValue(0.25));
prometheusTextWriter.writeSample(
name, addTags(tags, "quantile", "0.5"), snapshot.getValue(0.5));
prometheusTextWriter.writeSample(
name, addTags(tags, "quantile", "0.75"), snapshot.getValue(0.75));
prometheusTextWriter.writeSample(
name, addTags(tags, "quantile", "1.0"), snapshot.getValue(1.0));
}
private Map<String, String> addTags(Map<String, String> tags, String key, String value) {
HashMap<String, String> result = new HashMap<>(tags);
result.put(key, value);
return result;
}
private static String getHelpMessage(String metric, MetricType type) {
return String.format(
"Generated from metric import (metric=%s, type=%s)", metric, type.toString());
}
@Override
public boolean stop() {
if (httpServer != null) {
......@@ -110,9 +219,4 @@ public class DropwizardPrometheusReporter implements Reporter {
public ReporterType getReporterType() {
return ReporterType.PROMETHEUS;
}
@Override
public void setMetricManager(AbstractMetricManager metricManager) {
this.dropwizardMetricManager = metricManager;
}
}
......@@ -17,7 +17,9 @@
* under the License.
*/
package org.apache.iotdb.metrics.dropwizard.reporter;
package org.apache.iotdb.metrics.reporter.prometheus;
import org.apache.iotdb.metrics.utils.MetricType;
import java.io.FilterWriter;
import java.io.IOException;
......@@ -30,23 +32,36 @@ class PrometheusTextWriter extends FilterWriter {
super(out);
}
public void writeHelp(String name, String value) throws IOException {
public void writeHelp(String name) throws IOException {
write("# HELP ");
write(name);
write(' ');
write(value);
write('\n');
}
public void writeType(String name, DropwizardMetricType type) throws IOException {
public void writeType(String name, MetricType type) throws IOException {
write("# TYPE ");
write(name);
write(' ');
write(type.getText());
switch (type) {
case GAUGE:
case AUTO_GAUGE:
write("gauge");
break;
case COUNTER:
case RATE:
write("counter");
break;
case TIMER:
case HISTOGRAM:
write("summary");
break;
default:
break;
}
write('\n');
}
public void writeSample(String name, Map<String, String> labels, double value)
public void writeSample(String name, Map<String, String> labels, Object value)
throws IOException {
write(name);
if (labels.size() > 0) {
......@@ -60,20 +75,7 @@ class PrometheusTextWriter extends FilterWriter {
write('}');
}
write(' ');
write(doubleToGoString(value));
write(value.toString());
write('\n');
}
private static String doubleToGoString(double d) {
if (d == Double.POSITIVE_INFINITY) {
return "+Inf";
}
if (d == Double.NEGATIVE_INFINITY) {
return "-Inf";
}
if (Double.isNaN(d)) {
return "NaN";
}
return Double.toString(d);
}
}
......@@ -19,7 +19,14 @@
package org.apache.iotdb.metrics.type;
import java.util.Map;
public interface AutoGauge extends IMetric {
/** get value according to the state of obj */
long value();
@Override
default void constructValueMap(Map<String, Object> result) {
result.put("value", value());
}
}
......@@ -19,6 +19,8 @@
package org.apache.iotdb.metrics.type;
import java.util.Map;
public interface Counter extends IMetric {
/** Counter add 1 */
......@@ -29,4 +31,9 @@ public interface Counter extends IMetric {
/** Get the value of counter */
long count();
@Override
default void constructValueMap(Map<String, Object> result) {
result.put("value", count());
}
}
......@@ -19,6 +19,8 @@
package org.apache.iotdb.metrics.type;
import java.util.Map;
public interface Gauge extends IMetric {
/** Set value */
......@@ -32,4 +34,9 @@ public interface Gauge extends IMetric {
/** Decrease the value stored in gauge */
void decr(long value);
@Override
default void constructValueMap(Map<String, Object> result) {
result.put("value", value());
}
}
......@@ -19,6 +19,8 @@
package org.apache.iotdb.metrics.type;
import java.util.Map;
public interface Histogram extends IMetric {
/** Update histogram by value */
......@@ -29,4 +31,10 @@ public interface Histogram extends IMetric {
/** Take snapshot of histogram */
HistogramSnapshot takeSnapshot();
@Override
default void constructValueMap(Map<String, Object> result) {
result.put("count", count());
takeSnapshot().constructValueMap(result);
}
}
......@@ -19,10 +19,11 @@
package org.apache.iotdb.metrics.type;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
/** Used by timer and histogram. */
public interface HistogramSnapshot {
public interface HistogramSnapshot extends IMetric {
/** Get value by quantile */
double getValue(double quantile);
......@@ -45,6 +46,15 @@ public interface HistogramSnapshot {
/** Get max value in values */
long getMax();
/** Writes the values of the snapshot to the given stream */
void dump(OutputStream output);
@Override
default void constructValueMap(Map<String, Object> result) {
result.put("max", getMax());
result.put("sum", Arrays.stream(getValues()).sum());
result.put("p0", getValue(0.0));
result.put("p25", getValue(0.25));
result.put("p50", getValue(0.5));
result.put("p75", getValue(0.75));
result.put("p100", getValue(1.0));
}
}
......@@ -19,4 +19,8 @@
package org.apache.iotdb.metrics.type;
public interface IMetric {}
import java.util.Map;
public interface IMetric {
void constructValueMap(Map<String, Object> result);
}
......@@ -19,6 +19,8 @@
package org.apache.iotdb.metrics.type;
import java.util.Map;
public interface Rate extends IMetric {
/** Get the value of rate */
......@@ -41,4 +43,13 @@ public interface Rate extends IMetric {
/** Mark n in rate */
void mark(long n);
@Override
default void constructValueMap(Map<String, Object> result) {
result.put("count", getCount());
result.put("mean", getMeanRate());
result.put("m1", getOneMinuteRate());
result.put("m5", getFiveMinuteRate());
result.put("m15", getFifteenMinuteRate());
}
}
......@@ -19,6 +19,7 @@
package org.apache.iotdb.metrics.type;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public interface Timer extends IMetric {
......@@ -46,4 +47,10 @@ public interface Timer extends IMetric {
/** It's not safe to use the update interface of this rate */
Rate getImmutableRate();
@Override
default void constructValueMap(Map<String, Object> result) {
takeSnapshot().constructValueMap(result);
getImmutableRate().constructValueMap(result);
}
}
......@@ -21,37 +21,22 @@ package org.apache.iotdb.metrics.utils;
import org.apache.iotdb.metrics.config.MetricConfig;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionDataSetWrapper;
import org.apache.iotdb.session.pool.SessionPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
public class IoTDBMetricsUtils {
private static final Logger logger = LoggerFactory.getLogger(IoTDBMetricsUtils.class);
private static final MetricConfig metricConfig =
MetricConfigDescriptor.getInstance().getMetricConfig();
private static final String STORAGE_GROUP = "root.__system";
public static final String DATABASE = "root.__system";
/** Generate the path of metric by metricInfo */
public static String generatePath(MetricInfo metricInfo) {
return generatePath(metricInfo.getName(), metricInfo.getTags());
}
/** Generate the path of metric with tags array */
public static String generatePath(String name, String... tags) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(STORAGE_GROUP)
.append(".")
.append(metricConfig.getIoTDBReporterConfig().getLocation())
.append(".`")
.append(metricConfig.getRpcAddress())
.append(":")
.append(metricConfig.getRpcPort())
.append("`")
.append(".")
.append("`")
.append(name)
.append("`");
StringBuilder stringBuilder = generateMetric(name);
for (int i = 0; i < tags.length; i += 2) {
stringBuilder
.append(".")
......@@ -64,10 +49,26 @@ public class IoTDBMetricsUtils {
return stringBuilder.toString();
}
public static String generatePath(String name, Map<String, String> labels) {
/** Generate the path of metric with tags map */
public static String generatePath(String name, Map<String, String> tags) {
StringBuilder stringBuilder = generateMetric(name);
for (Map.Entry<String, String> entry : tags.entrySet()) {
stringBuilder
.append(".")
.append("`")
.append(entry.getKey())
.append("=")
.append(entry.getValue())
.append("`");
}
return stringBuilder.toString();
}
/** Generate the path of metric */
private static StringBuilder generateMetric(String name) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(STORAGE_GROUP)
.append(DATABASE)
.append(".")
.append(metricConfig.getIoTDBReporterConfig().getLocation())
.append(".`")
......@@ -79,28 +80,6 @@ public class IoTDBMetricsUtils {
.append("`")
.append(name)
.append("`");
for (Map.Entry<String, String> entry : labels.entrySet()) {
stringBuilder
.append(".")
.append("`")
.append(entry.getKey())
.append("=")
.append(entry.getValue())
.append("`");
}
return stringBuilder.toString();
}
public static void checkOrCreateStorageGroup(SessionPool session) {
try (SessionDataSetWrapper result =
session.executeQueryStatement("SHOW DATABASES " + STORAGE_GROUP)) {
if (!result.hasNext()) {
session.setStorageGroup(STORAGE_GROUP);
}
} catch (IoTDBConnectionException e) {
logger.error("CheckOrCreateStorageGroup failed because ", e);
} catch (StatementExecutionException e) {
// do nothing
}
return stringBuilder;
}
}
......@@ -19,6 +19,8 @@
package org.apache.iotdb.metrics.utils;
import org.apache.iotdb.tsfile.utils.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -74,16 +76,15 @@ public class MetricInfo {
return metaInfo;
}
/** Convert the metric name to string array. */
public String[] toStringArray() {
/** Convert the metric name and tag into pair */
public Pair<String, String[]> toStringArray() {
List<String> allNames = new ArrayList<>();
allNames.add(name);
tags.forEach(
(k, v) -> {
allNames.add(k);
allNames.add(v);
});
return allNames.toArray(new String[0]);
return new Pair<>(name, allNames.toArray(new String[0]));
}
@Override
......
......@@ -21,6 +21,7 @@ package org.apache.iotdb.metrics.utils;
public enum MetricType {
COUNTER,
AUTO_GAUGE,
GAUGE,
RATE,
HISTOGRAM,
......
......@@ -117,6 +117,7 @@ public class MicrometerMetricManager extends AbstractMetricManager {
switch (type) {
case COUNTER:
return Meter.Type.COUNTER;
case AUTO_GAUGE:
case GAUGE:
case RATE:
return Meter.Type.GAUGE;
......
/*
* 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.micrometer.reporter;
import org.apache.iotdb.metrics.config.MetricConfig;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.utils.IoTDBMetricsUtils;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.distribution.HistogramSnapshot;
import io.micrometer.core.instrument.step.StepMeterRegistry;
import io.micrometer.core.instrument.step.StepRegistryConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class IoTDBMeterRegistry extends StepMeterRegistry {
private static final Logger logger = LoggerFactory.getLogger(IoTDBMeterRegistry.class);
private static final MetricConfig.IoTDBReporterConfig ioTDBReporterConfig =
MetricConfigDescriptor.getInstance().getMetricConfig().getIoTDBReporterConfig();
private final SessionPool sessionPool;
public IoTDBMeterRegistry(StepRegistryConfig config, Clock clock) {
super(config, clock);
this.sessionPool =
new SessionPool(
ioTDBReporterConfig.getHost(),
ioTDBReporterConfig.getPort(),
ioTDBReporterConfig.getUsername(),
ioTDBReporterConfig.getPassword(),
ioTDBReporterConfig.getMaxConnectionNumber());
IoTDBMetricsUtils.checkOrCreateStorageGroup(sessionPool);
}
@Override
public void stop() {
super.stop();
if (sessionPool != null) {
sessionPool.close();
}
}
@Override
protected void publish() {
Long time = System.currentTimeMillis();
getMeters()
.forEach(
meter -> {
if (null != meter) {
Meter.Id id = meter.getId();
String name = id.getName();
List<Tag> tags = id.getTags();
Map<String, String> labels = tagsConvertToMap(tags);
meter.use(
gauge -> {
updateValue(name, labels, gauge.value(), time);
},
counter -> {
updateValue(name, labels, counter.count(), time);
},
timer -> {
writeSnapshotAndCount(name, labels, timer.takeSnapshot(), time);
},
summary -> {
writeSnapshotAndCount(name, labels, summary.takeSnapshot(), time);
},
longTaskTimer -> {
updateValue(name, labels, (double) longTaskTimer.activeTasks(), time);
},
timeGauge -> {
updateValue(name, labels, timeGauge.value(getBaseTimeUnit()), time);
},
functionCounter -> {
updateValue(name, labels, functionCounter.count(), time);
},
functionTimer -> {
updateValue(name, labels, functionTimer.count(), time);
},
m -> {
logger.debug("unknown meter:" + meter);
});
}
});
}
private void writeSnapshotAndCount(
String name, Map<String, String> labels, HistogramSnapshot snapshot, Long time) {
updateValue(name + "_max", labels, snapshot.max(), time);
updateValue(name + "_mean", labels, snapshot.mean(), time);
updateValue(name + "_total", labels, snapshot.total(), time);
updateValue(name + "_count", labels, (double) snapshot.count(), time);
}
private Map<String, String> tagsConvertToMap(List<Tag> tags) {
Map<String, String> labels = new HashMap<>();
for (Tag tag : tags) {
labels.put(tag.getKey(), tag.getValue());
}
return labels;
}
private void updateValue(String name, Map<String, String> labels, Double value, Long time) {
if (value != null) {
String deviceId = IoTDBMetricsUtils.generatePath(name, labels);
List<String> sensors = Collections.singletonList("value");
List<TSDataType> dataTypes = Collections.singletonList(TSDataType.DOUBLE);
List<Object> values = Collections.singletonList(value);
try {
sessionPool.insertRecord(deviceId, time, sensors, dataTypes, values);
} catch (IoTDBConnectionException | StatementExecutionException e) {
logger.warn("Failed to insert record");
}
}
}
@Override
protected TimeUnit getBaseTimeUnit() {
return TimeUnit.MILLISECONDS;
}
}
/*
* 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.micrometer.reporter;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import io.micrometer.core.instrument.step.StepRegistryConfig;
import java.time.Duration;
public interface IoTDBRegistryConfig extends StepRegistryConfig {
IoTDBRegistryConfig DEFAULT =
new IoTDBRegistryConfig() {
@Override
public String get(String key) {
return null;
}
@Override
public Duration step() {
return Duration.ofSeconds(
MetricConfigDescriptor.getInstance()
.getMetricConfig()
.getIoTDBReporterConfig()
.getPushPeriodInSecond());
}
};
@Override
default String prefix() {
return "iotdb";
}
}
/*
* 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.micrometer.reporter;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.utils.ReporterType;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.util.NamedThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.stream.Collectors;
public class MicrometerIoTDBReporter implements Reporter {
private static final Logger LOGGER = LoggerFactory.getLogger(MicrometerIoTDBReporter.class);
private AbstractMetricManager metricManager;
@Override
public boolean start() {
try {
Set<MeterRegistry> meterRegistrySet =
Metrics.globalRegistry.getRegistries().stream()
.filter(reporter -> reporter instanceof IoTDBMeterRegistry)
.collect(Collectors.toSet());
IoTDBMeterRegistry ioTDBMeterRegistry;
if (meterRegistrySet.size() == 0) {
ioTDBMeterRegistry = new IoTDBMeterRegistry(IoTDBRegistryConfig.DEFAULT, Clock.SYSTEM);
Metrics.addRegistry(ioTDBMeterRegistry);
} else {
ioTDBMeterRegistry = (IoTDBMeterRegistry) meterRegistrySet.toArray()[0];
}
ioTDBMeterRegistry.start(new NamedThreadFactory("iotdb-metrics-publisher"));
} catch (Exception e) {
LOGGER.error("Failed to start Micrometer IoTDBReporter, because {}", e.getMessage());
return false;
}
return true;
}
@Override
public boolean stop() {
try {
Set<MeterRegistry> meterRegistrySet =
Metrics.globalRegistry.getRegistries().stream()
.filter(reporter -> reporter instanceof IoTDBMeterRegistry)
.collect(Collectors.toSet());
for (MeterRegistry meterRegistry : meterRegistrySet) {
if (!meterRegistry.isClosed()) {
meterRegistry.close();
Metrics.removeRegistry(meterRegistry);
}
}
} catch (Exception e) {
LOGGER.error("Failed to stop Micrometer IoTDBReporter, because {}", e.getMessage());
return false;
}
return true;
}
@Override
public ReporterType getReporterType() {
return ReporterType.IOTDB;
}
@Override
public void setMetricManager(AbstractMetricManager metricManager) {
this.metricManager = metricManager;
}
}
......@@ -20,7 +20,7 @@
package org.apache.iotdb.metrics.micrometer.reporter;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.reporter.JmxReporter;
import org.apache.iotdb.metrics.utils.ReporterType;
import io.micrometer.core.instrument.Clock;
......@@ -33,9 +33,8 @@ import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.stream.Collectors;
public class MicrometerJmxReporter implements Reporter {
public class MicrometerJmxReporter implements JmxReporter {
private static final Logger LOGGER = LoggerFactory.getLogger(MicrometerJmxReporter.class);
private AbstractMetricManager metricManager;
@Override
public boolean start() {
......@@ -82,6 +81,6 @@ public class MicrometerJmxReporter implements Reporter {
@Override
public void setMetricManager(AbstractMetricManager metricManager) {
this.metricManager = metricManager;
// do nothing
}
}
/*
* 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.micrometer.reporter;
import org.apache.iotdb.metrics.AbstractMetricManager;
import org.apache.iotdb.metrics.config.MetricConfig;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.reporter.Reporter;
import org.apache.iotdb.metrics.utils.ReporterType;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.netty.channel.ChannelOption;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;
import java.time.Duration;
import java.util.Set;
import java.util.stream.Collectors;
public class MicrometerPrometheusReporter implements Reporter {
private static final Logger LOGGER = LoggerFactory.getLogger(MicrometerPrometheusReporter.class);
private static final MetricConfig metricConfig =
MetricConfigDescriptor.getInstance().getMetricConfig();
private AbstractMetricManager metricManager;
private DisposableServer httpServer;
@Override
public boolean start() {
if (httpServer != null) {
return false;
}
Set<MeterRegistry> meterRegistrySet =
Metrics.globalRegistry.getRegistries().stream()
.filter(reporter -> reporter instanceof PrometheusMeterRegistry)
.collect(Collectors.toSet());
PrometheusMeterRegistry prometheusMeterRegistry;
if (meterRegistrySet.size() == 0) {
prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
prometheusMeterRegistry.throwExceptionOnRegistrationFailure();
Metrics.addRegistry(prometheusMeterRegistry);
} else {
prometheusMeterRegistry = (PrometheusMeterRegistry) meterRegistrySet.toArray()[0];
}
httpServer =
HttpServer.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000)
.channelGroup(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE))
.port(metricConfig.getPrometheusReporterPort())
.route(
routes ->
routes.get(
"/metrics",
(request, response) ->
response.sendString(Mono.just(prometheusMeterRegistry.scrape()))))
.bindNow();
LOGGER.info(
"http server for metrics started, listen on {}", metricConfig.getPrometheusReporterPort());
return true;
}
@Override
public boolean stop() {
if (httpServer != null) {
try {
Set<MeterRegistry> meterRegistrySet =
Metrics.globalRegistry.getRegistries().stream()
.filter(reporter -> reporter instanceof PrometheusMeterRegistry)
.collect(Collectors.toSet());
for (MeterRegistry meterRegistry : meterRegistrySet) {
meterRegistry.close();
Metrics.removeRegistry(meterRegistry);
}
httpServer.disposeNow(Duration.ofSeconds(10));
httpServer = null;
} catch (Exception e) {
LOGGER.error("failed to stop server", e);
return false;
}
}
return true;
}
@Override
public ReporterType getReporterType() {
return ReporterType.PROMETHEUS;
}
@Override
public void setMetricManager(AbstractMetricManager metricManager) {
this.metricManager = metricManager;
}
}
......@@ -21,8 +21,6 @@ package org.apache.iotdb.metrics.micrometer.type;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
public class MicrometerHistogramSnapshot implements HistogramSnapshot {
......@@ -82,9 +80,4 @@ public class MicrometerHistogramSnapshot implements HistogramSnapshot {
// need distributionSummary to push 0 percentiles
return (long) getValue(0.0);
}
@Override
public void dump(OutputStream output) {
this.histogramSnapshot.outputSummary((PrintStream) output, 100);
}
}
......@@ -15,6 +15,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
org.apache.iotdb.metrics.micrometer.reporter.MicrometerJmxReporter
org.apache.iotdb.metrics.micrometer.reporter.MicrometerPrometheusReporter
org.apache.iotdb.metrics.micrometer.reporter.MicrometerIoTDBReporter
\ No newline at end of file
org.apache.iotdb.metrics.micrometer.reporter.MicrometerJmxReporter
\ No newline at end of file
......@@ -27,8 +27,8 @@ import org.apache.iotdb.commons.service.ServiceType;
import org.apache.iotdb.metrics.AbstractMetricService;
import org.apache.iotdb.metrics.config.ReloadLevel;
import org.apache.iotdb.metrics.metricsets.IMetricSet;
import org.apache.iotdb.metrics.reporter.InternalReporter;
import org.apache.iotdb.metrics.reporter.MemoryInternalReporter;
import org.apache.iotdb.metrics.reporter.iotdb.InternalIoTDBReporter;
import org.apache.iotdb.metrics.reporter.iotdb.MemoryInternalIoTDBReporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -72,14 +72,14 @@ public class MetricService extends AbstractMetricService implements MetricServic
public void stop() {
logger.info("Stop metric service");
internalReporter.stop();
internalReporter = new MemoryInternalReporter();
internalReporter = new MemoryInternalIoTDBReporter();
stopService();
JMXService.deregisterMBean(mbeanName);
logger.info("Finish stopping metric service");
}
@Override
public void reloadInternalReporter(InternalReporter internalReporter) {
public void reloadInternalReporter(InternalIoTDBReporter internalReporter) {
logger.info("Reload internal reporter");
internalReporter.addAutoGauge(this.internalReporter.getAllAutoGauge());
this.internalReporter.stop();
......@@ -115,7 +115,7 @@ public class MetricService extends AbstractMetricService implements MetricServic
return ServiceType.METRIC_SERVICE;
}
public void updateInternalReporter(InternalReporter InternalReporter) {
public void updateInternalReporter(InternalIoTDBReporter InternalReporter) {
this.internalReporter = InternalReporter;
}
......
......@@ -230,7 +230,7 @@ dn_target_config_node_list=127.0.0.1:22277
# dn_metric_frame_type=MICROMETER
# The level of metric module
# Options: [Core, Important, Normal, All]
# Options: [CORE, IMPORTANT, NORMAL, ALL]
# Datatype: String
# dn_metric_level=CORE
......
......@@ -48,8 +48,8 @@ import org.apache.iotdb.db.wal.utils.WALMode;
import org.apache.iotdb.external.api.IPropertiesLoader;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.config.ReloadLevel;
import org.apache.iotdb.metrics.reporter.InternalReporter;
import org.apache.iotdb.metrics.reporter.MemoryInternalReporter;
import org.apache.iotdb.metrics.reporter.iotdb.InternalIoTDBReporter;
import org.apache.iotdb.metrics.reporter.iotdb.MemoryInternalIoTDBReporter;
import org.apache.iotdb.metrics.utils.InternalReporterType;
import org.apache.iotdb.rpc.RpcTransportFactory;
import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
......@@ -1544,12 +1544,12 @@ public class IoTDBDescriptor {
ReloadLevel reloadLevel = MetricConfigDescriptor.getInstance().loadHotProps(commonProperties);
logger.info("Reload metric service in level {}", reloadLevel);
if (reloadLevel == ReloadLevel.RESTART_INTERNAL_REPORTER) {
InternalReporter internalReporter;
InternalIoTDBReporter internalReporter;
if (MetricConfigDescriptor.getInstance().getMetricConfig().getInternalReportType()
== InternalReporterType.IOTDB) {
internalReporter = new IoTDBInternalReporter();
} else {
internalReporter = new MemoryInternalReporter();
internalReporter = new MemoryInternalIoTDBReporter();
}
MetricService.getInstance().reloadInternalReporter(internalReporter);
} else {
......
......@@ -49,7 +49,7 @@ public class ChunkCacheMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "chunk");
MetricType.AUTO_GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "chunk");
}
@Override
......
......@@ -57,9 +57,9 @@ public class TimeSeriesMetadataCacheMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "timeSeriesMeta");
MetricType.AUTO_GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "timeSeriesMeta");
metricService.remove(
MetricType.GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "bloomFilter");
MetricType.AUTO_GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "bloomFilter");
}
@Override
......
......@@ -60,14 +60,14 @@ public class FlushManagerMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.QUEUE.toString(),
Tag.NAME.toString(),
"flush",
Tag.STATUS.toString(),
"waiting");
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.QUEUE.toString(),
Tag.NAME.toString(),
"flush",
......
......@@ -51,7 +51,7 @@ public class DataRegionMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.MEM.toString(),
Tag.NAME.toString(),
"storageGroup_" + storageGroupName);
......
......@@ -53,7 +53,7 @@ public class TsFileProcessorInfoMetrics implements IMetricSet {
public void unbindFrom(AbstractMetricService metricService) {
MetricService.getInstance()
.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.MEM.toString(),
Tag.NAME.toString(),
"chunkMetaData_" + storageGroupName);
......
......@@ -49,7 +49,7 @@ public class DataNodeSchemaCacheMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "schemaCache");
MetricType.AUTO_GAUGE, Metric.CACHE_HIT.toString(), Tag.NAME.toString(), "schemaCache");
}
@Override
......
......@@ -49,7 +49,7 @@ public class SchemaStatisticsManagerMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.QUANTITY.toString(), Tag.NAME.toString(), "timeSeries");
MetricType.AUTO_GAUGE, Metric.QUANTITY.toString(), Tag.NAME.toString(), "timeSeries");
}
@Override
......
......@@ -49,7 +49,7 @@ public class MPPDataExchangeServiceMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.THRIFT_ACTIVE_THREADS.toString(),
Tag.NAME.toString(),
ThreadName.MPP_DATA_EXCHANGE_RPC_SERVICE.getName());
......
......@@ -53,7 +53,7 @@ public class MppDataExchangeServiceThriftHandlerMetrics implements IMetricSet {
public void unbindFrom(AbstractMetricService metricService) {
MetricService.getInstance()
.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.THRIFT_CONNECTIONS.toString(),
Tag.NAME.toString(),
"MPPDataExchange");
......
......@@ -62,14 +62,14 @@ public class RawQueryReadTaskPoolManagerMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.QUEUE.toString(),
Tag.NAME.toString(),
ThreadName.SUB_RAW_QUERY_SERVICE.getName(),
Tag.STATUS.toString(),
"running");
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.QUEUE.toString(),
Tag.NAME.toString(),
ThreadName.SUB_RAW_QUERY_SERVICE.getName(),
......
......@@ -51,7 +51,7 @@ public class DataNodeInternalRPCServiceMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.THRIFT_ACTIVE_THREADS.toString(),
Tag.NAME.toString(),
ThreadName.DATANODE_INTERNAL_RPC_SERVICE.getName());
......
......@@ -50,7 +50,7 @@ public class RPCServiceMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.THRIFT_ACTIVE_THREADS.toString(),
Tag.NAME.toString(),
ThreadName.CLIENT_RPC_SERVICE.getName());
......
......@@ -120,16 +120,18 @@ public class FileMetrics implements IMetricSet {
currentServiceFuture = null;
}
metricService.remove(MetricType.GAUGE, Metric.FILE_SIZE.toString(), Tag.NAME.toString(), "wal");
metricService.remove(MetricType.GAUGE, Metric.FILE_SIZE.toString(), Tag.NAME.toString(), "seq");
metricService.remove(
MetricType.GAUGE, Metric.FILE_SIZE.toString(), Tag.NAME.toString(), "unseq");
MetricType.AUTO_GAUGE, Metric.FILE_SIZE.toString(), Tag.NAME.toString(), "wal");
metricService.remove(
MetricType.GAUGE, Metric.FILE_COUNT.toString(), Tag.NAME.toString(), "wal");
MetricType.AUTO_GAUGE, Metric.FILE_SIZE.toString(), Tag.NAME.toString(), "seq");
metricService.remove(
MetricType.GAUGE, Metric.FILE_COUNT.toString(), Tag.NAME.toString(), "seq");
MetricType.AUTO_GAUGE, Metric.FILE_SIZE.toString(), Tag.NAME.toString(), "unseq");
metricService.remove(
MetricType.GAUGE, Metric.FILE_COUNT.toString(), Tag.NAME.toString(), "unseq");
MetricType.AUTO_GAUGE, Metric.FILE_COUNT.toString(), Tag.NAME.toString(), "wal");
metricService.remove(
MetricType.AUTO_GAUGE, Metric.FILE_COUNT.toString(), Tag.NAME.toString(), "seq");
metricService.remove(
MetricType.AUTO_GAUGE, Metric.FILE_COUNT.toString(), Tag.NAME.toString(), "unseq");
}
private void collect() {
......
......@@ -37,24 +37,21 @@ import org.apache.iotdb.db.mpp.plan.parser.StatementGenerator;
import org.apache.iotdb.db.mpp.plan.statement.Statement;
import org.apache.iotdb.db.query.control.SessionManager;
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
import org.apache.iotdb.metrics.reporter.InternalReporter;
import org.apache.iotdb.metrics.type.AutoGauge;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
import org.apache.iotdb.metrics.reporter.iotdb.InternalIoTDBReporter;
import org.apache.iotdb.metrics.utils.InternalReporterType;
import org.apache.iotdb.metrics.utils.IoTDBMetricsUtils;
import org.apache.iotdb.metrics.utils.ReporterType;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.iotdb.service.rpc.thrift.TSInsertRecordReq;
import org.apache.iotdb.session.util.SessionUtils;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.utils.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.time.ZoneId;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
......@@ -62,7 +59,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class IoTDBInternalReporter extends InternalReporter {
public class IoTDBInternalReporter extends InternalIoTDBReporter {
private static final Logger LOGGER = LoggerFactory.getLogger(IoTDBInternalReporter.class);
private static final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
private static final SessionManager SESSION_MANAGER = SessionManager.getInstance();
......@@ -84,89 +81,84 @@ public class IoTDBInternalReporter extends InternalReporter {
SESSION_INFO = new SessionInfo(0, "root", ZoneId.systemDefault().getId());
}
private void collectAutoGauge() {
for (Map.Entry<Pair<String, String[]>, AutoGauge> entry : autoGauges.entrySet()) {
updateValue(
entry.getKey().left, entry.getValue().value(), TSDataType.INT64, entry.getKey().right);
}
}
@Override
public void updateValue(String name, Object value, TSDataType type, String... tags) {
// TODO spricoder update iotdb reporter
updateValue(name, value, type, System.currentTimeMillis(), tags);
}
@Override
public void updateValue(String name, Object value, TSDataType type, Long time, String... tags) {
if (value != null) {
try {
TSInsertRecordReq request = new TSInsertRecordReq();
String prefix = IoTDBMetricsUtils.generatePath(name, tags);
List<String> measurements = Collections.singletonList("value");
List<TSDataType> types = Collections.singletonList(type);
List<Object> values = Collections.singletonList(value);
ByteBuffer buffer = SessionUtils.getValueBuffer(types, values);
request.setPrefixPath(prefix);
request.setTimestamp(time);
request.setMeasurements(measurements);
request.setValues(buffer);
request.setIsAligned(false);
Statement s = StatementGenerator.createStatement(request);
final long queryId = SESSION_MANAGER.requestQueryId();
ExecutionResult result =
COORDINATOR.execute(s, queryId, SESSION_INFO, "", PARTITION_FETCHER, SCHEMA_FETCHER);
if (result.status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
LOGGER.error("Failed to update the value of metric with status {}", result.status);
}
} catch (IoTDBConnectionException e1) {
LOGGER.error("Failed to update the value of metric because of unknown type");
} catch (IllegalPathException | QueryProcessException e2) {
LOGGER.error("Failed to update the value of metric because of internal error");
}
}
}
@Override
public void writeSnapshotAndCount(String name, HistogramSnapshot snapshot, String... tags) {
Long time = System.currentTimeMillis();
updateValue(name + "_min", snapshot.getMin(), TSDataType.INT64, time, tags);
updateValue(name + "_mean", snapshot.getMean(), TSDataType.DOUBLE, time, tags);
updateValue(name + "_median", snapshot.getMedian(), TSDataType.DOUBLE, time, tags);
updateValue(name + "_95", snapshot.getValue(0.95), TSDataType.DOUBLE, time, tags);
updateValue(name + "_99", snapshot.getValue(0.99), TSDataType.DOUBLE, time, tags);
updateValue(name + "_999", snapshot.getValue(0.999), TSDataType.DOUBLE, time, tags);
updateValue(name + "_max", snapshot.getMax(), TSDataType.INT64, time, tags);
}
@Override
public InternalReporterType getType() {
return InternalReporterType.IOTDB;
}
@Override
public void start() {
public boolean start() {
if (currentServiceFuture == null) {
currentServiceFuture =
ScheduledExecutorUtil.safelyScheduleAtFixedRate(
service,
this::collectAutoGauge,
() -> {
writeMetricToIoTDB(autoGauges);
},
1,
MetricConfigDescriptor.getInstance()
.getMetricConfig()
.getAsyncCollectPeriodInSecond(),
TimeUnit.SECONDS);
}
return true;
}
@Override
public void stop() {
public boolean stop() {
if (currentServiceFuture != null) {
currentServiceFuture.cancel(true);
currentServiceFuture = null;
}
clear();
return true;
}
@Override
public ReporterType getReporterType() {
return ReporterType.IOTDB;
}
@Override
protected void writeMetricToIoTDB(Map<String, Object> valueMap, String prefix, long time) {
try {
TSInsertRecordReq request = new TSInsertRecordReq();
List<String> measurements = new ArrayList<>();
List<TSDataType> types = new ArrayList<>();
List<Object> values = new ArrayList<>();
for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
String measurement = entry.getKey();
Object value = entry.getValue();
measurements.add(measurement);
types.add(inferType(value));
values.add(value);
}
ByteBuffer buffer = SessionUtils.getValueBuffer(types, values);
request.setPrefixPath(prefix);
request.setTimestamp(time);
request.setMeasurements(measurements);
request.setValues(buffer);
request.setIsAligned(false);
Statement s = StatementGenerator.createStatement(request);
final long queryId = SESSION_MANAGER.requestQueryId();
ExecutionResult result =
COORDINATOR.execute(s, queryId, SESSION_INFO, "", PARTITION_FETCHER, SCHEMA_FETCHER);
if (result.status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
LOGGER.error("Failed to update the value of metric with status {}", result.status);
}
} catch (IoTDBConnectionException e1) {
LOGGER.error("Failed to update the value of metric because of unknown type");
} catch (IllegalPathException | QueryProcessException e2) {
LOGGER.error("Failed to update the value of metric because of internal error");
}
}
@Override
protected void writeMetricsToIoTDB(Map<String, Map<String, Object>> valueMap, long time) {
for (Map.Entry<String, Map<String, Object>> value : valueMap.entrySet()) {
writeMetricToIoTDB(value.getValue(), value.getKey(), time);
}
}
}
......@@ -76,10 +76,10 @@ public class ProcessMetrics implements IMetricSet {
private void removeProcessCPUInfo(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_CPU_LOAD.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_CPU_LOAD.toString(), Tag.NAME.toString(), "process");
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_CPU_TIME.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_CPU_TIME.toString(), Tag.NAME.toString(), "process");
}
private void collectProcessMemInfo(AbstractMetricService metricService) {
......@@ -124,15 +124,15 @@ public class ProcessMetrics implements IMetricSet {
private void removeProcessMemInfo(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_MAX_MEM.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_MAX_MEM.toString(), Tag.NAME.toString(), "process");
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_TOTAL_MEM.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_TOTAL_MEM.toString(), Tag.NAME.toString(), "process");
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_FREE_MEM.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_FREE_MEM.toString(), Tag.NAME.toString(), "process");
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_USED_MEM.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_USED_MEM.toString(), Tag.NAME.toString(), "process");
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_MEM_RATIO.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_MEM_RATIO.toString(), Tag.NAME.toString(), "process");
}
private void collectThreadInfo(AbstractMetricService metricService) {
......@@ -148,7 +148,10 @@ public class ProcessMetrics implements IMetricSet {
private void removeThreadInfo(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_THREADS_COUNT.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE,
Metric.PROCESS_THREADS_COUNT.toString(),
Tag.NAME.toString(),
"process");
}
private void collectProcessStatusInfo(AbstractMetricService metricService) {
......@@ -163,7 +166,7 @@ public class ProcessMetrics implements IMetricSet {
private void removeProcessStatusInfo(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.PROCESS_STATUS.toString(), Tag.NAME.toString(), "process");
MetricType.AUTO_GAUGE, Metric.PROCESS_STATUS.toString(), Tag.NAME.toString(), "process");
}
private long getProcessUsedMemory() {
......
......@@ -112,7 +112,7 @@ public class SystemMetrics implements IMetricSet {
private void removeSystemCpuInfo(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.SYS_CPU_LOAD.toString(), Tag.NAME.toString(), "system");
MetricType.AUTO_GAUGE, Metric.SYS_CPU_LOAD.toString(), Tag.NAME.toString(), "system");
metricService.remove(
MetricType.GAUGE, Metric.SYS_CPU_CORES.toString(), Tag.NAME.toString(), "system");
......@@ -163,22 +163,25 @@ public class SystemMetrics implements IMetricSet {
Tag.NAME.toString(),
"system");
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.SYS_FREE_PHYSICAL_MEMORY_SIZE.toString(),
Tag.NAME.toString(),
"system");
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.SYS_TOTAL_SWAP_SPACE_SIZE.toString(),
Tag.NAME.toString(),
"system");
metricService.remove(
MetricType.GAUGE,
MetricType.AUTO_GAUGE,
Metric.SYS_FREE_SWAP_SPACE_SIZE.toString(),
Tag.NAME.toString(),
"system");
metricService.remove(
MetricType.GAUGE, Metric.SYS_COMMITTED_VM_SIZE.toString(), Tag.NAME.toString(), "system");
MetricType.AUTO_GAUGE,
Metric.SYS_COMMITTED_VM_SIZE.toString(),
Tag.NAME.toString(),
"system");
}
private void collectSystemDiskInfo(AbstractMetricService metricService) {
......@@ -221,9 +224,15 @@ public class SystemMetrics implements IMetricSet {
private void removeSystemDiskInfo(AbstractMetricService metricService) {
fileStores.clear();
metricService.remove(
MetricType.GAUGE, Metric.SYS_DISK_TOTAL_SPACE.toString(), Tag.NAME.toString(), "system");
MetricType.AUTO_GAUGE,
Metric.SYS_DISK_TOTAL_SPACE.toString(),
Tag.NAME.toString(),
"system");
metricService.remove(
MetricType.GAUGE, Metric.SYS_DISK_FREE_SPACE.toString(), Tag.NAME.toString(), "system");
MetricType.AUTO_GAUGE,
Metric.SYS_DISK_FREE_SPACE.toString(),
Tag.NAME.toString(),
"system");
}
private void collectDiskMetrics() {
......
......@@ -50,7 +50,10 @@ public class InternalServiceThriftHandlerMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.THRIFT_CONNECTIONS.toString(), Tag.NAME.toString(), "Internal");
MetricType.AUTO_GAUGE,
Metric.THRIFT_CONNECTIONS.toString(),
Tag.NAME.toString(),
"Internal");
}
@Override
......
......@@ -47,7 +47,7 @@ public class RPCServiceThriftHandlerMetrics implements IMetricSet {
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.GAUGE, Metric.THRIFT_CONNECTIONS.toString(), Tag.NAME.toString(), "RPC");
MetricType.AUTO_GAUGE, Metric.THRIFT_CONNECTIONS.toString(), Tag.NAME.toString(), "RPC");
}
@Override
......
......@@ -100,13 +100,13 @@ public class MetricServiceTest {
assertNotEquals(counter1, counter2);
counter2 = metricService.getOrCreateCounter("counter5", MetricLevel.NORMAL, "tag", "value");
assertEquals(DoNothingMetricManager.doNothingCounter, counter2);
assertEquals(4, metricService.getAllCounters().size());
assertEquals(4, metricService.getMetricsByType(MetricType.COUNTER).size());
metricService.count(10, "counter6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getAllCounters().size());
assertEquals(5, metricService.getMetricsByType(MetricType.COUNTER).size());
metricService.remove(MetricType.COUNTER, "counter6");
assertEquals(5, metricService.getAllCounters().size());
assertEquals(5, metricService.getMetricsByType(MetricType.COUNTER).size());
metricService.remove(MetricType.COUNTER, "counter6", "tag", "value");
assertEquals(4, metricService.getAllCounters().size());
assertEquals(4, metricService.getMetricsByType(MetricType.COUNTER).size());
assertEquals(4, metricService.getAllMetricKeys().size());
// test gauge
......@@ -126,13 +126,13 @@ public class MetricServiceTest {
assertNotEquals(gauge1, gauge2);
gauge2 = metricService.getOrCreateGauge("gauge5", MetricLevel.NORMAL, "tag", "value");
assertEquals(DoNothingMetricManager.doNothingGauge, gauge2);
assertEquals(4, metricService.getAllGauges().size());
assertEquals(4, metricService.getMetricsByType(MetricType.GAUGE).size());
metricService.gauge(10, "gauge6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getAllGauges().size());
assertEquals(5, metricService.getMetricsByType(MetricType.GAUGE).size());
metricService.remove(MetricType.GAUGE, "gauge6");
assertEquals(5, metricService.getAllGauges().size());
assertEquals(5, metricService.getMetricsByType(MetricType.GAUGE).size());
metricService.remove(MetricType.GAUGE, "gauge6", "tag", "value");
assertEquals(4, metricService.getAllGauges().size());
assertEquals(4, metricService.getMetricsByType(MetricType.GAUGE).size());
assertEquals(8, metricService.getAllMetricKeys().size());
// test auto gauge
......@@ -150,10 +150,10 @@ public class MetricServiceTest {
list = null;
System.gc();
assertEquals(0L, autoGauge.value());
assertEquals(4, metricService.getAllGauges().size());
assertEquals(1, metricService.getAllAutoGauges().size());
metricService.remove(MetricType.GAUGE, "autoGauge", "tag", "value");
assertEquals(4, metricService.getAllGauges().size());
assertEquals(4, metricService.getMetricsByType(MetricType.GAUGE).size());
assertEquals(1, metricService.getMetricsByType(MetricType.AUTO_GAUGE).size());
metricService.remove(MetricType.AUTO_GAUGE, "autoGauge", "tag", "value");
assertEquals(4, metricService.getMetricsByType(MetricType.GAUGE).size());
assertEquals(8, metricService.getAllMetricKeys().size());
// test rate
......@@ -174,14 +174,14 @@ public class MetricServiceTest {
"rate4", MetricLevel.IMPORTANT, "tag", "value", "tag2", "value");
assertNotEquals(rate1, rate2);
rate2 = metricService.getOrCreateRate("rate5", MetricLevel.NORMAL, "tag", "value");
assertEquals(4, metricService.getAllRates().size());
assertEquals(4, metricService.getMetricsByType(MetricType.RATE).size());
assertEquals(DoNothingMetricManager.doNothingRate, rate2);
metricService.rate(10, "rate6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getAllRates().size());
assertEquals(5, metricService.getMetricsByType(MetricType.RATE).size());
metricService.remove(MetricType.RATE, "rate6");
assertEquals(5, metricService.getAllRates().size());
assertEquals(5, metricService.getMetricsByType(MetricType.RATE).size());
metricService.remove(MetricType.RATE, "rate6", "tag", "value");
assertEquals(4, metricService.getAllRates().size());
assertEquals(4, metricService.getMetricsByType(MetricType.RATE).size());
assertEquals(12, metricService.getAllMetricKeys().size());
// test histogram
......@@ -212,23 +212,23 @@ public class MetricServiceTest {
histogram2 =
metricService.getOrCreateHistogram("histogram5", MetricLevel.NORMAL, "tag", "value");
assertEquals(DoNothingMetricManager.doNothingHistogram, histogram2);
assertEquals(4, metricService.getAllHistograms().size());
assertEquals(4, metricService.getMetricsByType(MetricType.HISTOGRAM).size());
metricService.histogram(10, "histogram6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getAllHistograms().size());
assertEquals(5, metricService.getMetricsByType(MetricType.HISTOGRAM).size());
metricService.remove(MetricType.HISTOGRAM, "histogram6");
assertEquals(5, metricService.getAllHistograms().size());
assertEquals(5, metricService.getMetricsByType(MetricType.HISTOGRAM).size());
metricService.remove(MetricType.HISTOGRAM, "histogram6", "tag", "value");
assertEquals(4, metricService.getAllHistograms().size());
assertEquals(4, metricService.getMetricsByType(MetricType.HISTOGRAM).size());
assertEquals(16, metricService.getAllMetricKeys().size());
// test timer
Timer timer1 = metricService.getOrCreateTimer("timer1", MetricLevel.IMPORTANT, "tag", "value");
assertNotNull(timer1);
metricService.timer(2, TimeUnit.MINUTES, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(4, TimeUnit.MINUTES, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(6, TimeUnit.MINUTES, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(8, TimeUnit.MINUTES, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(10, TimeUnit.MINUTES, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(2, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(4, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(6, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(8, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(10, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, timer1.getImmutableRate().getCount());
assertEquals(5, timer1.takeSnapshot().size());
Timer timer2 = metricService.getOrCreateTimer("timer1", MetricLevel.IMPORTANT, "tag", "value");
......@@ -243,13 +243,13 @@ public class MetricServiceTest {
assertNotEquals(timer1, timer2);
timer2 = metricService.getOrCreateTimer("timer5", MetricLevel.NORMAL, "tag", "value");
assertNotEquals(timer1, timer2);
assertEquals(4, metricService.getAllTimers().size());
assertEquals(4, metricService.getMetricsByType(MetricType.TIMER).size());
metricService.timer(10, TimeUnit.MILLISECONDS, "timer6", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, metricService.getAllTimers().size());
assertEquals(5, metricService.getMetricsByType(MetricType.TIMER).size());
metricService.remove(MetricType.TIMER, "timer6");
assertEquals(5, metricService.getAllTimers().size());
assertEquals(5, metricService.getMetricsByType(MetricType.TIMER).size());
metricService.remove(MetricType.TIMER, "timer6", "tag", "value");
assertEquals(4, metricService.getAllTimers().size());
assertEquals(4, metricService.getMetricsByType(MetricType.TIMER).size());
assertEquals(20, metricService.getAllMetricKeys().size());
// test remove same key and different value counter
......@@ -259,15 +259,15 @@ public class MetricServiceTest {
Counter removeCounter2 =
metricService.getOrCreateCounter("remove", MetricLevel.IMPORTANT, "tag", "value2");
assertNotNull(removeCounter2);
assertEquals(6, metricService.getAllCounters().size());
assertEquals(6, metricService.getMetricsByType(MetricType.COUNTER).size());
assertEquals(22, metricService.getAllMetricKeys().size());
metricService.remove(MetricType.COUNTER, "remove", "tag", "value1");
assertEquals(5, metricService.getAllCounters().size());
assertEquals(5, metricService.getMetricsByType(MetricType.COUNTER).size());
assertEquals(21, metricService.getAllMetricKeys().size());
removeCounter2 =
metricService.getOrCreateCounter("remove", MetricLevel.IMPORTANT, "tag", "value1");
assertNotNull(removeCounter2);
assertEquals(6, metricService.getAllCounters().size());
assertEquals(6, metricService.getMetricsByType(MetricType.COUNTER).size());
assertEquals(22, metricService.getAllMetricKeys().size());
}
......
......@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode1/data/tracing
dn_consensus_dir=target/datanode1/consensus
dn_sync_dir=target/datanode1/sync
dn_enable_metric=true
dn_enable_performance_stat=false
dn_metric_reporter_list=PROMETHEUS
dn_metric_frame_type=MICROMETER
dn_metric_level=CORE
dn_metric_level=IMPORTANT
dn_metric_async_collect_period=5
dn_metric_prometheus_reporter_port=9097
\ No newline at end of file
......@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode2/data/tracing
dn_consensus_dir=target/datanode2/consensus
dn_sync_dir=target/datanode2/sync
dn_enable_metric=true
dn_enable_performance_stat=false
dn_metric_reporter_list=PROMETHEUS
dn_metric_frame_type=MICROMETER
dn_metric_level=CORE
dn_metric_level=IMPORTANT
dn_metric_async_collect_period=5
dn_metric_prometheus_reporter_port=9099
......@@ -35,10 +35,9 @@ dn_tracing_dir=target/datanode3/data/tracing
dn_consensus_dir=target/datanode3/consensus
dn_sync_dir=target/datanode3/sync
dn_enable_metric=true
dn_enable_performance_stat=false
dn_metric_reporter_list=PROMETHEUS
dn_metric_frame_type=MICROMETER
dn_metric_level=CORE
dn_metric_level=IMPORTANT
dn_metric_async_collect_period=5
dn_metric_prometheus_reporter_port=9101
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册