Ejemplo n.º 1
0
def getpaginfo():
    """
    get mem pag info
    :return:
    """

    page_memory = {}
    flag, node_id = getAgentId()
    page_memory["id"] = node_id
    try:
        rtinfo = launchcmd('sar -B 1 1').readlines()
        if rtinfo[-1]:
            page_list = rtinfo[-1].split()
            page_memory["pgpgin"] = page_list[1]
            page_memory["pgpgout"] = page_list[2]
            page_memory["fault"] = page_list[3]
            page_memory["majflt"] = page_list[4]
            page_memory["pgfree"] = page_list[5]
            page_memory["pgsteal"] = page_list[8]
        rtinfo_other = launchcmd('sar -R 1 1').readlines()
        if rtinfo_other[-1]:
            page_list_other = rtinfo_other[-1].split()
            page_memory["bufpg"] = page_list_other[2]
            page_memory["campg"] = page_list_other[3]

    except IOError:
        return page_memory
    return page_memory
Ejemplo n.º 2
0
def getmembasicinfo():
    """
    get memory info
    :param
    :return:
    """
    virtual_memory = {}
    flag, node_id = getAgentId()
    virtual_memory["id"] = node_id
    try:
        freem = launchcmd('free').readlines()
        shared = int(strip(freem[1].split()[4])) * 1024
        rtinfo = psutil.virtual_memory()
        if rtinfo:
            rtinfo_list = str(rtinfo).replace("svmem(",
                                              "").replace(")", "").split(",")
            for item in rtinfo_list:
                items = item.split("=")
                virtual_memory[strip(items[0])] = strip(items[1])
            virtual_memory["shared"] = shared

    except IOError:
        return virtual_memory

    return virtual_memory
Ejemplo n.º 3
0
def get_numastat_info():
    """
        get numastat info
        :return:
        """

    numastat_list = []
    numastat = []
    numa_dict = {}
    flag, node_id = getAgentId()
    numa_dict["id"] = node_id

    try:
        rtninfo = launchcmd('numastat').readlines()
        for item in rtninfo:
            items = item.split()
            numastat.append(items)
        for i in range(0, len(numastat[0])):
            numastat_info = {}
            numastat_info["name"] = numastat[0][i]
            numastat_info["numa_hit"] = numastat[1][i + 1]
            numastat_info["numa_miss"] = numastat[2][i + 1]
            numastat_info["numa_foreign"] = numastat[3][i + 1]
            numastat_info["interleave_hit"] = numastat[4][i + 1]
            numastat_info["local_node"] = numastat[5][i + 1]
            numastat_info["other_node"] = numastat[6][i + 1]
            numastat_list.append(numastat_info)
        numa_dict["body"] = numastat_list
    except IOError:
        return numa_dict

    return numa_dict
Ejemplo n.º 4
0
def get_udp_info():
        """
        get udp info
        :return:
        """
        udp_info = {}
        flag, node_id = getAgentId()
        udp_info["id"] = node_id
        try:

            rtinfo = launchcmd('sar -n UDP 1 1').readlines()
            if rtinfo:
                continue_falg = True
                for item in rtinfo:
                    if continue_falg:
                        if "idgm" in item:
                            continue_falg = False
                        continue
                    tmplist = item.split()
                    udp_info["time"] = tmplist[0]
                    udp_info["idgm/s"] = tmplist[1]
                    udp_info["odgm/s"] = tmplist[2]
                    udp_info["noport/s"] = tmplist[3]
                    udp_info["idgmerr/s"] = tmplist[4]
                    break
        except IOError, e:
            return udp_info
Ejemplo n.º 5
0
def get_socket_info():
        """
        get socket info
        :return:
        """
        socket_info = {}
        flag, node_id = getAgentId()
        socket_info["id"] = node_id
        try:
            rtinfo = launchcmd('sar -n SOCK 1 1').readlines()
            if rtinfo:
                continue_falg = True
                for item in rtinfo:
                    if continue_falg:
                        if "totsck" in item:
                            continue_falg = False
                        continue
                    tmplist = item.split()
                    socket_info["time"] = tmplist[0]
                    socket_info["totsck"] = tmplist[1]
                    socket_info["tcpsck"] = tmplist[2]
                    socket_info["udpsck"] = tmplist[3]
                    socket_info["rawsck"] = tmplist[4]
                    socket_info["ip-frag"] = tmplist[5]
                    socket_info["tcp-tw"] = tmplist[6]
                    break
        except IOError, e:
            return socket_info
