|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.jjt.biz.service.IPrometheusService;
|
|
|
import com.jjt.common.core.redis.RedisCache;
|
|
|
+import com.jjt.common.utils.StringUtils;
|
|
|
import com.jjt.common.utils.http.HttpUtils;
|
|
|
import com.jjt.system.service.ISysConfigService;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -11,7 +12,6 @@ import org.yaml.snakeyaml.util.UriEncoder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.DecimalFormat;
|
|
|
-import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
* 告警记录Service业务层处理
|
|
@@ -34,6 +34,7 @@ public class PrometheusServiceImpl implements IPrometheusService {
|
|
|
private String baseUri() {
|
|
|
return configService.selectConfigByKey("pm.url");
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 即时查询
|
|
|
*
|
|
@@ -42,20 +43,23 @@ public class PrometheusServiceImpl implements IPrometheusService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Float query(String param) {
|
|
|
- float v = 0f;
|
|
|
- String uri = baseUri() + "/api/v1/query?query=";
|
|
|
- uri += UriEncoder.encode(param);
|
|
|
- String result = HttpUtils.sendGet(uri);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- JSONArray array = jsonObject.getJSONObject("data").getJSONArray("result");
|
|
|
- try {
|
|
|
- JSONArray value = array.getJSONObject(0).getJSONArray("value");
|
|
|
- DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
- v = Float.parseFloat(df.format(value.getFloat(1)));
|
|
|
+ if (StringUtils.isNotEmpty(param)) {
|
|
|
|
|
|
- } catch (Exception ignored) {
|
|
|
+ String uri = baseUri() + "/api/v1/query?query=";
|
|
|
+ uri += UriEncoder.encode(param);
|
|
|
+ String result = HttpUtils.sendGet(uri);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ JSONArray array = jsonObject.getJSONObject("data").getJSONArray("result");
|
|
|
+ try {
|
|
|
+ JSONArray value = array.getJSONObject(0).getJSONArray("value");
|
|
|
+ DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
+ return Float.parseFloat(df.format(value.getFloat(1)));
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
}
|
|
|
- return v;
|
|
|
}
|
|
|
|
|
|
/**
|