我有一个带有Soap Client的Spring Boot应用程序,它正在检查某些应用程序是否还存在。 如果该应用程序仍在运行,则将压力表设置为1,否则将其设置为0。 问题是,当我启动应用程序并发送请求且响应正常时,我在普罗米修斯中看到测量值是1,但是当我停止服务器并发送另一个请求时,我希望测量值应该为0,但又是1。
这是我的代码。我也尝试过使用原子整数,但是仍然存在问题。
@Autowired
MeterRegistry meterRegistry;
public void callWebService() throws IOException {
String request = "message";
List<String> list = convertUsingJava8(url);
for (String string : list) {
// AtomicInteger n = meterRegistry.gauge(string, new AtomicInteger(0));
// Gauge shit = Gauge.build().name(string).help("shit").register();
StringEntity stringEntity;
stringEntity = new StringEntity(request, "UTF-8");
stringEntity.setChunked(true);
HttpPost httpPost = new HttpPost(string);
httpPost.setEntity(stringEntity);
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
HttpResponse response = null;
response = httpClient.execute(httpPost);
StringBuilder total = getMessage(response);
System.out.println(total.toString());
if (total.toString().contains("true")) {
// shit.set(1.0);
// meterRegistry.counter(string).increment();
meterRegistry.gauge(string, 1);
// n.getAndSet(1);
// System.out.println(n);
// meterRegistry.gauge(string, 1);
}
} catch (IOException e) {
System.gc();
meterRegistry.gauge(string, 0);
// shit.set(0.0);
// n.getAndSet(0);
// System.out.println(n);
// meterRegistry.gauge(string, 0);
e.getMessage();
}
}
}