Displaying system information using python

Hi,

I am now getting following error:

Traceback (most recent call last):
File “/home/zulfi/PycharmProjects/Classes/psutilPrintInfo.py”, line 31, in
obj_Counting_SysInfo.main()
File “/home/zulfi/PycharmProjects/Classes/psutilPrintInfo.py”, line 27, in main
self.system_info()
File “/home/zulfi/PycharmProjects/Classes/psutilPrintInfo.py”, line 16, in system_info
mem = process.get_memory_info()[0] / float(2 ** 30) # memory in GB
AttributeError: ‘Process’ object has no attribute ‘get_memory_info’

My code is given below:

import psutil
import os

class Counting_SysInfo:
    def __init__(self, i):
        self.i = i

    def Print_Numbers(self):
        for i in range(50):
            print (i)

    def system_info(self):
        # return the memory usage in MB
        self.Print_Numbers()
        process = psutil.Process(os.getpid())
        mem = process.get_memory_info()[0] / float(2 ** 30)  # memory in GB
        cpu = process.cpu_percent() / psutil.cpu_count()
        disk = process.disk_usage(part.mountpoint).percent  # https://github.com/giampaolo/psutil/blob/master/scripts/disk_usage.py
        vMem = int(process.virtual_memory().available)
        print(process.memory_info().rss)  # in bytes
        RSS = process.memory_info().rss
        # https://stackoverflow.com/questions/17990227/whats-the-unit-of-rss-in-psutil-process-get-memory-info
        pageFaults = process.memory_info().pfaults  # https://readthedocs.org/projects/giamptest/downloads/pdf/latest/
        print("mem= ", mem, "cpu= ", cpu, 'disk= ',disk, "VMem= ", vMem, "RSS= ", RSS, "page faults=", pageFaults )

    def main(self):
        self.system_info()

if __name__ == "__main__":
    obj_Counting_SysInfo = Counting_SysInfo(10)
    obj_Counting_SysInfo.main()

Somebody please guide me how to solve this problem.

Zulfi.

AttributeError: ‘Process’ object has no attribute ‘get_memory_info’

I assume you’ve been looking at very old examples? It’s memory_info, not get_memory_info, so you get an error because you’re trying to call a method that doesn’t exist

As an example, see psutil · PyPI (current release, memory_info) vs. psutil · PyPI (2012 release, get_memory_info) under the Process Management examples

Hi,
Memory error removed, Thanks. Now I am getting error with disk usage:

import psutil
import os
print(psutil.Process(os.getpid()).disk_usage('/').percent)

print(psutil.Process(os.getpid()).disk_usage(‘/’).percent)
AttributeError: ‘Process’ object has no attribute ‘disk_usage’
Somebody please guide me.
Zulfi.

disk_usage is the overall disk usage on the whole system, it’s not per-process.

psutil.disk_usage('/')

I’d really recommend looking at the documentation I’ve linked. I don’t use Python very often at all, I’m just telling you things that are described in the examples on that page

Thank you sir.

God bless you.