This is an automated email from the ASF dual-hosted git repository.
zhaoqingran pushed a commit to branch bulletin
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/bulletin by this push:
new a380e6f3b [feat(bulletin)] add metrics data support and optimize data
loading
a380e6f3b is described below
commit a380e6f3bdf9a3c7fd418feeee698951c12fd8c9
Author: zqr10159 <[email protected]>
AuthorDate: Sat Jul 13 17:38:21 2024 +0800
[feat(bulletin)] add metrics data support and optimize data loading
- Implement new BulletinMetricsData entity to support metrics data.
- Refactor BulletinController to add getAllMetricsData endpoint.
- Optimize data loading in bulletin component by removing unnecessary
search functionality and streamlining data handling.
- Dynamic column generation for metrics data in bulletin tables.
BREAKING CHANGE: The search functionality has been removed from the
bulletin component UI and will require updates to user interactions. The
BulletinController now requires handling of the new BulletinMetricsData entity.
---
.../manager/bulletin/BulletinMetricsData.java | 81 ++++++++++++++++++++++
.../manager/controller/BulletinController.java | 62 +++++++++++++++++
.../app/routes/bulletin/bulletin.component.html | 14 ----
3 files changed, 143 insertions(+), 14 deletions(-)
diff --git
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinMetricsData.java
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinMetricsData.java
new file mode 100644
index 000000000..bdc3230cf
--- /dev/null
+++
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinMetricsData.java
@@ -0,0 +1,81 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with
+ * * this work for additional information regarding copyright ownership.
+ * * The ASF licenses this file to You under the Apache License, Version 2.0
+ * * (the "License"); you may not use this file except in compliance with
+ * * the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ *
+ */
+
+package org.apache.hertzbeat.common.entity.manager.bulletin;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.hertzbeat.common.entity.dto.Field;
+import org.apache.hertzbeat.common.entity.dto.ValueRow;
+
+/**
+ * Bulletin Metrics Data
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Schema(description = "Bulletin Metrics Data")
+public class BulletinMetricsData {
+
+ @Schema(title = "Monitor Type")
+ private String app;
+
+ @Schema(description = "Content Data")
+ private Content content;
+
+ @Data
+ @Builder
+ @AllArgsConstructor
+ @NoArgsConstructor
+ public static class Content{
+ @Schema(title = "Monitor ID")
+ private Long id;
+
+ @Schema(title = "Monitor IP")
+ private String host;
+
+ @Schema(title = "Monitor Metrics")
+ private List<Metric> metrics;
+ }
+
+ @Data
+ @Builder
+ @AllArgsConstructor
+ @NoArgsConstructor
+ @Schema(description = "Metrics Data")
+ public static class Metric{
+ @Schema(title = "Metric type")
+ private String type;
+
+ @Schema(title = "Metric name")
+ private String name;
+
+ @Schema(title = "Metric unit")
+ private String unit;
+
+ @Schema(title = "Metric value")
+ private String value;
+ }
+}
diff --git
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
index 166b3eef0..6e58dedbb 100644
---
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
+++
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
@@ -28,6 +28,7 @@ import jakarta.validation.Valid;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -42,8 +43,10 @@ import org.apache.hertzbeat.common.entity.dto.Value;
import org.apache.hertzbeat.common.entity.dto.ValueRow;
import org.apache.hertzbeat.common.entity.manager.bulletin.Bulletin;
import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinDto;
+import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinMetricsData;
import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinVo;
import org.apache.hertzbeat.common.entity.message.CollectRep;
+import org.apache.hertzbeat.common.util.Pair;
import org.apache.hertzbeat.manager.service.BulletinService;
import org.apache.hertzbeat.warehouse.store.realtime.RealTimeDataReader;
import org.springframework.beans.factory.annotation.Autowired;
@@ -185,5 +188,64 @@ public class BulletinController {
return ResponseEntity.ok(Message.success(dataList));
}
+ @GetMapping("/metrics")
+ @Operation(summary = "Query All Bulletin Real Time Metrics Data",
description = "Query All Bulletin real-time metrics data of monitoring
indicators")
+ public ResponseEntity<Message<List<BulletinMetricsData>>>
getAllMetricsData() {
+ boolean available = realTimeDataReader.isServerAvailable();
+ if (!available) {
+ return ResponseEntity.ok(Message.fail(FAIL_CODE, "real time store
not available"));
+ }
+ List<Bulletin> bulletinList = bulletinService.listBulletin();
+ List<BulletinMetricsData> dataList = new ArrayList<>();
+ for (Bulletin bulletin : bulletinList) {
+ List<String> metricList = bulletin.getMetrics();
+ Map<String, CollectRep.MetricsData> metricsDataMap =
metricList.stream()
+ .collect(Collectors.toMap(
+ metric -> metric,
+ metric -> metric.split("-")[0],
+ (existing, replacement) -> existing
+ ))
+ .values().stream()
+ .distinct()
+ .collect(Collectors.toMap(
+ metric -> metric,
+ metric ->
realTimeDataReader.getCurrentMetricsData(bulletin.getMonitorId(), metric)
+ ));
+
+
+
+ for (Map.Entry<String, CollectRep.MetricsData> entry :
metricsDataMap.entrySet()) {
+ CollectRep.MetricsData storageData = entry.getValue();
+
+ BulletinMetricsData.BulletinMetricsDataBuilder dataBuilder =
BulletinMetricsData.builder();
+ dataBuilder.app(storageData.getApp());
+
+ BulletinMetricsData.Content.ContentBuilder contentBuilder =
BulletinMetricsData.Content.builder();
+ BulletinMetricsData.Metric.MetricBuilder metricBuilder =
BulletinMetricsData.Metric.builder();
+
+ contentBuilder.id(storageData.getId());
+
+ List<BulletinMetricsData.Metric> metrics =
storageData.getFieldsList().stream()
+ .map(tmpField -> metricBuilder
+ .type(entry.getKey().split("-")[0])
+ .name(tmpField.getName())
+ .unit(tmpField.getUnit())
+ .build())
+ .collect(Collectors.toList());
+
+ for (CollectRep.ValueRow valueRow :
storageData.getValuesList()) {
+ for (int i = 0; i < metrics.size(); i++) {
+ BulletinMetricsData.Metric metric = metrics.get(i);
+ String origin = valueRow.getColumns(i);
+ metric.setValue(origin);
+ }
+ }
+ contentBuilder.metrics(metrics);
+ BulletinMetricsData bulletinMetricsData =
dataBuilder.content(contentBuilder.build()).build();
+ dataList.add(bulletinMetricsData);
+ }
+ }
+ return ResponseEntity.ok(Message.success(dataList));
+ }
}
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.html
b/web-app/src/app/routes/bulletin/bulletin.component.html
index 081355aa7..44d82ddc2 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.html
+++ b/web-app/src/app/routes/bulletin/bulletin.component.html
@@ -40,20 +40,6 @@
删除看板项
</button>
</ng-template>
- <ng-template #right>
- <input
- style="width: 200px; text-align: center"
- nz-input
- type="text"
- [placeholder]="'alert.setting.search' | i18n"
- nzSize="default"
- (keyup.enter)="loadBulletinDefineTable()"
- [(ngModel)]="search"
- />
- <button nz-button nzType="primary" (click)="loadBulletinDefineTable()">
- {{ 'common.search' | i18n }}
- </button>
- </ng-template>
</app-toolbar>
<nz-tabset nzType="card">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]