museumsvictoria/nodel

Start uptime can be misleading if start timestamp was inaccurate

justparking opened this issue · 0 comments

When nodel first starts up it records a start timestamp and is labelled as part of the Uptime field in when presented in /diagnostics.xml:
image

The data it uses is this, from /REST/diagnostics

"startTime": "2022-06-30T09:45:40.933+10:00",

A problem can arise when the clock that it relies on (wall clock) is inaccurate so the start time (and calculated uptime) can be misleading. A particularly bad scenario is where the controller doesn't use batteries so the start time can be wildly inaccurate and show a time based on when it was last powered on. If someone relied on that value it would not be something

Having a dependable uptime is very important so I propose that in addition to storing the startTime, an actual uptime field is stored too which it simply milliseconds since start up. In Java terms it'd be calculated similar to this:

  public final static long s_startInstant = System.nanoTime();

  public static long getUptimeMillis() {
    return (System.nanoTime() - s_startInstant())  / 1000000;
  }

Note: the original startTime should remain as its presence or obvious inaccuracy can reveal useful information about a given system.