psutil | Cross-platform lib for process and system monitoring in Python | Monitoring library

 by   giampaolo Python Version: 5.9.8 License: BSD-3-Clause

kandi X-RAY | psutil Summary

kandi X-RAY | psutil Summary

psutil is a Python library typically used in Performance Management, Monitoring applications. psutil has no bugs, it has build file available, it has a Permissive License and it has high support. However psutil has 1 vulnerabilities. You can install using 'pip install psutil' or download it from GitHub, PyPI.

Cross-platform lib for process and system monitoring in Python
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              psutil has a highly active ecosystem.
              It has 9325 star(s) with 1330 fork(s). There are 238 watchers for this library.
              There were 2 major release(s) in the last 6 months.
              There are 232 open issues and 1389 have been closed. On average issues are closed in 226 days. There are 35 open pull requests and 0 closed requests.
              OutlinedDot
              It has a negative sentiment in the developer community.
              The latest version of psutil is 5.9.8

            kandi-Quality Quality

              psutil has 0 bugs and 0 code smells.

            kandi-Security Security

              psutil has 1 vulnerability issues reported (0 critical, 1 high, 0 medium, 0 low).
              psutil code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              psutil is licensed under the BSD-3-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              psutil releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              psutil saves you 9212 person hours of effort in developing the same functionality from scratch.
              It has 18982 lines of code, 1662 functions and 74 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed psutil and discovered the below as its top functions. This is intended to give you an instant insight into psutil implemented functionality, and help decide if they suit your requirements.
            • Run a process
            • Prints a string to stdout
            • Convert bytes to human readable string
            • Hilite string
            • Returns the CPU percent of the process
            • Return the CPU count
            • Returns the current CPU times
            • Get process information
            • Return the CPU usage percentage
            • Set the scputimes
            • Get CPU times
            • Update window statistics
            • Prints a summary of CPU usage
            • Set global scputimes
            • Poll process info by interval
            • Hilite a string
            • Uninstall psutil
            • Return a dict representation of the process
            • Read the history file
            • Return the platform name
            • Returns the number of memory in memory
            • Validate URLs
            • Return the path to a python executable
            • Return the CPU times
            • Print a summary of the CPU usage
            • Return a list of cpu times
            • Show the status of all processes
            • Return the disk usage for the given path
            • A helper method to add template labels
            Get all kandi verified functions for this library.

            psutil Key Features

            No Key Features are available at this moment for psutil.

            psutil Examples and Code Snippets

            Load
            Pythondot img1Lines of Code : 0dot img1License : Weak Copyleft (LGPL-3.0)
            copy iconCopy
            "In short it is the average sum of the number of processes
            waiting in the run-queue plus the number currently executing
            over 1, 5, and 15 minutes time periods."  
            Install
            Pythondot img2Lines of Code : 0dot img2License : Weak Copyleft (LGPL-3.0)
            copy iconCopy
            pip install glances
            pip install glances[all]
            pip install --upgrade glances
            pip install --upgrade psutil
            pip install --upgrade glances[all]  
            Other system info
            Pythondot img3Lines of Code : 0dot img3License : Permissive (BSD-3-Clause)
            copy iconCopy
            >>> import psutil
            >>> psutil.users()
            [suser(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0, pid=1352),
             suser(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0, pid=1788)]
            >>  
            How to find out the full command with which the process was launched?
            Pythondot img4Lines of Code : 3dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import psutil
            psutil.Process(pid=xxx).cmdline()
            
            how to get cpu stats every 15 seconds ? python
            Pythondot img5Lines of Code : 18dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            try:
                import psutil, time
                while True:
                    d = psutil.cpu_percent(1.5)
                    e = psutil.cpu_percent(1.5)
                    f = psutil.cpu_percent(1.5)
                    g = psutil.cpu_percent(1.5)
                    
                    val = (d + e + f + g)/4
                    p
            PIP failed to build package cytoolz
            Pythondot img6Lines of Code : 4dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            python -m pip install --user cython
            python -m pip install --user cytoolz
            python -m pip install --user eth-brownie
            
            Python: Getting current Connection Type (Lan, Wifi, Mobile(sim card)) of device
            Pythondot img7Lines of Code : 92dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            >>> import psutil
            >>> from pprint import pprint
            
            >>> nets = psutil.net_if_stats()
            >>> pprint(nets)
            {'Bluetooth 네트워크 연결': snicstats(isup=False, duplex=, speed=3, mtu=1500),
             'Loopback Pseudo-Interface 1':
            how to check service running on other server with python
            Pythondot img8Lines of Code : 13dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                        ip = your_ip
                        server_user = your_serviceuser
                        server_pass = your_pass
                        command = f"net use \\\\{ip} {server_pass} /USER:{server_user}"
                        os.system(command)
                        command = f"SC \
            No such file or directory: '/opt/anaconda3/lib/python3.8/site-packages/rtree/lib'
            Pythondot img9Lines of Code : 4dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            python is /opt/anaconda3/bin/python
            python is /usr/local/bin/python
            python is /usr/bin/python
            
            Avoid huge memory usage in Python when substituting elements in large list of strings
            Pythondot img10Lines of Code : 37dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            l = [["23873498uh3149ubn34",
                  "59ubn23459un3459",
                  "un3459-un345",
                  "9u3n45iu9n345",
                  str(i)] for i in range(10_000_000)]
            
            >>> print(l[10][2] is l[56000][2]) # first indices are arbitrar

            Community Discussions

            QUESTION

            Pythoncom - Passing same COM object to multiple threads
            Asked 2022-Mar-29 at 07:59

            Hello :) I´m a complete beginner when it comes to COM objects, any help is appreciated!

            I´m working on a Python program supposed to read incoming MS-Word documents in a client/server fashion, i.e. the client sends a request (one or multiple MS-Word documents) and the server reads specific content from those requests using pythoncom and win32com.

            Because I want to minimize waiting time for the client (client needs a status message from server, I do not want to open an MS-Word instance for every request. Hence, I intend to have a pool of running MS-Word instances from which the server can pick and choose. This, in turn, means I have to reuse those instances from the pool in different threads and this is what causes trouble right now. After I read Using win32com with multithreading, my dummy code for the server looks like this:

            ...

            ANSWER

            Answered 2022-Mar-29 at 07:59

            What happens is you put back in the "activePool" a COM reference that you got from CoGetInterfaceAndReleaseStream. But this reference was created specially for this new thread and then you call CoMarshalInterThreadInterfaceInStream on this new reference.

            That's what is wrong.

            You must always use the original COM reference you got from the thread that created it, to be able to call CoMarshalInterThreadInterfaceInStream repeatedly.

            So, to solve the problem, you must change how your apppool works, use some kind of a "in use" flag but don't touch the original COM reference.

            Source https://stackoverflow.com/questions/71618529

            QUESTION

            PIP failed to build package cytoolz
            Asked 2022-Mar-26 at 18:26

            I'm trying to install eth-brownie using 'pipx install eth-brownie' but I get an error saying

            ...

            ANSWER

            Answered 2022-Jan-02 at 09:59

            I used pip install eth-brownie and it worked fine, I didnt need to downgrade. Im new to this maybe I could be wrong but it worked fine with me.

            Source https://stackoverflow.com/questions/69875694

            QUESTION

            Open installed apps on Windows intelligently
            Asked 2022-Mar-23 at 09:17

            I am coding a voice assistant to automate my pc which is running Windows 11 and I want to open apps using voice commands, I don't want to hard code every installed app's .exe path. Is there any way to get a dictionary of the app's name and their .exe path. I am able to get currently running apps and close them using this:

            ...

            ANSWER

            Answered 2022-Mar-02 at 09:40

            This can be accomplished via the following code:

            Source https://stackoverflow.com/questions/71320226

            QUESTION

            how to check service running on other server with python
            Asked 2022-Mar-14 at 13:12

            I have a problem with checking my service on other windows or Linux servers.

            My problem is that I have to make a request from one server to the other servers and check if the vital services of those servers are active or disabled.

            I wrote Python code to check for services, which only works on a local system.

            ...

            ANSWER

            Answered 2022-Mar-08 at 17:46

            As far as I know, psutil can only be used for gathering information about local processes, and is not suitable for retrieving information about processes running on other hosts. If you want to check whether or not a process is running on another host, there are many ways to approach this problem, and the solution depends on how deep you want to go (or need to go), and what your local situation is. From the top of my head, here are some ideas:

            If you are only dealing with network services with exposed ports:

            • A very simple solution would involve using a script and a port scanner (nmap); if a port that a service is listening behind, is open, then we can assume that the service is running. Run the script every once in a while to check up on the services, and do your thing.

            • If you want to stay in Python, you can achieve the same end result by using Python's socket module to try and connect to a given host and port to determine whether or not the port that a service is listening behind, is open.

            • A Python package or tool for monitoring network services on other hosts like this probably already exists.

            If you want more information and need to go deeper, or you want to check up on local services, your solution will have to involve a local monitor process on each host, and connecting to that process to gather information.

            • You can use your code to implement a server that lets clients connect to it, to check up on the services running on that host. (Check the socket module's official documentation for examples on how to implement clients and servers.)

            Here's the big thing though. Based on your question and how it was asked, I would assume that you do not have the experience nor the insight to implement this in a secure way yet. If you're using this for a simple hobby/student project, roll out your own solution, and learn. Otherwise, I would recommend that you check out an existing solution like Nagios, and follow the security recommendations very closely.

            Source https://stackoverflow.com/questions/71393915

            QUESTION

            Colab: (0) UNIMPLEMENTED: DNN library is not found
            Asked 2022-Feb-08 at 19:27

            I have pretrained model for object detection (Google Colab + TensorFlow) inside Google Colab and I run it two-three times per week for new images I have and everything was fine for the last year till this week. Now when I try to run model I have this message:

            ...

            ANSWER

            Answered 2022-Feb-07 at 09:19

            It happened the same to me last friday. I think it has something to do with Cuda instalation in Google Colab but I don't know exactly the reason

            Source https://stackoverflow.com/questions/71000120

            QUESTION

            pip install xlwings fails
            Asked 2022-Jan-28 at 04:30

            I'm on MacOS Mojave Version 10.14.6, 2.8 GHz Intel Core i7 processor. Python version: 2.7.

            "pip install xlwings" fails for me. I have tried to resolve this by upgrading setuptools with pip install -U setuptools

            However, this does not fix the issue. The full error message for "pip install xlwings" is as follows:

            ...

            ANSWER

            Answered 2022-Jan-28 at 04:30

            xlwings declares appscript as a dependency but it doesn't limit version; appscript doesn't properly declare Python version compatibility (xlwings does it properly) so pip is trying to install the latest version which is not compatible with Python 2.7. Try to limit versions this way:

            Source https://stackoverflow.com/questions/70888688

            QUESTION

            Avoid memory fragmentation when memory pools are a bad idea
            Asked 2022-Jan-12 at 17:45

            I am developing a C++ application, where the program run endlessly, allocating and freeing millions of strings (char*) over time. And RAM usage is a serious consideration in the program. This results in RAM usage getting higher and higher over time. I think the problem is heap fragmentation. And I really need to find a solution.

            You can see in the image, after millions of allocation and freeing in the program, the usage is just increasing. And the way I am testing it, I know for a fact that the data it stores is not increasing. I can guess that you will ask, "How are you sure of that?", "How are you sure it's not just a memory leak?", Well.

            This test run much longer. I run malloc_trim(0), whenever possible in my program. And it seems, application can finally return the unused memory to the OS, and it goes almost to zero (the actual data size my program has currently). This implies the problem is not a memory leak. But I can't rely on this behavior, the allocation and freeing pattern of my program is random, what if it never releases the memory ?

            • I said memory pools are a bad idea for this project in the title. Of course I don't have absolute knowledge. But the strings I am allocating can be anything between 30-4000 bytes. Which makes many optimizations and clever ideas much harder. Memory pools are one of them.
            • I am using GCC 11 / G++ 11 as a compiler. If some old versions have bad allocators. I shouldn't have that problem.
            • How am I getting memory usage ? Python psutil module. proc.memory_full_info()[0], which gives me RSS.
            • Of course, you don't know the details of my program. It is still a valid question, if this is indeed because of heap fragmentation. Well what I can say is, I am keeping a up to date information about how many allocations and frees took place. And I know the element counts of every container in my program. But if you still have some ideas about the causes of the problem, I am open to suggestions.
            • I can't just allocate, say 4096 bytes for all the strings so it would become easier to optimize. That's the opposite I am trying to do.

            So my question is, what do programmers do(what should I do), in an application where millions of alloc's and free's take place over time, and they are of different sizes so memory pools are hard to use efficiently. I can't change what the program does, I can only change implementation details.

            Bounty Edit: When trying to utilize memory pools, isn't it possible to make multiple of them, to the extent that there is a pool for every possible byte count ? For example my strings can be something in between 30-4000 bytes. So couldn't somebody make 4000 - 30 + 1, 3971 memory pools, for each and every possible allocation size of the program. Isn't this applicable ? All pools could start small (no not lose much memory), then enlarge, in a balance between performance and memory. I am not trying to make a use of memory pool's ability to reserve big spaces beforehand. I am just trying to effectively reuse freed space, because of frequent alloc's and free's.

            Last edit: It turns out that, the memory growth appearing in the graphs, was actually from a http request queue in my program. I failed to see that hundreds of thousands of tests that I did, bloated this queue (something like webhook). And the reasonable explanation of figure 2 is, I finally get DDOS banned from the server (or can't open a connection anymore for some reason), the queue emptied, and the RAM issue resolved. So anyone reading this question later in the future, consider every possibility. It would have never crossed my mind that it was something like this. Not a memory leak, but an implementation detail. Still I think @Hajo Kirchhoff deserves the bounty, his answer was really enlightening.

            ...

            ANSWER

            Answered 2022-Jan-09 at 12:25

            If everything really is/works as you say it does and there is no bug you have not yet found, then try this:

            malloc and other memory allocation usually uses chunks of 16 bytes anyway, even if the actual requested size is smaller than 16 bytes. So you only need 4000/16 - 30/16 ~ 250 different memory pools.

            Source https://stackoverflow.com/questions/70602043

            QUESTION

            Running odoo in Debugging VSCode and found error ModuleNotFoundError: No module named 'stdnum' - - -
            Asked 2021-Dec-27 at 17:01

            i using VSCode as my IDE for development odoo and for now run using Start > Debugging ( F5)

            While running at web browser localhost:8069 ( default ) then appear Internal Server Error and in terminal VSCode there are errors :

            ...

            ANSWER

            Answered 2021-Dec-27 at 17:01

            After trying for a few days and just found out that pip and python in the project are not pointing to .venv but to anaconda due to an update. when error

            no module stdnum

            actually there is a problem with pip so make sure your pip path with which pip or which python

            1. to solve .venv that doesn't work by deleting the .venv folder, create venv in python, and install all requirements again

            Source https://stackoverflow.com/questions/70457690

            QUESTION

            Can't install Azure packages with pip: ruamel.yaml error
            Asked 2021-Nov-27 at 17:57

            I'm having trouble installing the following packages in a new python 3.9.7 virtual environment on Arch Linux.

            My requirements.txt file:

            ...

            ANSWER

            Answered 2021-Nov-27 at 17:57

            The ruamel.yaml documentation states that it should be installed using:

            Source https://stackoverflow.com/questions/70136750

            QUESTION

            Tensorflow Object Detection API taking forever to install in a Google Colab and failing
            Asked 2021-Nov-19 at 00:16

            I am trying to install the Tensorflow Object Detection API on a Google Colab and the part that installs the API, shown below, takes a very long time to execute (in excess of one hour) and eventually fails to install.

            ...

            ANSWER

            Answered 2021-Nov-19 at 00:16

            I have solved this problem with

            Source https://stackoverflow.com/questions/70012098

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Install psutil

            You can install using 'pip install psutil' or download it from GitHub, PyPI.
            You can use psutil like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install psutil

          • CLONE
          • HTTPS

            https://github.com/giampaolo/psutil.git

          • CLI

            gh repo clone giampaolo/psutil

          • sshUrl

            git@github.com:giampaolo/psutil.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Monitoring Libraries

            netdata

            by netdata

            sentry

            by getsentry

            skywalking

            by apache

            osquery

            by osquery

            cat

            by dianping

            Try Top Libraries by giampaolo

            pyftpdlib

            by giampaoloPython

            pysendfile

            by giampaoloPython

            confix

            by giampaoloPython

            psutil-cli

            by giampaoloPython

            giampaolo.github.io

            by giampaoloHTML