Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c8c8aa0
[Dropwizard Prometheus] fix prometheus name of dropwizard.
Mar 17, 2022
c106e53
Merge remote-tracking branch 'tsinghua/master' into fix/name_in_dropw…
Mar 21, 2022
201d9fa
[Dropwizard Prometheus] fix prometheus name of dropwizard.
Mar 21, 2022
4d3b510
[IoTDB Reporter] move iotdb reporter.
Mar 21, 2022
2b9d14e
[IoTDB Reporter] fix reporter init problem.
Mar 21, 2022
121cb73
Merge remote-tracking branch 'tsinghua/master' into improve/iotdb_rep…
Mar 21, 2022
5ab44c1
Merge branch 'fix/name_in_dropwizard' into improve/iotdb_reporter_impl
Mar 22, 2022
af030d1
[IoTDB Reporter] fix tags in dropwizard.
Mar 22, 2022
e9bc78a
[IoTDB Reporter] fix default value.
Mar 22, 2022
c0cc1e8
Merge remote-tracking branch 'tsinghua/master' into improve/iotdb_rep…
Mar 23, 2022
b89b3d5
[Dependency] fix cycle dependency
Mar 23, 2022
e7c1261
Merge remote-tracking branch 'tsinghua/master' into improve/iotdb_rep…
Mar 24, 2022
e4500a9
[iotdb reporter] fix hot load
Mar 24, 2022
6553793
Merge remote-tracking branch 'tsinghua/master' into improve/iotdb_rep…
Mar 24, 2022
94ec06e
[conf] fix name
Mar 24, 2022
111a33b
[conf] update config name parameter
Mar 24, 2022
c45f446
[hot load] fix hot load of reporter
Mar 24, 2022
f6a7184
[conf] update config
Mar 24, 2022
057921a
[conf] fix restart reporter
Mar 24, 2022
24c5c9f
[conf] fix test
Mar 24, 2022
0511263
[doc] update doc
Mar 25, 2022
7d10437
[doc] update doc
Mar 25, 2022
17dd830
Merge remote-tracking branch 'tsinghua/master' into improve/iotdb_rep…
Mar 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/UserGuide/Maintenance-Tools/Metric-Tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,17 @@ metricLevel: IMPORTANT
predefinedMetrics:
- JVM

# Period time of push, only used by IoTDB Reporter
pushPeriodInSecond: 5

# The http server's port for prometheus exporter to get metric data.
prometheusExporterPort: 9091

# The config of iotdb reporter
ioTDBReporterConfig:
host: 127.0.0.1
port: 6667
username: root
password: root
database: _metric
pushPeriodInSecond: 15
```

Then you can get metrics data as follows
Expand Down
14 changes: 10 additions & 4 deletions docs/zh/UserGuide/Maintenance-Tools/Metric-Tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,17 @@ metricLevel: IMPORTANT
predefinedMetrics:
- JVM

# 数据推送时间,该参数只对 IoTDB Reporter 生效
pushPeriodInSecond: 5

# Prometheus Reporter 使用的端口
prometheusExporterPort: 9091
prometheusExporterPort: 9091

# IoTDB Reporter相关的配置
ioTDBReporterConfig:
host: 127.0.0.1
port: 6667
username: root
password: root
database: _metric
pushPeriodInSecond: 15
```

