예제 #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
예제 #2
0
파일: heartbeat.py 프로젝트: legendtkl/CUP
    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
예제 #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