def _get_host_network_io_rate(self, seconds): prev_recv_bytes = self.host_stats['net_recv_bytes'] prev_sent_bytes = self.host_stats['net_sent_bytes'] net_ios = psutil.network_io_counters(True) recv_bytes = 0 sent_bytes = 0 for key in set(netinfo.nics() + netinfo.wlans()) & set(net_ios.iterkeys()): recv_bytes = recv_bytes + net_ios[key].bytes_recv sent_bytes = sent_bytes + net_ios[key].bytes_sent rx_rate = int(float(recv_bytes - prev_recv_bytes) / seconds + 0.5) tx_rate = int(float(sent_bytes - prev_sent_bytes) / seconds + 0.5) self.host_stats.update({'net_recv_rate': rx_rate, 'net_sent_rate': tx_rate, 'net_recv_bytes': recv_bytes, 'net_sent_bytes': sent_bytes})
def _get_host_network_io_rate(self, seconds): net_recv_bytes = self.host_stats["net_recv_bytes"] net_sent_bytes = self.host_stats["net_sent_bytes"] prev_recv_bytes = net_recv_bytes[-1] if net_recv_bytes else 0 prev_sent_bytes = net_sent_bytes[-1] if net_sent_bytes else 0 net_ios = psutil.network_io_counters(True) recv_bytes = 0 sent_bytes = 0 for key in set(netinfo.nics() + netinfo.wlans()) & set(net_ios.iterkeys()): recv_bytes = recv_bytes + net_ios[key].bytes_recv sent_bytes = sent_bytes + net_ios[key].bytes_sent rx_rate = int(float(recv_bytes - prev_recv_bytes) / seconds + 0.5) tx_rate = int(float(sent_bytes - prev_sent_bytes) / seconds + 0.5) self.host_stats["net_recv_rate"].append(rx_rate) self.host_stats["net_sent_rate"].append(tx_rate) self.host_stats["net_recv_bytes"].append(recv_bytes) self.host_stats["net_sent_bytes"].append(sent_bytes)
def _get_host_network_io_rate(self, seconds): net_recv_bytes = self.host_stats['net_recv_bytes'] net_sent_bytes = self.host_stats['net_sent_bytes'] prev_recv_bytes = net_recv_bytes[-1] if net_recv_bytes else 0 prev_sent_bytes = net_sent_bytes[-1] if net_sent_bytes else 0 net_ios = psutil.network_io_counters(True) recv_bytes = 0 sent_bytes = 0 for key in set(netinfo.nics() + netinfo.wlans()) & set(net_ios.iterkeys()): recv_bytes = recv_bytes + net_ios[key].bytes_recv sent_bytes = sent_bytes + net_ios[key].bytes_sent rx_rate = int(float(recv_bytes - prev_recv_bytes) / seconds + 0.5) tx_rate = int(float(sent_bytes - prev_sent_bytes) / seconds + 0.5) self.host_stats['net_recv_rate'].append(rx_rate) self.host_stats['net_sent_rate'].append(tx_rate) self.host_stats['net_recv_bytes'].append(recv_bytes) self.host_stats['net_sent_bytes'].append(sent_bytes)