Bam*_*bus 5 java spring-boot prometheus micrometer
我有带有肥皂客户端的 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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
743 次 |
| 最近记录: |