pub struct HealthState {
ticks: AtomicU64,
last_tick_unix: AtomicI64,
started_unix: i64,
certificates: OnceLock<Arc<dyn CertificateAlerts>>,
data_dir: OnceLock<(PathBuf, DiskWatermarks)>,
disk_alert: AtomicU8,
}Expand description
The tick’s pulse, shared with whoever answers GET /health.
Kept separate from HealthTick itself so a caller can hand the state to
the HTTP router and the join handle to nothing but the shutdown path —
the router has no business awaiting the task or aborting it, only reading
the counters.
Fields§
§ticks: AtomicU64How many ticks have fired since the process started.
last_tick_unix: AtomicI64Unix seconds of the most recent tick, or 0 for “never yet” — the
first tick fires one interval after startup, by design; see
HealthTick::spawn.
started_unix: i64Unix seconds this state was created, which is startup for all
practical purposes: it is built and handed to HealthTick::spawn
in the same breath the tick task is.
certificates: OnceLock<Arc<dyn CertificateAlerts>>Whoever can answer for the certificates, once there is one — see
HealthState::attach_certificates for why this is filled in after
the router is already serving rather than passed to the constructor.
data_dir: OnceLock<(PathBuf, DiskWatermarks)>The data directory whose volume HealthState::disk reads, and
the watermarks its free space is measured against; see
HealthState::attach_data_dir.
disk_alert: AtomicU8The DiskAlert the last tick read, as its u8: ok before one
has.
Implementations§
Source§impl HealthState
impl HealthState
Sourcefn record_tick(&self)
fn record_tick(&self)
Records that a tick just fired.
Sourcepub fn attach_certificates(&self, alerts: Arc<dyn CertificateAlerts>)
pub fn attach_certificates(&self, alerts: Arc<dyn CertificateAlerts>)
Names who can answer for the certificates.
Separate from HealthState::new because of the order the binary
builds things in: the router — and this state with it — exists before
the ACME fleet does, since the fleet is bootstrapped by the code that
is handed the finished router to serve. The first call wins and later
ones are ignored, so a second fleet cannot quietly replace the one the
listener is actually serving certificates from.
Sourcepub fn attach_data_dir(&self, dir: PathBuf, watermarks: DiskWatermarks)
pub fn attach_data_dir(&self, dir: PathBuf, watermarks: DiskWatermarks)
Names the data directory whose volume HealthState::disk reads,
and the watermarks its free space is measured against.
The first call wins, as it does for
HealthState::attach_certificates. A state nothing names has no
volume to read, which is every in-memory run.
Sourcepub async fn disk(&self) -> Option<DiskHealth>
pub async fn disk(&self) -> Option<DiskHealth>
The data volume’s free and total bytes, read as this is called.
Read on the blocking pool, because statvfs asks the filesystem, and
a volume that has stopped answering must not hold an async worker.
None when no data directory was named, and when the read fails,
which is logged.
Sourcepub(crate) fn watch_disk(&self, disk: &DiskHealth) -> Option<DiskAlert>
pub(crate) fn watch_disk(&self, disk: &DiskHealth) -> Option<DiskAlert>
Writes a line when disk has crossed a watermark since the last
reading: warn going down, info coming back up. A first reading
below a watermark is a crossing. Answers the alert it wrote about.
Sourcepub async fn certificates(&self) -> CertificateHealth
pub async fn certificates(&self) -> CertificateHealth
The certificate half of the health response.
async, and so kept out of HealthState::snapshot: the levels are
read from the renewal trackers themselves rather than from a copy
something has to remember to refresh, which is what makes a warning
in this response and a warning in the log the same fact.
Sourcepub fn snapshot(&self) -> HealthSnapshot
pub fn snapshot(&self) -> HealthSnapshot
A point-in-time read, safe to serialize into an HTTP response.
Trait Implementations§
Source§impl Debug for HealthState
impl Debug for HealthState
Source§impl Default for HealthState
impl Default for HealthState
Source§fn default() -> HealthState
fn default() -> HealthState
Auto Trait Implementations§
impl !Freeze for HealthState
impl !RefUnwindSafe for HealthState
impl Send for HealthState
impl Sync for HealthState
impl Unpin for HealthState
impl UnsafeUnpin for HealthState
impl !UnwindSafe for HealthState
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more