Ejemplo n.º 6
0
def get_ps_info(itemid):
    psInfo = []
    num = 10
    if "cpu" == itemid:
        commands = "pidstat | sort -k7nr |grep -v 'PID' | head -n " + str(num)
    else:
        commands = "ps -aux|sort -k4nr|grep -v 'USER'|head -n " + str(num)

    try:
        ps_info = launchcmd(commands).readlines()

        for psitem in ps_info:
            if "cpu" == itemid:
                format_iteminfo = format_pidstat_info(psitem)
            else:
                format_iteminfo = format_process_info(psitem)

            if format_iteminfo["pid"].isdigit() and psutil.pid_exists(
                    int(format_iteminfo["pid"])):
                format_iteminfo["name"] = psutil.Process(
                    int(format_iteminfo["pid"])).name()
            else:
                format_iteminfo["name"] = ""
            psInfo.append(format_iteminfo)
    except Exception, e:
        return psInfo
Ejemplo n.º 7
0
def get_throughput_info():
        """
        get throughput info
        :return:
        """

        throughput_list = {}
        flag, node_id = getAgentId()
        throughput_list["id"] = node_id
        try:

            rtinfo = launchcmd('sar -n ALL 1 1').readlines()
            if rtinfo:
                continue_falg = True
                falg = True
                for item in rtinfo:
                    throughput_info = {}
                    if continue_falg:
                        if "IFACE" in item:
                            continue_falg = False
                        continue
                    if "rxerr" in item:
                        falg = False
                        continue
                    if "call" in item:
                        break
                    tmplist = item.split()
                    if tmplist is None or tmplist == []:
                        continue
                    if falg:
                        throughput_info["time"] = tmplist[0]
                        throughput_info["name"] = tmplist[1]
                        throughput_info["rxpck/s"] = tmplist[2]
                        throughput_info["txpck/s"] = tmplist[3]
                        throughput_info["rxkB/s"] = tmplist[4]
                        throughput_info["txkB/s"] = tmplist[5]
                        throughput_info["rxcmp/s"] = tmplist[6]
                        throughput_info["txcmp/s"] = tmplist[7]
                        throughput_info["rxmcst/s"] = tmplist[8]

                        throughput_list[tmplist[1]] = throughput_info
                    else:
                        throughput_info = throughput_list[tmplist[1]]
                        throughput_info["rxerr/s"] = tmplist[2]
                        throughput_info["txerr/s"] = tmplist[3]
                        throughput_info["coll/s"] = tmplist[4]
                        throughput_info["rxdrop/s"] = tmplist[5]
                        throughput_info["txdrop/s"] = tmplist[6]
                        throughput_info["txcarr/s"] = tmplist[7]
                        throughput_info["rxfram/s"] = tmplist[8]
                        throughput_info["rxfifo/s"] = tmplist[9]
                        throughput_info["txfifo/s"] = tmplist[10]
                        throughput_list[tmplist[1]] = throughput_info

        except IOError, e:

            return throughput_list
Ejemplo n.º 8
0
def get_iptrafic_info():
        """
        get iptrafic info
        :return:
        """

        iptrafic_info = {}
        flag, node_id = getAgentId()
        iptrafic_info["id"] = node_id
        try:
            rtinfo = launchcmd('sar -n ALL 1 1').readlines()
            if rtinfo:
                continue_falg = True
                falg = True
                for item in rtinfo:
                    if continue_falg:
                        if "irec" in item:
                            continue_falg = False
                        continue
                    if "ihdrerr" in item:
                        falg = False
                        continue
                    if "imsg" in item:
                        break
                    tmplist = item.split()
                    if tmplist is None or tmplist == []:
                        continue
                    if falg:
                        iptrafic_info["time"] = tmplist[0]
                        iptrafic_info["irec/s"] = tmplist[1]
                        iptrafic_info["fwddgm/s"] = tmplist[2]
                        iptrafic_info["idel/s"] = tmplist[3]
                        iptrafic_info["orq/s"] = tmplist[4]
                        iptrafic_info["asmrq/s"] = tmplist[5]
                        iptrafic_info["asmok/s"] = tmplist[6]
                        iptrafic_info["fragok/s"] = tmplist[7]
                        iptrafic_info["fragcrt/s"] = tmplist[8]
                    else:
                        iptrafic_info["ihdrerr/s"] = tmplist[1]
                        iptrafic_info["iadrerr/s"] = tmplist[2]
                        iptrafic_info["iukwnpr/s"] = tmplist[3]
                        iptrafic_info["idisc/s"] = tmplist[4]
                        iptrafic_info["odisc/s"] = tmplist[5]
                        iptrafic_info["onort/s"] = tmplist[6]
                        iptrafic_info["asmf/s"] = tmplist[7]
                        iptrafic_info["fragf/s"] = tmplist[8]

        except IOError, e:
            return iptrafic_info
