From 0a7c7146e0dae50ba720ca944365c4f104cd97cc 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 e2b9b43d0bd..d553a590efb 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 {