Coder Social home page Coder Social logo

anilpatidar / process_monitor_repo Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 16 KB

Process resources monitoring application Develop a console application in Python that, for a given process: • periodically gathers process metrics (for a specified amount of time) • creates a report of the gathered process metrics (in CSV format) • outputs the average for each process metric • detects possible memory leaks and raises a warning

Python 100.00%

process_monitor_repo's Introduction

process_monitor_repo

Process resources monitoring application Develop a console application in Python that, for a given process: • periodically gathers process metrics (for a specified amount of time) • creates a report of the gathered process metrics (in CSV format) • outputs the average for each process metric • detects possible memory leaks and raises a warning

Run Command :

python3 src/process_monitor.py 539 5 1 Usage: python script_name.py <process_pid>

Modules : psutil: to get process data psutil.process_iter(['pid', 'name', 'cpu_percent', 'memory_percent', 'num_fds'])

csv: to write CSV File with open(filename, mode='w', newline='') as csvfile: fieldnames = ['Process Name', 'PID', 'CPU Percent', 'Memory Percent'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

    writer.writeheader()
    for process_info in process_metrics:
        writer.writerow({
            'Process Name': process_info['name'],
            'PID': process_info['pid'],
            'CPU Percent': process_info['cpu_percent'],
             'Memory Percent': process_info['memory_percent'],
        })

macos commands related to process:

List all the Processes: ps aux ps ef

Output column :

USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND

Print specific column : ps aux | awk '{print $11}' here print $11 will print the 11th column value,

The sort command with -k4,4rn option sorts the output based on the 4th column (memory usage in percentage) in reverse numerical order (-n) to sort it by highest memory usage first, and with r option to sort in descending order.

ps aux | sort -k4,4rn

If you want to see only the top N processes with the highest memory usage, you can use the head command to limit the output:

ps aux | sort -k4,4rn | head -n 10

process_monitor_repo's People

Contributors

anilpatidar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.