Skip to content
This repository was archived by the owner on Dec 23, 2017. It is now read-only.

Commit 1c2407a

Browse files
author
Jochen Schalanda
committed
Base node uptime calulation on System#nanoTime()
Previously, the uptime of a Graylog node has been calculated using the difference between the start time and the current time. If the system time changed during the runtime of the node (e. g. by synchronisation using an NTP service), the uptime would be incorrect and could even be negative. The current implementation is using the System#nanoTime() ticker to calculate the uptime since the JVM (or more precisely: since the plugin) has been started.
1 parent c20316c commit 1c2407a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/org/graylog/plugins/usagestatistics/collectors/NodeCollector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757

5858
@Singleton
5959
public class NodeCollector {
60+
private static final long JVM_START = System.nanoTime();
61+
6062
private final NodeId nodeId;
6163
private final ServerStatus serverStatus;
6264
private final MetricRegistry metricRegistry;
@@ -182,7 +184,7 @@ private JvmInfo buildJvmSpecs() {
182184
}
183185

184186
private NodeStats buildNodeStats() {
185-
final long uptime = Tools.iso8601().getMillis() - serverStatus.getStartedAt().getMillis();
187+
final long uptime = (System.nanoTime() - JVM_START) / 1_000_000L;
186188
final ThroughputStats throughputStats = ThroughputStats.create(
187189
ThroughputStats.Throughput.create(
188190
MetricUtils.safeGetCounter(metricRegistry, "org.graylog2.throughput.input").getCount(),

0 commit comments

Comments
 (0)