Skip to content
Permalink
Browse files
[IOTDB-3158][metric] fix NPE exception (#5891)
  • Loading branch information
SpriCoder committed May 14, 2022
1 parent d93a848 commit fe253ffdfdb94aec990472f99dc9ae20540ab859
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
@@ -156,6 +156,9 @@ public void report(
}

private void sendGauge(String name, Gauge gauge) {
if (null == gauge) {
return;
}
MetricName metricName = new MetricName(name);
Object obj = gauge.getValue();
double value;
@@ -168,12 +171,18 @@ private void sendGauge(String name, Gauge gauge) {
}

private void sendCounter(String name, Counter counter) {
if (null == counter) {
return;
}
MetricName metricName = new MetricName(name);
double value = counter.getCount();
updateValue(prefixed(metricName.getName()), metricName.getTags(), value);
}

private void sendHistogram(String name, Histogram histogram) {
if (null == histogram) {
return;
}
MetricName metricName = new MetricName(name);
writeSnapshotAndCount(
prefixed(metricName.getName()),
@@ -184,12 +193,18 @@ private void sendHistogram(String name, Histogram histogram) {
}

private void sendMeter(String name, Meter meter) {
if (null == meter) {
return;
}
MetricName metricName = new MetricName(name);
double value = meter.getCount();
updateValue(prefixed(metricName.getName()), metricName.getTags(), value);
}

private void sendTimer(String name, Timer timer) {
if (null == timer) {
return;
}
MetricName metricName = new MetricName(name);
writeSnapshotAndCount(
prefixed(metricName.getName()),
@@ -73,38 +73,40 @@ protected void publish() {
getMeters()
.forEach(
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);
});
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);
});
}
});
}

0 comments on commit fe253ff

Please sign in to comment.