A Weird Imagination

Monitor all the things

CPU and memory#

On Linux, the basic way to monitor load is to use top. The only thing top really has going for it is that it is almost certainly available on any system you will ever use. Luckily, there's a better way: htop. htop supports colors and mouse clicks and lists the available key commands at the bottom of the terminal. It also can be customized to your liking. You can start by putting my htoprc in your ~/.config/htop/ directory:

$ mkdir -p ~/.config/htop/
$ cd ~/.config/htop/
$ wget https://gist.githubusercontent.com/dperelman/1e051f5705685cb41f31/raw/3ab9cf17b166120a805d5f76a71ce82452f553b4/htoprc

Or just explore the options yourself.

Hit F1 (or click Help in the bottom-left) to get an explanation of the colors used in the CPU and memory bars and a guide to keystrokes not listed at the bottom.

In my usage, I find insufficient memory is more often the problem than CPU, so I usually leave htop sorted by the MEM% column.

Other resources#

While CPU and memory are the easiest to monitor resources, they are not the only ones. Linux offers a wide variety of system monitors, depending on what resource you want to monitor and what format you want to view it in. This post focuses on real-time viewing with human-friendly displays but most of these have options or variants that support logging historical data in a more machine-friendly format as well.

GPU#

With modern workloads often doing computations on GPUs, just monitoring the CPU and main memory is not enough. There does not seem to be any universal utility for watching GPU usage, instead, each vendor has their own separate utility. Choose the right one for your GPU.

If you don't know what brand GPU a computer has, you can check with lspci:

$ lspci | grep -F VGA
00:02.0 VGA compatible controller: Intel Corporation 82815 Chipset Graphics Controller (CGC) (rev 11)

Disk I/O#

The iotop command will show which processes are reading or writing to a local drive. Due to security concerns about I/O usage possibly leaking private information about the length of passwords, iotop must be run as root:

$ sudo iotop

iotop has a few options to filter its output. Particularly notable is -o (also toggled by the o key when running), which hides processes with zero disk I/O.

Networking#

This blog post covers many tools for watching how much bandwidth your computer is using. For graphical views, there are three main dimensions you are likely to care about: transfer rate, time, and remote host. It's difficult to make a chart with all three, so if you want to see transfer rate over time, use nload or if you want to see the current transfer rate split over which connection is using the bandwidth, use iftop1 . If neither of those meets your needs, do look through the list of network monitors, and hopefully one of them will.

Power#

While modern laptops get quite long battery life without any special effort, if you're using an older machine or just away from an outlet for longer than normal, powertop can help you eke out a little more battery life. It helped me get my T60 up from 4 hours to 5 hours of battery life turning off everything possible.

Even if you aren't counting watts, it's still interesting to see exactly how much power your computer is using and which components are using it.

Latency#

If you care about latency on your system, you can track down its causes using latencytop, although if you are not developing a latency-sensitive application or kernel patch, you likely don't have a use for latencytop. In addition to requiring root (or proper permissions), latencytop requires a kernel compile flag that is most likely not enabled in your distribution's kernel:

$ grep -F CONFIG_LATENCYTOP /boot/config-$(uname -r) /proc/config.gz
# CONFIG_LATENCYTOP is not set
grep: /proc/config.gz: No such file or directory

so if you want to use it you will have to compile your own kernel.


  1. if is short for interface to go along with ifconfig

Comments

Have something to add? Post a comment by sending an email to comments@aweirdimagination.net. You may use Markdown for formatting.

There are no comments yet.