From ba36cfbd1a2fb0a46e327e1dfe31025d1fcf84bf Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sat, 23 Sep 2023 11:02:48 +0800 Subject: [PATCH] bugfix mongodb collect extra metrics npe (#1257) --- .../collector/collect/mongodb/MongodbSingleCollectImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java b/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java index cd4d5436a85..4751f1c98ef 100644 --- a/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java +++ b/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java @@ -112,6 +112,9 @@ public void collect(CollectRep.MetricsData.Builder builder, long appId, String a document = (Document) document.get(metricsParts[i]); } } + if (document == null) { + throw new RuntimeException("the document get from command " + metrics.getMongodb().getCommand() + " is null."); + } fillBuilder(metrics, valueRowBuilder, document); builder.addValues(valueRowBuilder.build()); } catch (MongoServerUnavailableException | MongoTimeoutException unavailableException) { @@ -137,7 +140,7 @@ public String supportProtocol() { private void fillBuilder(Metrics metrics, CollectRep.ValueRow.Builder valueRowBuilder, Document document) { metrics.getAliasFields().forEach(it -> { if (document.containsKey(it)) { - Object fieldValue =document.get(it); + Object fieldValue = document.get(it); if (fieldValue == null) { valueRowBuilder.addColumns(CommonConstants.NULL_VALUE); } else {