Ejemplo n.º 9
0
def get_tcp_info():
        """
        get tcp info
        :return:
        """
        tcp_info = {}
        flag, node_id = getAgentId()
        tcp_info["id"] = node_id
        try:
            rtinfo = launchcmd('sar -n ALL 1 1').readlines()
            if rtinfo:
                continue_falg = True
                falg = True
                for item in rtinfo:
                    if continue_falg:
                        if "active" in item:
                            continue_falg = False
                        continue
                    if "atmptf" in item:
                        falg = False
                        continue
                    if "idgm" in item:
                        break
                    tmplist = item.split()
                    if tmplist is None or tmplist == []:
                        continue
                    if falg:
                        tcp_info["time"] = tmplist[0]
                        tcp_info["active/s"] = tmplist[1]
                        tcp_info["passive/s"] = tmplist[2]
                        tcp_info["iseg/s"] = tmplist[3]
                        tcp_info["oseg/s"] = tmplist[4]
                    else:
                        tcp_info["atmptf/s"] = tmplist[1]
                        tcp_info["estres/s"] = tmplist[2]
                        tcp_info["retrans/s"] = tmplist[3]
                        tcp_info["isegerr/s"] = tmplist[4]
                        tcp_info["orsts/s"] = tmplist[5]
        except IOError, e:
            return tcp_info
Ejemplo n.º 10
0
def get_slab_info():
    """
        get slab info
        :return:
        """

    slab_list = []
    slab_res = {}
    flag, node_id = getAgentId()
    slab_res["id"] = node_id

    try:
        rtinfo = launchcmd('slabtop -o').readlines()
        if rtinfo:
            continue_falg = True
            for item in rtinfo:
                slab_info = {}
                if continue_falg:
                    if "OBJS" in item:
                        continue_falg = False
                    continue
                slab_info["name"] = item.split()[7]
                slab_info["objs"] = item.split()[0]
                slab_info["slabs"] = item.split()[4]
                slab_info["obj_slab"] = item.split()[5]
                slab_info["active"] = item.split()[1]
                slab_info["obj_size"] = item.split()[3]
                slab_info["use"] = item.split()[2]
                slab_list.append(slab_info)
            slab_res["body"] = slab_list
            return slab_res

    except IOError:
        return slab_res

    return slab_res
Ejemplo n.º 11
0
def get_swap_info():
    """
    get swap info
    :param
    :return:
    """
    swap_memory = {}
    flag, node_id = getAgentId()
    swap_memory["id"] = node_id
    try:
        rtinfo = psutil.swap_memory()
        if rtinfo:
            rtinfo_list = str(rtinfo).replace("sswap(",
                                              "").replace(")", "").split(",")
            pg_in_out = launchcmd('sar -W 1 1').readlines()
            for item in rtinfo_list:
                items = item.split("=")
                swap_memory[strip(items[0])] = strip(items[1])
                swap_memory["pswpin"] = pg_in_out[-1].split()[1]
                swap_memory["pswpout"] = pg_in_out[-1].split()[2]
    except IOError:
        return swap_memory

    return swap_memory
Ejemplo n.º 12
0
def get_core_num():
    # CPU core num
    proc_cpu_cores = launchcmd(
        'cat /proc/cpuinfo | grep "processor" |wc -l').readline()
    return proc_cpu_cores