in AWSIoTDeviceDefenderAgentSDK/metrics.py [0:0]
def __init__(self, short_names=False, last_metric=None):
"""Initialize a new metrics object.
Parameters
----------
short_names : bool
Toggle short object tags in output metrics.
last_metric : Metrics object
Metric object used for delta metric calculation.
"""
self.t = tags.Tags(short_names)
# Header Information
self._timestamp = int(time.time())
if last_metric is None:
self.interval = 0
else:
self.interval = self._timestamp - last_metric._timestamp
# Network Metrics
self._net_connections = []
self.listening_tcp_ports = []
self.listening_udp_ports = []
# Custom Metrics
self.cpu_metrics = []
# Network Stats By Interface
self.total_counts = {} # The raw values from the system
self._interface_stats = {} # The diff values, if delta metrics are used
if last_metric is None:
self._old_interface_stats = {}
else:
self._old_interface_stats = last_metric.total_counts
self.max_list_size = 50