Good weekend, everyone. The second original article of the day is here. Today, we mainly bring a system administrator daily use of an operation and maintenance tool, I hope you have harvest.
Psutil (Process and System Utilities) is a cross-platform library that manages system resources through ps, top (htop), ifconfig, and kill commands.
With it we can better system monitoring, analysis and limit the use of system resources, is a necessary tool for system administrators.
Installation:
PIP install psutil
1> import psutil 2> psutil.cpu_count() 31 4> psutil.cpu_count(logical=False) # Number of physical cpus 5> mem = psutil.virtual_memory() 6> mem.total 916676044810> psutil.disk_partitions() # 11[sdiskPart (device='/dev/vda1', mountpoint='/', fstype='ext4', opts='rw,relatime,errors=remount-ro,stripe=32639,data=ordered'),12 sdiskpart(device='/dev/vda1', mountpoint='/var/lib/docker/aufs', fstype='ext4', Opts =' rW,relatime,errors=remount-ro,stripe=32639,data=ordered')] 12 > psutil.pids( Psuitl.process (32470).name()Copy the code
Psutil includes CPU, memory, disk, and process information, as well as network information, user logins, and boot time.
After we get these information, we can do a simple server memory monitoring, without the need to use a full set of tools such as StastSD + Promeuthus or Graphite + Grafana for large-scale monitoring system services and API data.
Can be reference to the articles of the cow force | build Web performance monitoring system from 0 to 1
Finally, you can look at other uses of ipython, which I’ve mentioned for a long time.
Hope you have a good weekend!
The articles
Let’s talk about the latest embarrassing incident in the tech world
From today on, be an idle man, feed the horses, chop wood, travel around the world…