Exemple #1
0
    def __init__(self, name, init_this_host=False, iface='eth0'):
        """
        :param name:
            name of the LinuxHost
        :param init_this_host:
            if init_this_host is True, will initialize the object by this linux
            . Otherwise, you need to initialize it by yourself.
        """
        super(self.__class__, self).__init__(name)
        # -1 means initialized
        self._dict_info = {
            'iface': iface,
            'ipaddr': '0.0.0.0',
            'hostname': net.get_local_hostname(),
            'cpu_idle': -1,
            'mem_inuse': -1,  # MB
            'mem_total': -1,
            'net_in': -1,  # kb
            'net_out': -1  # kb
        }

        if init_this_host:
            self._dict_info['ipaddr'] = net.get_hostip()
            cpuinfo = linux.get_cpu_usage(1)
            meminfo = linux.get_meminfo()
            self._dict_info['net_in'] = linux.get_net_recv_speed(
                self._dict_info['iface'], 1)
            self._dict_info['net_out'] = linux.get_net_transmit_speed(
                self._dict_info['iface'], 1)
            # pylint: disable=E1101
            self._dict_info['cpu_idle'] = cpuinfo.idle
            # pylint: disable=E1101
            self._dict_info['mem_inuse'] = meminfo.total - meminfo.free
Exemple #2
0
    def __init__(self, name, init_this_host=False, iface='eth0'):
        """
        :param name:
            name of the LinuxHost
        :param init_this_host:
            if init_this_host is True, will initialize the object by this linux
            . Otherwise, you need to initialize it by yourself.
        """
        super(self.__class__, self).__init__(name)
        # -1 means initialized
        self._dict_info = {
            'iface':   iface,
            'ipaddr': '0.0.0.0',
            'hostname': net.get_local_hostname(),
            'cpu_idle': -1,
            'mem_inuse': -1,        # MB
            'mem_total': -1,
            'net_in': -1,        # kb
            'net_out': -1      # kb
        }

        if init_this_host:
            self._dict_info['ipaddr'] = net.get_hostip()
            cpuinfo = linux.get_cpu_usage(1)
            meminfo = linux.get_meminfo()
            self._dict_info['net_in'] = linux.get_net_recv_speed(
                self._dict_info['iface'], 1
            )
            self._dict_info['net_out'] = linux.get_net_transmit_speed(
                self._dict_info['iface'], 1
            )
            # pylint: disable=E1101
            self._dict_info['cpu_idle'] = cpuinfo.idle
            # pylint: disable=E1101
            self._dict_info['mem_inuse'] = meminfo.total - meminfo.free
Exemple #3
0
    def __init__(self, name, init_this_host=False, iface='eth0', port=0):
        """
        :param name:
            name of the LinuxHost
        :param init_this_host:
            if init_this_host is True, will initialize the object by this linux
            . Otherwise, you need to initialize it by yourself.
        :exception socket.gaierror :
            if we cannot get the ip of the host, the object construction
            may raise socket.gaierror exception.
            You have to code {try:  catch socket.gaierror as err:}
        """
        Device.__init__(self, name)
        # -1 means initialized
        self._dict_info = {
            'iface': iface,
            'ipaddr': '0.0.0.0',
            'port': 0,
            'hostname': net.get_local_hostname(),
            'cpu_idle': -1,
            'mem_inuse': -1,  # MB
            'mem_total': -1,
            'net_in': -1,  # kb
            'net_out': -1  # kb
        }

        if init_this_host:
            self._dict_info['ipaddr'] = net.get_hostip()
            self._dict_info['port'] = port
            cpuinfo = linux.get_cpu_usage(1)
            meminfo = linux.get_meminfo()
            self._dict_info['net_in'] = linux.get_net_recv_speed(
                self._dict_info['iface'], 1)
            self._dict_info['net_out'] = linux.get_net_transmit_speed(
                self._dict_info['iface'], 1)
            # pylint: disable=E1101
            self._dict_info['cpu_idle'] = cpuinfo.idle
            # pylint: disable=E1101
            self._dict_info['mem_inuse'] = meminfo.total - meminfo.free
            self._dict_info['mem_total'] = meminfo.total
Exemple #4
0
# Examples:
# 1. Get system info
import json

import cup
from cup import exfile
from cup.net import route
from cup.res import linux

# count cpu usage in interval, by default 60 seconds

cpuinfo = linux.get_cpu_usage(intvl_in_sec=60)
print(cpuinfo.usr)

# total, available, percent, used, free, active, inactive, buffers, cached

meminfo = linux.get_meminfo()
print(meminfo.total)
print(meminfo.available)

# http://cup.iobusy.com/api-ref/

print(cup.res.linux.boot_time())

print(cup.res.linux.get_disk_info())

ri = route.RouteInfo()
print(json.dumps(ri.get_routes(), indent=1))

# Lock file in order to prevent others from trying to lock it again