From b52c642414946ba252ac67494a7343f88c59fc08 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 9 Aug 2023 11:39:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=97=B6=EF=BC=8C=E8=BE=93=E5=85=A5promQL?= =?UTF-8?q?=E4=B8=AD=E5=8C=85=E6=8B=AC=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8=E4=BD=BF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1028478 --user=刘瑞斌 【性能测试】github#26031,【性能测试】监控磁盘IO使用率,在prometheus页面使用promQL语句(读+写之和)可以正常查询到,将表达式放到MS监控里,没有监控数据出现 https://www.tapd.cn/55049933/s/1402006 --- .../service/MetricQueryService.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/performance-test/backend/src/main/java/io/metersphere/service/MetricQueryService.java b/performance-test/backend/src/main/java/io/metersphere/service/MetricQueryService.java index f7851c5b55..e1afe8f923 100644 --- a/performance-test/backend/src/main/java/io/metersphere/service/MetricQueryService.java +++ b/performance-test/backend/src/main/java/io/metersphere/service/MetricQueryService.java @@ -17,11 +17,14 @@ import io.metersphere.request.MetricRequest; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; -import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.*; import java.util.stream.Collectors; @@ -82,8 +85,18 @@ public class MetricQueryService { String start = df.format(startTime / 1000.0); String end = df.format(endTime / 1000.0); try { - Map response = restTemplate.getForObject(prometheusHost + "/api/v1/query_range?query={promQL}&start={start}&end={end}&step={step}", Map.class, promQL, start, end, step); - LogUtil.info(prometheusHost + "/api/v1/query_range?query={" + promQL + "}&start={" + start + "}&end{" + end + "}&step={" + step + "}"); + LogUtil.debug(prometheusHost + "/api/v1/query_range?query=" + promQL + "&start=" + start + "&end" + end + "&step=" + step); + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + // 设置请求参数 + MultiValueMap postParameters = new LinkedMultiValueMap<>(); + postParameters.add("query", promQL); + postParameters.add("start", start); + postParameters.add("end", end); + postParameters.add("step", step); + HttpEntity> httpEntity = new HttpEntity<>(postParameters, headers); + + Map response = restTemplate.postForObject(prometheusHost + "/api/v1/query_range", httpEntity, Map.class); metricData = handleResult(seriesName, response, instance); } catch (Exception e) { LogUtil.error("query prometheus metric fail.");