mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-19 22:58:08 +01:00
Add a shutdown monitor that publishes shutdown state as a metric
This commit is contained in:
committed by
Jon Chambers
parent
758900b7a8
commit
ce7d687205
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2013-2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws Exception {
|
||||
shuttingDown.set(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
shuttingDown.set(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user