当前位置: 首页>>代码示例>>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;未经允许,请勿转载。