Set the timestamps by using the absolute epoch time in milliseconds
(i.e., ms from the Epoch):
System.currentTimeMillis()
The previous solution System.nanoTime() starts from a fixed, but
arbitrary time and cannot be used to compare timestamps across
different systems.
For now, the System.currentTimeMillis() granularity should be good enough
for end-to-end measurements.
In the follow-up iterations, if we need breakdown of the execution path
on a single machine, we can utilize System.nanoTime() if necessary.
As part of the update, the names of the timestamp metrics are now updated
to include ".EpochMs" suffix:
"Topology.EventNotification.LastEventTimestamp" ->
"Topology.EventNotification.LastEventTimestamp.EpochMs"
"Intents.AddOperation.BeginOperationTimestamp" ->
"Intents.AddOperation.BeginOperationTimestamp.EpochMs"
"Intents.AddOperation.EndOperationTimestamp" ->
"Intents.AddOperation.EndOperationTimestamp.EpochMs"
"Intents.RemoveOperation.BeginOperationTimestamp" ->
"Intents.RemoveOperation.BeginOperationTimestamp.EpochMs"
"Intents.RemoveOperation.EndOperationTimestamp" ->
"Intents.RemoveOperation.EndOperationTimestamp.EpochMs"
Change-Id: I9ebf067bb8aa8055fd445781213ca741b5df5e74
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
index aeb06c2..dccef16 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
@@ -81,16 +81,16 @@
private static final MetricsFeature METRICS_FEATURE_EVENT_NOTIFICATION =
METRICS_COMPONENT.registerFeature("EventNotification");
//
- // Timestamp of the last Topology event (system nanoseconds)
- private volatile long lastEventTimestamp = 0;
- private final Gauge<Long> gaugeLastEventTimestamp =
+ // Timestamp of the last Topology event (ms from the Epoch)
+ private volatile long lastEventTimestampEpochMs = 0;
+ private final Gauge<Long> gaugeLastEventTimestampEpochMs =
OnosMetrics.registerMetric(METRICS_COMPONENT,
METRICS_FEATURE_EVENT_NOTIFICATION,
- "LastEventTimestamp",
+ "LastEventTimestamp.EpochMs",
new Gauge<Long>() {
@Override
public Long getValue() {
- return lastEventTimestamp;
+ return lastEventTimestampEpochMs;
}
});
// Rate of the Topology events published to the Topology listeners
@@ -506,14 +506,14 @@
apiAddedLinkEvents.size() + apiRemovedLinkEvents.size() +
apiAddedHostEvents.size() + apiRemovedHostEvents.size();
this.listenerEventRate.mark(totalEvents);
- this.lastEventTimestamp = System.nanoTime();
+ this.lastEventTimestampEpochMs = System.currentTimeMillis();
//
// Deliver the events
//
for (ITopologyListener listener : this.topologyListeners) {
TopologyEvents events =
- new TopologyEvents(lastEventTimestamp,
+ new TopologyEvents(lastEventTimestampEpochMs,
kryo.copy(apiAddedSwitchEvents),
kryo.copy(apiRemovedSwitchEvents),
kryo.copy(apiAddedPortEvents),