然后按照下面的操作获取metrics数据
Expand Down
1 change: 0 additions & 1 deletion metrics/dropwizard-metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<groupId>org.apache.iotdb</groupId>
<artifactId>metrics-interface</artifactId>
<version>0.14.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
public class MetricName {
private String name;
private MetricLevel metricLevel;
private Map<String, String> tags;
private Map<String, String> tags = new LinkedHashMap<>();
private static final String TAG_SEPARATOR = ".";

public MetricName(String name, String... tags) {
this.name = name;
this.tags = new HashMap<>();
if (tags.length % 2 == 0) {
for (int i = 0; i < tags.length; i += 2) {
this.tags.put(tags[i], tags[i + 1]);
Expand All @@ -53,6 +52,30 @@ public MetricName(String name, MetricLevel metricLevel, String... tags) {
this.metricLevel = metricLevel;
}

/** Create metric name from flatString */
public MetricName(String flatString) {
int firstIndex = flatString.indexOf("{");
int lastIndex = flatString.indexOf("}");
if (firstIndex == -1 || lastIndex == -1) {
String sanitizeMetricName = flatString.replaceAll("[^a-zA-Z0-9:_\\]\\[]", "_");
this.name = sanitizeMetricName;
} else {
String[] labelsFlat = flatString.substring(firstIndex + 1, lastIndex).split("\\.");
String sanitizeMetricName =
flatString.substring(0, firstIndex).replaceAll("[^a-zA-Z0-9:_\\]\\[]", "_");
if (labelsFlat.length == 0) {
this.name = sanitizeMetricName;
} else {
this.name = sanitizeMetricName;
if (labelsFlat.length % 2 == 0) {
for (int i = 0; i < labelsFlat.length; i += 2) {
this.tags.put(labelsFlat[i], labelsFlat[i + 1]);
}
}
}
}
}

/**
* convert the metric name to flat string
*
Expand All @@ -74,11 +97,7 @@ public String toFlatString() {
return stringBuilder.toString();
}

/**
* convert the metric name to string array.
*
* @return
*/
/** convert the metric name to string array. */
public String[] toStringArray() {
List<String> allNames = new ArrayList<>();
allNames.add(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iotdb.db.metrics.dropwizard.reporter;
package org.apache.iotdb.metrics.dropwizard.reporter;

import org.apache.iotdb.metrics.MetricManager;
import org.apache.iotdb.metrics.config.MetricConfig;
Expand Down Expand Up @@ -49,7 +49,8 @@ public boolean start() {
.prefixedWith("dropwizard:")
.filter(MetricFilter.ALL)
.build();
ioTDBReporter.start(metricConfig.getPushPeriodInSecond(), TimeUnit.SECONDS);
ioTDBReporter.start(
metricConfig.getIoTDBReporterConfig().getPushPeriodInSecond(), TimeUnit.SECONDS);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void scrape() throws IOException {

/** Export Gauge as Prometheus Gauge */
public void writeGauge(String dropwizardName, Gauge<?> gauge) throws IOException {
MetricName metricName = getMetricNameFromName(dropwizardName);
MetricName metricName = new MetricName(dropwizardName);
String sanitizeName = metricName.getName();
writer.writeHelp(sanitizeName, getHelpMessage(dropwizardName, gauge));
writer.writeType(sanitizeName, MetricType.GAUGE);
Expand All @@ -77,7 +77,7 @@ public void writeGauge(String dropwizardName, Gauge<?> gauge) throws IOException

/** Export counter as Prometheus Gauge */
public void writeCounter(String dropwizardName, Counter counter) throws IOException {
MetricName metricName = getMetricNameFromName(dropwizardName);
MetricName metricName = new MetricName(dropwizardName);
String sanitizeName = metricName.getName();
writer.writeHelp(sanitizeName, getHelpMessage(dropwizardName, counter));
writer.writeType(sanitizeName, MetricType.GAUGE);
Expand All @@ -87,7 +87,7 @@ public void writeCounter(String dropwizardName, Counter counter) throws IOExcept
/** Export histogram snapshot as Prometheus SUMMARY */
public void writeHistogram(String dropwizardName, Histogram histogram) throws IOException {
writeSnapshotAndCount(
getMetricNameFromName(dropwizardName),
new MetricName(dropwizardName),
histogram.getSnapshot(),
histogram.getCount(),
1.0,
Expand Down Expand Up @@ -125,42 +125,24 @@ private void writeSnapshotAndCount(
/** Export Timer as Prometheus Summary */
public void writeTimer(String dropwizardName, Timer timer) throws IOException {
writeSnapshotAndCount(
getMetricNameFromName(dropwizardName),
new MetricName(dropwizardName),
timer.getSnapshot(),
timer.getCount(),
1.0D / TimeUnit.SECONDS.toNanos(1L),
getHelpMessage(dropwizardName, timer));
writeMetered(getMetricNameFromName(dropwizardName), timer);
writeMetered(new MetricName(dropwizardName), timer);
}

/** Export Meter as Prometheus Counter */
public void writeMeter(String dropwizardName, Meter meter) throws IOException {
MetricName metricName = getMetricNameFromName(dropwizardName);
MetricName metricName = new MetricName(dropwizardName);
String sanitizeName = metricName.getName() + "_total";

writer.writeHelp(sanitizeName, getHelpMessage(dropwizardName, meter));
writer.writeType(sanitizeName, MetricType.COUNTER);
writer.writeSample(sanitizeName, metricName.getTags(), meter.getCount());

writeMetered(getMetricNameFromName(dropwizardName), meter);
}

/** Get metric name and tags from name */
private MetricName getMetricNameFromName(String dropwizardName) {
int firstIndex = dropwizardName.indexOf("{");
int lastIndex = dropwizardName.indexOf("}");
if (firstIndex == -1 || lastIndex == -1) {
String sanitizeMetricName = sanitizeMetricName(dropwizardName);
return new MetricName(sanitizeMetricName);
} else {
String[] labelsFlat = dropwizardName.substring(firstIndex + 1, lastIndex).split("\\.");
String sanitizeMetricName = sanitizeMetricName(dropwizardName.substring(0, firstIndex));
if (labelsFlat.length == 0) {
return new MetricName(sanitizeMetricName);
} else {
return new MetricName(sanitizeMetricName, labelsFlat);
}
}
writeMetered(new MetricName(dropwizardName), meter);
}

/** Export meter for multi type */
Expand All @@ -184,8 +166,4 @@ private static String getHelpMessage(String metricName, Metric metric) {
"Generated from Dropwizard metric import (metric=%s, type=%s)",
metricName, metric.getClass().getName());
}

static String sanitizeMetricName(String dropwizardName) {
return dropwizardName.replaceAll("[^a-zA-Z0-9:_\\]\\[]", "_");
}
}
Loading