diff options
Diffstat (limited to 'src/main/java/com/nis/job/ConfagentJob.java')
| -rw-r--r-- | src/main/java/com/nis/job/ConfagentJob.java | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/main/java/com/nis/job/ConfagentJob.java b/src/main/java/com/nis/job/ConfagentJob.java index 1823e14..6d1194c 100644 --- a/src/main/java/com/nis/job/ConfagentJob.java +++ b/src/main/java/com/nis/job/ConfagentJob.java @@ -1,6 +1,7 @@ package com.nis.job; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.log.Log; @@ -141,13 +142,12 @@ public class ConfagentJob extends QuartzJobBean { RestTemplate restTemplate = new RestTemplate(); // responseEntity = restTemplate.postForEntity(String.format("%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD), null, String.class); int port= Integer.parseInt(promServerPort); - String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + //String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + String url = UrlBuilder.create().setScheme("http").setHost(ipaddr).setPort(port).appendPath(Constant.API_RELOAD).toString(); responseEntity = ReflectUtil.invoke(restTemplate, "postForEntity", url, null, String.class, Collections.emptyMap()); } catch (RestClientException e) { logger.error("热加载 global prometheus api 接口失败,API 地址是:" + String.format("%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e); - } catch (MalformedURLException e) { - logger.error(e); - } + } if (responseEntity != null && responseEntity.getStatusCodeValue() == 200) { logger.info(String.format("%s:%s", ipaddr, promServerPort) + " global prometheus 热加载配置文件成功"); @@ -172,13 +172,12 @@ public class ConfagentJob extends QuartzJobBean { RestTemplate restTemplate = new RestTemplate(); // responseEntity = ReflectUtil.invoke(restTemplate,"postForEntity",new UrlBuilder().setScheme("http").setHost(ipaddr).setPort(port).addPath(Constant.API_RELOAD).toString(), null, String.class);; int port= Integer.parseInt(promServerPort); - String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + //String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + String url = UrlBuilder.create().setScheme("http").setHost(ipaddr).setPort(port).appendPath(Constant.API_RELOAD).toString(); responseEntity = ReflectUtil.invoke(restTemplate, "postForEntity", url, null, String.class, Collections.emptyMap()); } catch (RestClientException e) { logger.error("热加载 per-datacenter prometheus api 接口失败,API 地址是:" + String.format("%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e); - } catch (MalformedURLException e) { - logger.error(e); - } + } if (responseEntity != null && responseEntity.getStatusCodeValue() == 200) { logger.info(String.format("%s:%s", ipaddr, promServerPort) + " per datacenter prometheus 热加载配置文件成功"); } @@ -240,13 +239,12 @@ public class ConfagentJob extends QuartzJobBean { try { RestTemplate restTemplate = new RestTemplate(); int port= Integer.parseInt(promServerPort); - String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + //String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + String url = UrlBuilder.create().setScheme("http").setHost(ipaddr).setPort(port).appendPath(Constant.API_RELOAD).toString(); responseEntity = ReflectUtil.invoke(restTemplate, "postForEntity", url, null, String.class, Collections.emptyMap()); } catch (RestClientException e) { logger.error("热加载 thanos rule api 接口失败,API 地址是:" + String.format("%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e); - } catch (MalformedURLException e) { - logger.error(e); - } + } if (responseEntity != null && responseEntity.getStatusCodeValue() == 200) { logger.info(String.format("%s:%s", ipaddr, promServerPort) + " thanos rule 热加载配置文件成功"); } @@ -413,13 +411,12 @@ public class ConfagentJob extends QuartzJobBean { RestTemplate restTemplate = new RestTemplate(); // responseEntity = restTemplate.postForEntity(String.format("%s:%s%s", ipaddr, snmpPort, Constant.API_RELOAD), null, String.class); int port = Integer.parseInt(snmpPort); - String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + //String url = new URL("http", ipaddr, port, Constant.API_RELOAD).toString(); + String url = UrlBuilder.create().setScheme("http").setHost(ipaddr).setPort(port).appendPath(Constant.API_RELOAD).toString(); responseEntity = ReflectUtil.invoke(restTemplate, "postForEntity", url, null, String.class, Collections.emptyMap()); } catch (RestClientException e) { logger.error("热加载 snmp_exporter api 接口失败,API 地址是:" + String.format("%s:%s%s", ipaddr, snmpPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e); - } catch (MalformedURLException e) { - logger.error(e); - } + } if (responseEntity != null && responseEntity.getStatusCodeValue() == 200) { logger.info(String.format("%s:%s", ipaddr, snmpPort) + " snmp_exporter 热加载配置文件成功"); } |
