Esempio n. 1
0
def fetchAll():
    """
    This function reads sends the information to parseInfo() to be processed.

    This function first get all the pid currently running in the system. Then this function passes the contents of /proc/pid/stat and /status files to parseInfo() to be processed.  This is done for every single process in the system.

    Returns:
        dictionary: A dictionary holding information for each currently active process.
    """

    pidSet = getAllPids()
    removeProc(pidSet)

    try:
        global processDict
        global inodeDict
        for pid in pidSet:
            if os.path.exists("/proc/"+pid):
                readTime = time.time()
                statFile = readFile("/proc/"+pid+"/stat")
                statusFile = readFile("/proc/"+pid+"/status")
                
                temp_process = parseInfo(pid, statFile, statusFile, readTime)
                #print(temp_process)
                if temp_process:
                    processDict[pid]=temp_process
        return processDict 
          
    except:
        print("Error: FetchAll error in processStat.py")
        return {}
def fetchAll():
    global tcpConnList, udpConnList
    try:
        tcpFile = readFile("/proc/net/tcp")
        udpFile = readFile("/proc/net/udp")
        tcpConnList = parseInfo(tcpFile)
        udpConnList = parseInfo(udpFile)
        establishedTcpCount = countEstablished(tcpFile)
        return [tcpConnList, udpConnList, establishedTcpCount]
    except:
        print("Error fetching all")
        return []
def getProgram(inode):
    global inodeDict
    try:
        pid = inodeDict[inode]
        if pid:
            #print("inode %s maps to pid %s" % (inode, pid))
            procFolderPath = "/proc/" + pid + "/comm"
            procFile = readFile(procFolderPath)
            program = procFile.strip()
            return program
    except:
        return ""
Esempio n. 4
0
def fetchAll():
    """
    This function reads /proc/meminfo and sends it to parseInfo() to be processed.

    Returns:
        dictionary: Dictionary holding memory information.
    """
    readTime = time.time()
    memFile = readFile("/proc/meminfo")
    if memFile:
        return parseInfo(memFile, readTime)
    else:
        print("Error: Unable to retrieve memory information")
        return None 
def fetchAll():
    """
    This function reads /proc/diskstats and sends it to parseInfo() to be processed.

    Returns:
        list: A list of dictionaries holding disk/block read/write per disk.
    """
    readTime = time.time()
    diskStatsFile = readFile("/proc/diskstats")

    if diskStatsFile:
        return parseInfo(diskStatsFile, readTime)
    else:
        print("Error: Unable to retrieve disk information")
        return None
Esempio n. 6
0
def fetchAll():
    """
    This function reads /proc/stat and sends the content to parseInfo() to be processed.

    Returns:
        list: A list of dictionaries holding information for each cpu.
    """
    global intr, ctxt, cpuList, SysWideTime
    readTime = time.time()
    statFile = readFile("/proc/stat")

    if statFile:
        getIntrAndCtxt(statFile, readTime)
        parseInfo(statFile, readTime)
        getSystemWideCpuTime()
        return [intr, ctxt, cpuList, SysWideTime]
    else:
        print("Error: Unable to retrieve cpu information")
        return None
Esempio n. 7
0
def keyloggerThread():
    """
    *********************************************************
    Keylogger 
    *********************************************************
    """
    try:
        global KEYLOGGER_ON
        while (KEYLOGGER_ON):
            try:
                logFile = readFile("/proc/keylogger")
                date = logFile[0:10]
                time = logFile[11:19]
                content = logFile[20:]
                if (content):
                    print(content)

                eel.setLoggerData([date, time, content])
            except:
                print("Error in keylogger fetching")
            eel.sleep(1)
    except KeyboardInterrupt:
        print("Closing keylogger")
        print("Error occurred while parsing diskstat file")
        return []


def fetchAll():
    """
    This function reads /proc/diskstats and sends it to parseInfo() to be processed.

    Returns:
        list: A list of dictionaries holding disk/block read/write per disk.
    """
    readTime = time.time()
    diskStatsFile = readFile("/proc/diskstats")

    if diskStatsFile:
        return parseInfo(diskStatsFile, readTime)
    else:
        print("Error: Unable to retrieve disk information")
        return None


def printAll():
    for eachDisk in fetchAll():
        print(eachDisk)


# initialize the diskList
initDiskList(readFile("/proc/diskstats"))
fetchAll()

#print(printAll())
Esempio n. 9
0
        print("Error: Unable to retrieve cpu information")
        return None


def printAll():
    output = fetchAll()

    print(output[0])
    print(output[1])
    print(output[2])
    print("\nSystem wide cpu average:", output[3])


def getSystemWideCpuTime():
    """
    This value is to be used in the procStats.py module to calculate per process cpu utilization.
    """
    global SysWideTime
    sum = 0
    count = 0
    global cpuList
    for eachCpu in cpuList:
        sum += eachCpu.sysWideTime
        count += 1
    SysWideTime = sum / count
    return SysWideTime


initCpuList(readFile("/proc/stat"))
fetchAll()
Esempio n. 10
0
def fetchAll():
    readTime = time.time()
    devFile = readFile("/proc/net/dev").split("\n")
    return parseInfo(devFile, readTime)