Skip to content

Commit

Permalink
update museumsvictoria#258: Uptime can be misleading if start timesta…
Browse files Browse the repository at this point in the history
…mp is inaccurate

Update thanks to automatic.com.au
  • Loading branch information
justparking authored and scroix committed Apr 1, 2024
1 parent 17606a5 commit ea291af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ public class Diagnostics {
private final static int PERIOD = 2500;

/**
* Start time.
* Start time based on the system wall clock time timestamp
*/
private DateTime _startTime = DateTime.now();


/**
* The start instant of the framework used for uptime unaffected by wall clock accuracy
* (.nanoTime based, public for convenience)
*/
public final static long START_INSTANT = System.nanoTime();

/**
* The permanent non-daemon thread to keep track of the counters.
* (may not be started in thread-restricted environments)
Expand Down Expand Up @@ -128,11 +134,16 @@ public void run() {
_logger.info("Environment dump: {}", Serialisation.serialise(this));
} // (init)

@Value(name="startTime", title = "Start time", desc = "When this service was started.")
@Value(name="startTime", title = "Start time", desc = "When this service was started according to system's wall clock.")
public DateTime startTime() {
return _startTime;
}


@Value(name="uptime", title = "Uptime", desc = "Uptime in milliseconds unaffected by wall clock accuracy.")
public long uptime() {
return (System.nanoTime() - START_INSTANT) / 1000000;
}

@Value(name = "systemProperties", title = "System properties", desc = "The list of built-in system properties.")
public Properties properties() {
return System.getProperties();
Expand Down
2 changes: 1 addition & 1 deletion nodel-webui-js/src/index.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@
</tr>
<tr>
<th scope="row">Uptime</th>
<td>{{>~fromtime(startTime)}}, started {{>~nicetime(startTime, false, 'llll')}}</td>
<td>{{>~fromtime(uptime)}}, start timestamp {{>~nicetime(startTime, false, 'llll')}}</td>
</tr>
<tr>
<th scope="row">Host path</th>
Expand Down
8 changes: 6 additions & 2 deletions nodel-webui-js/src/nodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ $.views.helpers({
if (format) return moment(value).format(format);
else return moment(value).format('Do MMM, h:mm a');
},
fromtime: function(value){
return moment(value).from(moment(), true);
fromtime: function(value) {
now = moment();
if (typeof(value) == 'string') // treat value as an absolute timestamp
return moment(value).from(now, true);
else // treat value as a duration in millis
return moment(now).subtract(value, 'ms').from(now, true);
},
srcflt: function(item, i, items) {
if(this.view.data.flt) {
Expand Down

0 comments on commit ea291af

Please sign in to comment.