Skip to content

Commit c480d63

Browse files
authored
[PR] [bugfix] Set the prometheus monitoring time and correct historical da… (apache#3264)
1 parent ce479c6 commit c480d63

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/prometheus/PrometheusAutoCollectImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ private void validateParams(Metrics metrics) throws Exception {
156156
}
157157

158158
private List<CollectRep.MetricsData> parseResponseByPrometheusExporter(InputStream inputStream, CollectRep.MetricsData.Builder builder) throws IOException {
159+
long endTime = System.currentTimeMillis();
160+
builder.setTime(endTime);
159161
Map<String, MetricFamily> metricFamilyMap = OnlineParser.parseMetrics(inputStream);
160162
List<CollectRep.MetricsData> metricsDataList = new LinkedList<>();
161163
if (metricFamilyMap == null) {

hertzbeat-warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/history/jpa/JpaDatabaseDataStorage.java

+3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ public Map<String, List<Value>> getHistoryMetricData(Long monitorId, String app,
201201
List<Predicate> andList = new ArrayList<>();
202202
Predicate predicateMonitorId = criteriaBuilder.equal(root.get("monitorId"), monitorId);
203203
Predicate predicateMonitorType = criteriaBuilder.equal(root.get("app"), app);
204+
if (CommonConstants.PROMETHEUS.equals(app)) {
205+
predicateMonitorType = criteriaBuilder.like(root.get("app"), CommonConstants.PROMETHEUS_APP_PREFIX + "%");
206+
}
204207
Predicate predicateMonitorMetrics = criteriaBuilder.equal(root.get("metrics"), metrics);
205208
Predicate predicateMonitorMetric = criteriaBuilder.equal(root.get("metric"), metric);
206209
andList.add(predicateMonitorId);

0 commit comments

Comments
 (0)