Refer to this article for more background information on Python virtual environments, in combination with P圜harm Installing the PsUtil package from PyPi It won’t affect your system’s Python installation or your other Python projects. You can then install whatever package, and even a specific version of a package, just for the project you work on. I highly recommend using a separate Python virtual environment for each of your Python projects. I named it the same as the project and located it in subdirectory venv of my home directory.Select the option to create a new virtual environment for the project and specify its location.I called the project psutil-demo and located it in subdirectory PycharmProjects of my home directory.Select the location and name of the project.We’ll make use of P圜harm’s feature to automatically create and manage a Python virtual environment for our psutil-demo project. Let’s create a new project, called psutil-demo, for testing out the CPU and RAM usage functions. Sudo apt install build-essential python3 python3-dev python3-venv python3-pip Project and virtual environment creation On Debian you can achieve this by installing the following system packages: Since we plan on working with some Python code, let’s prepare our Linux system for Python development. It is based on the Gnome desktop environment and has the P圜harm Community Edition installed. Refer to this article for instructions on how to quickly install the P圜harm Community Edition on your system.įor writing this article and testing out the example code, I used my Debian 10 based laptop. The free P圜harm Community Edition suffices. Ideally, you also have P圜harm installed, the excellent Python IDE from JetBrains. Consequently, all you need for this article is a basic Linux installation with desktop environment. ![]() Pretty much all Linux distributions come bundled with Python 3. But isn’t it more fun to build something yourself? It could be an enjoyable and educational hobby project. You could write a small Python program to read and visualize the logged CPU and RAM usage.Īren’t there tools for this already? Sure, you could install something such as Sysstat.With the help of Logrotate you could control how long a history of logged data to keep.A periodic Cron job could write the CPU and RAM usage to a log-file, including a time stamp.This information can help you determine if it’s time to upgrade your server hardware. Long term logging of CPU and RAM usage of a server.Why would you want to create your own PsUtil based Python program to monitor CPU and RAM usage? Well, I can think of a few examples. Later on, you can simply copy-paste these functions into your own Python programs. I’ll present a number of Python functions to obtain CPU and RAM usage, based on the PsUtil package. This article teaches you how to install the PsUtil package into your Python virtual environment and how you can use it, to monitor the CPU and RAM usage from your own Python program. With PsUtil, you can quickly whip together your own system monitor tool in Python. ![]() This makes it easy to add system utilization monitoring functionality to your own Python program. With the PsUtil package installed in your Python (virtual) environment, you can obtain information about CPU and RAM usage. This makes installing the PsUtil package a breeze with the help of pip. Furthermore, he publishes stable releases of PsUtil on the Python Package Index (PyPi). He works on the code regularly in his public PsUtil GitHub repository. He has done so for over a decade now, meaning that the code base is quite mature and stable. ![]() Giampaolo Rodola initially developed and currently maintains the PsUtil code. PsUtil is a Python package with functionality to easily obtain system utilization information. ![]() Want to monitor the CPU and RAM usage of your Linux system from your own Python program? Then you came to the right place! This article teaches you how to install the PsUtil package into your Python virtual environment and how you can use it to monitor the CPU and RAM usage from your own Python program.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |