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.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(CpuUsageGauge.class, "cpu"), new CpuUsageGauge(3, TimeUnit.SECONDS));
|
||||||
environment.metrics().register(name(FreeMemoryGauge.class, "free_memory"), new FreeMemoryGauge());
|
environment.metrics().register(name(FreeMemoryGauge.class, "free_memory"), new FreeMemoryGauge());
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
|
|
||||||
package org.whispersystems.textsecuregcm.metrics;
|
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 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
|
* 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.
|
* 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);
|
private final AtomicBoolean shuttingDown = new AtomicBoolean(false);
|
||||||
|
|
||||||
public ApplicationShutdownMonitor() {
|
public ApplicationShutdownMonitor(final MeterRegistry meterRegistry) {
|
||||||
Metrics.gauge(name(getClass().getSimpleName(), "shuttingDown"), shuttingDown, b -> b.get() ? 1 : 0);
|
// 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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue