Class Health

java.lang.Object
net.targetr.rc.monitoring.health.Health

public class Health extends Object
Monitors the server health and stores a history of stats.
Author:
Dr Michael Gardiner
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum number of stats to store in history.
    static final int
    The sleep duration between stat collections.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs the Health monitor and starts the monitoring thread.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addTimeOffset(HealthStat stat, long time)
    Converts the absolute timestamp of a stat into an offset relative to the current time.
    static Health
    get()
    Gets the singleton instance of the Health monitor.
    static HealthStat
    getChanges(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.
    Retrieves the most recently collected health stat.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STAT_PERIOD

      public static final int STAT_PERIOD
      The sleep duration between stat collections.
      See Also:
    • MAX_HISTORY_SIZE

      public static final int MAX_HISTORY_SIZE
      The maximum number of stats to store in history.
      See Also:
  • Constructor Details

    • Health

      public Health()
      Constructs the Health monitor and starts the monitoring thread.
  • Method Details

    • get

      public static Health get()
      Gets the singleton instance of the Health monitor.
      Returns:
      the health monitor instance
    • getRecent

      public HealthStat getRecent()
      Retrieves the most recently collected health stat.
      Returns:
      a HealthStat object containing the latest server stats
    • getHistory

      public List<HealthStat> 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

      public static void addTimeOffset(HealthStat stat, long time)
      Converts the absolute timestamp of a stat into an offset relative to the current time.
      Parameters:
      stat - the stat to update
      time - the current time against which to calculate the offset
    • getChanges

      public static HealthStat getChanges(HealthStat oldState, HealthStat newState)
      Calculates the differences between an old health state and a new one.
      Parameters:
      oldState - the previous state
      newState - the current state
      Returns:
      a HealthStat containing only the fields that have changed