X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Ftelemetry%2Fmetrics.py;h=7a22acfd1b26eb53751732f8e6afa3bde24e38fe;hb=refs%2Fchanges%2F09%2F35709%2F13;hp=e5a66b3e0cde34d4241ca1a301cd5d802c3a69d3;hpb=d255d2545ee6cdc871bc35314fad72c3c48b225b;p=csit.git diff --git a/resources/tools/telemetry/metrics.py b/resources/tools/telemetry/metrics.py index e5a66b3e0c..7a22acfd1b 100644 --- a/resources/tools/telemetry/metrics.py +++ b/resources/tools/telemetry/metrics.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2022 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -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): """ @@ -334,7 +340,7 @@ class MetricBase: def samples(self): """ - Returns samples wheter an object is parent or child. + Returns samples whether an object is parent or child. :returns: List of Metric objects with values. :rtype: list @@ -596,9 +602,9 @@ class Info(MetricBase): """ Set info to the given value. - :param amount: Value to set. - :type amount: int or float - :raises ValueError: If lables are overlapping. + :param value: Value to set. + :type value: int or float + :raises ValueError: If labels are overlapping. """ if self._labelname_set.intersection(value.keys()): raise ValueError( @@ -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()),)