當前位置: 首頁>>代碼示例>>Python>>正文


Python psutil.net_if_stats方法代碼示例

本文整理匯總了Python中psutil.net_if_stats方法的典型用法代碼示例。如果您正苦於以下問題:Python psutil.net_if_stats方法的具體用法?Python psutil.net_if_stats怎麽用?Python psutil.net_if_stats使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在psutil的用法示例。


在下文中一共展示了psutil.net_if_stats方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getNetworkInfo

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def getNetworkInfo(cls):
        interfaces = {}

        stats = psutil.net_if_stats()
        for key, value in six.iteritems(stats):
            interfaces[key] = value.__dict__
            interfaces[key]['addresses'] = []
            interfaces[key]['io_counters'] = None

        addresses = psutil.net_if_addrs()
        for key, value in six.iteritems(addresses):
            if key not in interfaces:
                continue

            for addr in value:
                interfaces[key]['addresses'].append(addr.__dict__)

        traffic = psutil.net_io_counters(pernic=True)
        for key, value in six.iteritems(traffic):
            if key not in interfaces:
                continue

            interfaces[key]['io_counters'] = value.__dict__

        return interfaces 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:27,代碼來源:system_status.py

示例2: test_procfs_path

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_procfs_path(self):
        tdir = tempfile.mkdtemp()
        try:
            psutil.PROCFS_PATH = tdir
            self.assertRaises(IOError, psutil.virtual_memory)
            self.assertRaises(IOError, psutil.cpu_times)
            self.assertRaises(IOError, psutil.cpu_times, percpu=True)
            self.assertRaises(IOError, psutil.boot_time)
            # self.assertRaises(IOError, psutil.pids)
            self.assertRaises(IOError, psutil.net_connections)
            self.assertRaises(IOError, psutil.net_io_counters)
            self.assertRaises(IOError, psutil.net_if_stats)
            self.assertRaises(IOError, psutil.disk_io_counters)
            self.assertRaises(IOError, psutil.disk_partitions)
            self.assertRaises(psutil.NoSuchProcess, psutil.Process)
        finally:
            psutil.PROCFS_PATH = "/proc"
            os.rmdir(tdir) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:20,代碼來源:test_linux.py

示例3: test_procfs_path

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_procfs_path(self):
        tdir = self.get_testfn()
        os.mkdir(tdir)
        try:
            psutil.PROCFS_PATH = tdir
            self.assertRaises(IOError, psutil.virtual_memory)
            self.assertRaises(IOError, psutil.cpu_times)
            self.assertRaises(IOError, psutil.cpu_times, percpu=True)
            self.assertRaises(IOError, psutil.boot_time)
            # self.assertRaises(IOError, psutil.pids)
            self.assertRaises(IOError, psutil.net_connections)
            self.assertRaises(IOError, psutil.net_io_counters)
            self.assertRaises(IOError, psutil.net_if_stats)
            # self.assertRaises(IOError, psutil.disk_io_counters)
            self.assertRaises(IOError, psutil.disk_partitions)
            self.assertRaises(psutil.NoSuchProcess, psutil.Process)
        finally:
            psutil.PROCFS_PATH = "/proc" 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:20,代碼來源:test_linux.py

示例4: _acquire_ifb_device

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def _acquire_ifb_device() -> str:
    devices = psutil.net_if_stats()
    for device_name, device in devices.items():
        if not IFB_REGEX.match(device_name):
            continue

        if not device.isup:
            _activate_device(device_name)
            # Deactivate existing IFB device if it wasn't activated
            atexit.register(_clean_up, shutdown_ifb_device=device_name)

        return device_name

    # Clean up IFB device if it was created
    atexit.register(_clean_up, remove_ifb_device=True)
    return _create_ifb_device() 
開發者ID:cryzed,項目名稱:TrafficToll,代碼行數:18,代碼來源:tc.py

