Package net.targetr.rc.monitoring.health
Class Health
java.lang.Object
net.targetr.rc.monitoring.health.Health
Monitors the server health and stores a history of stats.
- Author:
- Dr Michael Gardiner
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHistory pruning threshold; the next sample is appended after pruning.static final intSleep duration in milliseconds between stat collections. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddTimeOffset(HealthStat stat, long time) Replaces a sample's monotonictimewithtimeOffsetin milliseconds.static Healthget()Gets the singleton instance of the Health monitor.static HealthStatgetChanges(HealthStat oldState, HealthStat newState) Calculates the differences between an old health state and a new one.Retrieves the history of health stats, structured as initial state and subsequent differences.Returns a copy of the latest sample, waiting for the first sample if necessary.
-
Field Details
-
STAT_PERIOD
public static final int STAT_PERIODSleep duration in milliseconds between stat collections.- See Also:
-
MAX_HISTORY_SIZE
public static final int MAX_HISTORY_SIZEHistory pruning threshold; the next sample is appended after pruning.- See Also:
-
-
Constructor Details
-
Health
public Health()Constructs the Health monitor and starts the monitoring thread.
-
-
Method Details
-
get
Gets the singleton instance of the Health monitor.- Returns:
- the health monitor instance
-
getRecent
Returns a copy of the latest sample, waiting for the first sample if necessary.- Returns:
- latest metrics with a millisecond timeOffset relative to retrieval
-
getHistory
Retrieves the history of health stats, structured as initial state and subsequent differences.- Returns:
- a list of HealthStat objects representing the changes over time
-
addTimeOffset
Replaces a sample's monotonictimewithtimeOffsetin milliseconds.- Parameters:
stat- the stat to updatetime- reference time inClock.realtime()milliseconds
-
getChanges
Calculates the differences between an old health state and a new one.- Parameters:
oldState- the previous statenewState- the current state- Returns:
- a HealthStat containing only the fields that have changed
-