diff --git a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java index 24c9847e763..2d4f37a3b75 100644 --- a/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java +++ b/warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/HistoryJpaDatabaseDataStorage.java @@ -128,15 +128,16 @@ void saveData(CollectRep.MetricsData metricsData) { String metrics = metricsData.getMetrics(); List fieldsList = metricsData.getFieldsList(); try { - List historyList = new LinkedList<>(); - History.HistoryBuilder historyBuilder = History.builder() - .monitorId(metricsData.getId()) - .app(monitorType) - .metrics(metrics) - .time(metricsData.getTime()); + List allHistoryList = new LinkedList<>(); for (CollectRep.ValueRow valueRow : metricsData.getValuesList()) { + List singleHistoryList = new LinkedList<>(); Map labels = new HashMap<>(8); for (int i = 0; i < fieldsList.size(); i++) { + History.HistoryBuilder historyBuilder = History.builder() + .monitorId(metricsData.getId()) + .app(monitorType) + .metrics(metrics) + .time(metricsData.getTime()); final CollectRep.Field field = fieldsList.get(i); final int fieldType = field.getType(); final String fieldName = field.getName(); @@ -183,11 +184,12 @@ void saveData(CollectRep.MetricsData metricsData) { } } - historyList.add(historyBuilder.build()); + singleHistoryList.add(historyBuilder.build()); } - historyBuilder.instance(JsonUtil.toJson(labels)); + singleHistoryList.forEach(history -> history.setInstance(JsonUtil.toJson(labels))); + allHistoryList.addAll(singleHistoryList); } - historyDao.saveAll(historyList); + historyDao.saveAll(allHistoryList); } catch (Exception e) { log.error(e.getMessage(), e); }