示例5: collect_system_information

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def collect_system_information(self):
        values = {}
        mem = psutil.virtual_memory()
        values['memory_total'] = mem.total

        import cpuinfo
        cpu = cpuinfo.get_cpu_info()
        values['resources_limit'] = self.resources_limit
        values['cpu_name'] = cpu['brand']
        values['cpu'] = [cpu['hz_advertised_raw'][0], cpu['count']]
        values['nets'] = {}
        values['disks'] = {}
        values['gpus'] = {}
        values['boot_time'] = psutil.boot_time()

        try:
            for gpu_id, gpu in enumerate(aetros.cuda_gpu.get_ordered_devices()):
                gpu['available'] = gpu_id in self.enabled_gpus

                values['gpus'][gpu_id] = gpu
        except aetros.cuda_gpu.CudaNotImplementedException: pass

        for disk in psutil.disk_partitions():
            try:
                name = self.get_disk_name(disk[1])
                values['disks'][name] = psutil.disk_usage(disk[1]).total
            except Exception:
                # suppress Operation not permitted
                pass

        try:
            for id, net in psutil.net_if_stats().items():
                if 0 != id.find('lo') and net.isup:
                    self.nets.append(id)
                    values['nets'][id] = net.speed or 1000
        except Exception:
            # suppress Operation not permitted
            pass

        return values 
開發者ID:aetros,項目名稱:aetros-cli,代碼行數:42,代碼來源:ServerCommand.py

示例6: update_network_interfaces

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def update_network_interfaces(self):
        self.ui.comboBox_Interface.clear()
        self.net_if = psutil.net_if_addrs()
        net_if_stats = psutil.net_if_stats()

        net_names = list(self.net_if.keys())

        for if_name in net_names:
            if not net_if_stats[if_name].isup:
                self.net_if.pop(if_name, None)
            else:
                self.ui.comboBox_Interface.addItem(if_name)

        interface_idx = self.config.get('Interface', 0)

        if interface_idx >= self.ui.comboBox_Interface.count():
            self.ui.comboBox_Interface.setCurrentIndex(0)
        else:
            self.ui.comboBox_Interface.setCurrentIndex(interface_idx)

        current_interface = self.ui.comboBox_Interface.currentText()
        self.config['Interface'] = self.ui.comboBox_Interface.currentIndex()

        for snicaddr in self.net_if[current_interface]:
            if snicaddr.family == socket.AF_INET:
                ipv4_add = snicaddr.address
                break
            else:
                ipv4_add = '0.0.0.0'

        self.ui.label_LocalIP.setText(ipv4_add)

        self.save_config() 
開發者ID:rookiepeng,項目名稱:socket-test,代碼行數:35,代碼來源:socket_test.py

示例7: test_net_if_stats

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_net_if_stats(self):
        self.execute(psutil.net_if_stats)

    # --- sensors 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:6,代碼來源:test_memory_leaks.py

示例8: test_net_if_stats

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_net_if_stats(self):
        # Duplicate of test_system.py. Keep it anyway.
        for ifname, _ in psutil.net_if_stats().items():
            self.assertIsInstance(ifname, str) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:6,代碼來源:test_contracts.py

示例9: test_net_if_stats

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_net_if_stats(self):
        nics = psutil.net_if_stats()
        assert nics, nics
        all_duplexes = (psutil.NIC_DUPLEX_FULL,
                        psutil.NIC_DUPLEX_HALF,
                        psutil.NIC_DUPLEX_UNKNOWN)
        for name, stats in nics.items():
            self.assertIsInstance(name, str)
            isup, duplex, speed, mtu = stats
            self.assertIsInstance(isup, bool)
            self.assertIn(duplex, all_duplexes)
            self.assertIn(duplex, all_duplexes)
            self.assertGreaterEqual(speed, 0)
            self.assertGreaterEqual(mtu, 0) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:16,代碼來源:test_system.py

