Use a strong reference to the application shutdown gauge
This commit is contained in:
parent
31e2be2e4d
commit
a2c4d3fe95
|
@ -727,7 +727,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
|||
|
||||
environment.healthChecks().register("cacheCluster", new RedisClusterHealthCheck(cacheCluster));
|
||||
|
||||
environment.lifecycle().manage(new ApplicationShutdownMonitor());
|
||||
environment.lifecycle().manage(new ApplicationShutdownMonitor(Metrics.globalRegistry));
|
||||
|
||||
environment.metrics().register(name(CpuUsageGauge.class, "cpu"), new CpuUsageGauge(3, TimeUnit.SECONDS));
|
||||
environment.metrics().register(name(FreeMemoryGauge.class, "free_memory"), new FreeMemoryGauge());
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
|
||||
package org.whispersystems.textsecuregcm.metrics;
|
||||
|
||||
import io.dropwizard.lifecycle.Managed;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.codahale.metrics.MetricRegistry.name;
|
||||
|
||||
import io.dropwizard.lifecycle.Managed;
|
||||
import io.micrometer.core.instrument.Gauge;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* A managed monitor that reports whether the application is shutting down as a metric. That metric can then be used in
|
||||
* conjunction with other indicators to conditionally fire or suppress alerts.
|
||||
|
@ -19,8 +21,12 @@ public class ApplicationShutdownMonitor implements Managed {
|
|||
|
||||
private final AtomicBoolean shuttingDown = new AtomicBoolean(false);
|
||||
|
||||
public ApplicationShutdownMonitor() {
|
||||
Metrics.gauge(name(getClass().getSimpleName(), "shuttingDown"), shuttingDown, b -> b.get() ? 1 : 0);
|
||||
public ApplicationShutdownMonitor(final MeterRegistry meterRegistry) {
|
||||
// without a strong reference to the gauge’s value supplier, shutdown garbage collection
|
||||
// might prevent the final value from being reported
|
||||
Gauge.builder(name(getClass().getSimpleName(), "shuttingDown"), () -> shuttingDown.get() ? 1 : 0)
|
||||
.strongReference(true)
|
||||
.register(meterRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue