in AWSIoTDeviceDefenderAgentSDK/metrics.py [0:0]
def add_network_stats(self, bytes_in, packets_in, bytes_out, packets_out):
"""
Add cumulative network stats across all network interfaces.
If a previous metrics object was supplied,attempts to calculate and store delta metric.
Parameters
----------
bytes_in: int
Number of bytes received on this interface
bytes_out: int
Number of bytes sent from this interface
packets_in: int
Number of packets received on this interface
packets_out: int
Number of packets sent from this interface
"""
self.total_counts = {
'bytes_in': bytes_in,
'bytes_out': bytes_out,
'packets_in': packets_in,
'packets_out': packets_out
}
if self._old_interface_stats:
bytes_in_diff = bytes_in - self._old_interface_stats[self.t.bytes_in]
bytes_out_diff = bytes_out - self._old_interface_stats[self.t.bytes_out]
packets_in_diff = packets_in - self._old_interface_stats[self.t.packets_in]
packets_out_diff = packets_out - self._old_interface_stats[self.t.packets_out]
self._interface_stats = {self.t.bytes_in: bytes_in_diff,
self.t.bytes_out: bytes_out_diff,
self.t.packets_in: packets_in_diff,
self.t.packets_out: packets_out_diff}
else:
self._interface_stats = {self.t.bytes_in: bytes_in, self.t.bytes_out: bytes_out,
self.t.packets_in: packets_in,
self.t.packets_out: packets_out}