aria.ops.data

 1#  Copyright 2022 VMware, Inc.
 2#  SPDX-License-Identifier: Apache-2.0
 3from __future__ import annotations
 4
 5import time
 6from typing import Optional
 7from typing import Union
 8
 9
10class Metric:
11    """Class representing a Metric Data Point.
12
13    Metrics are numeric values that represent data at a particular point in time. These are stored as time series data.
14    Examples:
15        CPU Utilization
16        Disk Capacity
17        Current User Session Count
18        Cumulative Data Received
19    """
20
21    def __init__(self, key: str, value: float, timestamp: Optional[int] = None):
22        """Creates a Metric
23
24        :param key: A string representing the type of metric. TODO: Describe how Keys work.
25        :param value: The value of the Metric. Must be type float.
26        :param timestamp: Time in milliseconds since the Epoch when this metric value was recorded.
27            Defaults to the current time.
28        """
29        self.key = key
30        self.value = value
31
32        if timestamp is None:
33            self.timestamp = int(time.time() * 1000)
34        else:
35            self.timestamp = timestamp
36
37    def get_json(self) -> dict:
38        """Get a JSON representation of this Metric.
39
40        Returns a JSON representation of this Metric in the format required by vROps.
41
42        :return: A JSON representation of this Metric.
43        """
44        return {
45            "key": self.key,
46            "numberValue": float(self.value),
47            "timestamp": self.timestamp,
48        }
49
50
51class Property:
52    """Class representing a Property value.
53
54    A Property is a value, usually a string, that will change infrequently or not at all. Only the current value is
55    important.
56    Examples:
57        IP Address
58        Software Version
59        CPU Core Count
60    """
61
62    def __init__(
63        self, key: str, value: Union[float, str], timestamp: Optional[int] = None
64    ):
65        """Creates a Property.
66
67        :param key: A string representing the type of property. TODO: Describe how Keys work.
68        :param value: The value of the property. Can be str or float.
69        :param timestamp: Time in milliseconds since the Epoch when this property value was recorded.
70            Defaults to the current time.
71        """
72        self.key = key
73        self.value = value
74
75        if timestamp is None:
76            self.timestamp = int(time.time() * 1000)
77        else:
78            self.timestamp = timestamp
79
80    def get_json(self) -> dict:
81        """Get a JSON representation of this Property.
82
83        Returns a JSON representation of this Property in the format required by vROps.
84
85        :return: A JSON representation of this Property.
86        """
87        if isinstance(self.value, str):
88            label = "stringValue"
89        else:
90            label = "numberValue"
91            self.value = float(self.value)
92
93        return {"key": self.key, label: self.value, "timestamp": self.timestamp}
class Metric:
11class Metric:
12    """Class representing a Metric Data Point.
13
14    Metrics are numeric values that represent data at a particular point in time. These are stored as time series data.
15    Examples:
16        CPU Utilization
17        Disk Capacity
18        Current User Session Count
19        Cumulative Data Received
20    """
21
22    def __init__(self, key: str, value: float, timestamp: Optional[int] = None):
23        """Creates a Metric
24
25        :param key: A string representing the type of metric. TODO: Describe how Keys work.
26        :param value: The value of the Metric. Must be type float.
27        :param timestamp: Time in milliseconds since the Epoch when this metric value was recorded.
28            Defaults to the current time.
29        """
30        self.key = key
31        self.value = value
32
33        if timestamp is None:
34            self.timestamp = int(time.time() * 1000)
35        else:
36            self.timestamp = timestamp
37
38    def get_json(self) -> dict:
39        """Get a JSON representation of this Metric.
40
41        Returns a JSON representation of this Metric in the format required by vROps.
42
43        :return: A JSON representation of this Metric.
44        """
45        return {
46            "key": self.key,
47            "numberValue": float(self.value),
48            "timestamp": self.timestamp,
49        }

Class representing a Metric Data Point.

Metrics are numeric values that represent data at a particular point in time. These are stored as time series data. Examples: CPU Utilization Disk Capacity Current User Session Count Cumulative Data Received

