aboutsummaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorVratko Polak <vrpolak@cisco.com>2021-06-24 19:40:38 +0200
committerVratko Polak <vrpolak@cisco.com>2021-06-24 19:40:38 +0200
commitfd59d7ff012291f27e9ad2cd6ca863d8307f9104 (patch)
tree7a14a9b3fb5f32c4cb3f43677d6a510940c6f000 /resources
parent39001a2af7f465bb97e21747db749ff3e44ebbd4 (diff)
Metrics: Fix timestamps, they were not epoch
Library documentation [0] says this about monotonic(): The reference point of the returned value is undefined, so that only the difference between the results of two calls is valid. Switching to time(). [0] https://docs.python.org/3/library/time.html Change-Id: Ia7ef8d89119f7dc72619cac44b213611163ff054 Signed-off-by: Vratko Polak <vrpolak@cisco.com>
Diffstat (limited to 'resources')
-rw-r--r--resources/tools/telemetry/metrics.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/resources/tools/telemetry/metrics.py b/resources/tools/telemetry/metrics.py
index e5a66b3e0c..281760183b 100644
--- a/resources/tools/telemetry/metrics.py
+++ b/resources/tools/telemetry/metrics.py
@@ -11,11 +11,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Metric library."""
+"""Metric library.
+
+Time measurements are done by time.time().
+Although time.time() is susceptible to big (or even negative) jumps
+when a system is badly synchronized, it is still better
+than time.monotonic(), as that value has no relation to epoch time.
+"""
from collections import namedtuple
from threading import Lock
-from time import monotonic
+from time import time
import re
@@ -41,7 +47,7 @@ class Value:
"""
with self._lock:
self._value += amount
- self._timestamp = monotonic()
+ self._timestamp = time()
def set(self, value):
"""
@@ -53,7 +59,7 @@ class Value:
"""
with self._lock:
self._value = value
- self._timestamp = monotonic()
+ self._timestamp = time()
def get(self):
"""
@@ -616,4 +622,4 @@ class Info(MetricBase):
:rtype: tuple
"""
with self._lock:
- return ((u"_info", self._value, 1.0, monotonic()),)
+ return ((u"_info", self._value, 1.0, time()),)