示例10: test_net_if_stats

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_net_if_stats(self):
        for name, stats in psutil.net_if_stats().items():
            try:
                out = sh("ifconfig %s" % name)
            except RuntimeError:
                pass
            else:
                self.assertEqual(stats.isup, 'RUNNING' in out, msg=out)
                self.assertEqual(stats.mtu,
                                 int(re.findall(r'mtu (\d+)', out)[0]))

    # --- sensors_battery 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:14,代碼來源:test_osx.py

示例11: test_net_if_stats

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_net_if_stats(self):
        for name, stats in psutil.net_if_stats().items():
            try:
                out = sh("ifconfig %s" % name)
            except RuntimeError:
                pass
            else:
                # Not always reliable.
                # self.assertEqual(stats.isup, 'RUNNING' in out, msg=out)
                self.assertEqual(stats.mtu,
                                 int(re.findall(r'(?i)MTU[: ](\d+)', out)[0])) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:13,代碼來源:test_linux.py

示例12: test_net_if_stats

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_net_if_stats(self):
        # Duplicate of test_system.py. Keep it anyway.
        for ifname, info in psutil.net_if_stats().items():
            self.assertIsInstance(ifname, str)
            self.assertIsInstance(info.isup, bool)
            if enum is not None:
                self.assertIsInstance(info.duplex, enum.IntEnum)
            else:
                self.assertIsInstance(info.duplex, int)
            self.assertIsInstance(info.speed, int)
            self.assertIsInstance(info.mtu, int) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:13,代碼來源:test_contracts.py

示例13: test_net_if_stats_enodev

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_net_if_stats_enodev(self):
        # See: https://github.com/giampaolo/psutil/issues/1279
        with mock.patch('psutil._psutil_posix.net_if_mtu',
                        side_effect=OSError(errno.ENODEV, "")) as m:
            ret = psutil.net_if_stats()
            self.assertEqual(ret, {})
            assert m.called 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:9,代碼來源:test_system.py

示例14: test_against_ifconfig

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def test_against_ifconfig(self):
        for name, stats in psutil.net_if_stats().items():
            try:
                out = sh("ifconfig %s" % name)
            except RuntimeError:
                pass
            else:
                # Not always reliable.
                # self.assertEqual(stats.isup, 'RUNNING' in out, msg=out)
                self.assertEqual(stats.mtu,
                                 int(re.findall(r'(?i)MTU[: ](\d+)', out)[0])) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:13,代碼來源:test_linux.py

示例15: main

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import net_if_stats [as 別名]
def main():
    stats = psutil.net_if_stats()
    io_counters = psutil.net_io_counters(pernic=True)
    for nic, addrs in psutil.net_if_addrs().items():
        print("%s:" % (nic))
        if nic in stats:
            st = stats[nic]
            print("    stats          : ", end='')
            print("speed=%sMB, duplex=%s, mtu=%s, up=%s" % (
                st.speed, duplex_map[st.duplex], st.mtu,
                "yes" if st.isup else "no"))
        if nic in io_counters:
            io = io_counters[nic]
            print("    incoming       : ", end='')
            print("bytes=%s, pkts=%s, errs=%s, drops=%s" % (
                bytes2human(io.bytes_recv), io.packets_recv, io.errin,
                io.dropin))
            print("    outgoing       : ", end='')
            print("bytes=%s, pkts=%s, errs=%s, drops=%s" % (
                bytes2human(io.bytes_sent), io.packets_sent, io.errout,
                io.dropout))
        for addr in addrs:
            print("    %-4s" % af_map.get(addr.family, addr.family), end="")
            print(" address   : %s" % addr.address)
            if addr.broadcast:
                print("         broadcast : %s" % addr.broadcast)
            if addr.netmask:
                print("         netmask   : %s" % addr.netmask)
            if addr.ptp:
                print("      p2p       : %s" % addr.ptp)
        print("") 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:33,代碼來源:ifconfig.py


注:本文中的psutil.net_if_stats方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。