Metric(key: str, value: float, timestamp: Optional[int] = None)
22    def __init__(self, key: str, value: float, timestamp: Optional[int] = None):
23        """Creates a Metric
24
25        :param key: A string representing the type of metric. TODO: Describe how Keys work.
26        :param value: The value of the Metric. Must be type float.
27        :param timestamp: Time in milliseconds since the Epoch when this metric value was recorded.
28            Defaults to the current time.
29        """
30        self.key = key
31        self.value = value
32
33        if timestamp is None:
34            self.timestamp = int(time.time() * 1000)
35        else:
36            self.timestamp = timestamp

Creates a Metric

Parameters
  • key: A string representing the type of metric. TODO: Describe how Keys work.
  • value: The value of the Metric. Must be type float.
  • timestamp: Time in milliseconds since the Epoch when this metric value was recorded. Defaults to the current time.
def get_json(self) -> dict:
38    def get_json(self) -> dict:
39        """Get a JSON representation of this Metric.
40
41        Returns a JSON representation of this Metric in the format required by vROps.
42
43        :return: A JSON representation of this Metric.
44        """
45        return {
46            "key": self.key,
47            "numberValue": float(self.value),
48            "timestamp": self.timestamp,
49        }

Get a JSON representation of this Metric.

Returns a JSON representation of this Metric in the format required by vROps.

Returns

A JSON representation of this Metric.

class Property:
52class Property:
53    """Class representing a Property value.
54
55    A Property is a value, usually a string, that will change infrequently or not at all. Only the current value is
56    important.
57    Examples:
58        IP Address
59        Software Version
60        CPU Core Count
61    """
62
63    def __init__(
64        self, key: str, value: Union[float, str], timestamp: Optional[int] = None
65    ):
66        """Creates a Property.
67
68        :param key: A string representing the type of property. TODO: Describe how Keys work.
69        :param value: The value of the property. Can be str or float.
70        :param timestamp: Time in milliseconds since the Epoch when this property value was recorded.
71            Defaults to the current time.
72        """
73        self.key = key
74        self.value = value
75
76        if timestamp is None:
77            self.timestamp = int(time.time() * 1000)
78        else:
79            self.timestamp = timestamp
80
81    def get_json(self) -> dict:
82        """Get a JSON representation of this Property.
83
84        Returns a JSON representation of this Property in the format required by vROps.
85
86        :return: A JSON representation of this Property.
87        """
88        if isinstance(self.value, str):
89            label = "stringValue"
90        else:
91            label = "numberValue"
92            self.value = float(self.value)
93
94        return {"key": self.key, label: self.value, "timestamp": self.timestamp}

Class representing a Property value.

A Property is a value, usually a string, that will change infrequently or not at all. Only the current value is important. Examples: IP Address Software Version CPU Core Count

Property(key: str, value: Union[float, str], timestamp: Optional[int] = None)
63    def __init__(
64        self, key: str, value: Union[float, str], timestamp: Optional[int] = None
65    ):
66        """Creates a Property.
67
68        :param key: A string representing the type of property. TODO: Describe how Keys work.
69        :param value: The value of the property. Can be str or float.
70        :param timestamp: Time in milliseconds since the Epoch when this property value was recorded.
71            Defaults to the current time.
72        """
73        self.key = key
74        self.value = value
75
76        if timestamp is None:
77            self.timestamp = int(time.time() * 1000)
78        else:
79            self.timestamp = timestamp

Creates a Property.

Parameters
  • key: A string representing the type of property. TODO: Describe how Keys work.
  • value: The value of the property. Can be str or float.
  • timestamp: Time in milliseconds since the Epoch when this property value was recorded. Defaults to the current time.
def get_json(self) -> dict:
81    def get_json(self) -> dict:
82        """Get a JSON representation of this Property.
83
84        Returns a JSON representation of this Property in the format required by vROps.
85
86        :return: A JSON representation of this Property.
87        """
88        if isinstance(self.value, str):
89            label = "stringValue"
90        else:
91            label = "numberValue"
92            self.value = float(self.value)
93
94        return {"key": self.key, label: self.value, "timestamp": self.timestamp}

Get a JSON representation of this Property.

Returns a JSON representation of this Property in the format required by vROps.

Returns

A JSON representation of this Property.