Monitoring your *nix computer.


""


One of the things about Unix, and nowadays, Linux, is that there's a lot going on all the time. Sysadmins and users alike need to be aware of the load on the system and as a result, many monitors have been written and deployed over time. We will star with the "default" and probably oldest system monitors, top. This uility shows CPU load, memory usage and a list of running processes.

While it's running, you can press keys to perform actions such as killing a process (k), changing a process's priority with renice (r), or sorting the process list by CPU (P), memory (M), or runtime (T). You can also filter processes by user (u), toggle between command name and full command line (c), or customise which columns are shown (f) and their order (o). Pressing h brings up a help screen with all available commands, and q exits the interface. These shortcuts make top not just a monitoring tool, but also an interactive environment for managing system performance in real time.

the top command offers several interactive features that make it a powerful tool for monitoring and managing system processes. While it's running, you can press keys to perform actions such as killing a process (`k`), changing a process's priority with renice (`r`), or sorting the process list by CPU (`P`), memory (`M`), or runtime (`T`). You can also filter processes by user (`u`), toggle between command name and full command line (`c`), or customise which columns are shown (`f`) and their order (`o`). Pressing `h` brings up a help screen with all available commands, and `q` exits the interface. These shortcuts make `top` not just a monitoring tool, but also an interactive environment for managing system performance in real time. It's been around a long time, I recall being shown the command to use on the Unix systems in university, forty-odd years ago.

Coming more up to date, as i began running Linux as a daily driver, i discovered or was shown htop, a more informative, prettier and interactive solution. it's possible to use cursor keys to move around the process list and there are keyboard shortcuts using function keys to organise and interact with the list. Soon I discovered btop, even prettier and capable of being customised. Other useful monitors include atop and glances and the ubiquitous nmon. in addition to these, run from a terminal window, I have conky running on my desktop, showing me useful information like date and time, free memory, disk and swap space and many other useful things. conky is highly configurable, well documented and quite popular with those who like to rice their desktops. it looks good and at a glance i can see how my wifi connection is doing, what each of my cpu cores is up to, battery health, core tempertures and of course a list of current processes. For insight on that, see a screenshot on Imgur. most f these advanced monitors should be available for installation through your distro's usual channels.

Sooner or later, everyone needs to monitor some aspect of their system, so i hope this will help throw some light on possibilities for general system monitoring in *nix systems. It's possible to do live monitoring of some systems or devices using short commands or script such as watch command, for example: watch -n 1 cat /proc/net/wireless or watch -n 2 'free -h | grep Swap'. The oddest things can be looked at in Linux, hence this silly thing I wrote out of curiosity, on discovering the file /proc/sys/kernel/random/entropy_avail:

#!/bin/bash
####### edit INTERVAL and DURATION as required.########


# Print the table header
print_header() {
  echo "Time                Entropy     Δ Entropy"
  echo "-----------------------------------------------"
}

# Function to print the table row
print_row() {
  local time="$1"
  local entropy="$2"
  local delta_entropy="$3"
  printf "%-20s %-12s %s\n" "$time" "$entropy" "$delta_entropy"
}

##------------ Interval in seconds
INTERVAL=3

##------------ Duration in seconds
DURATION=240

# Calculate the number of iterations
ITERATIONS=$((DURATION / INTERVAL))

# Print the table header
print_header

# Capture the initial entropy and check if it's a valid number
initial_entropy=$(cat /proc/sys/kernel/random/entropy_avail)
echo "Initial entropy: $initial_entropy"

# Initialize tracking variables
PREVIOUS_ENTROPY=$initial_entropy
TOTAL_DELTA=0

# Loop to gather entropy data
for ((i = 0; i < ITERATIONS; i++)); do
  CURRENT_TIME=$(date +"%Y-%m-%d %H:%M:%S")
  CURRENT_ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)

  # Validate the entropy value
  if +$ ]; then
    echo "Error: Unable to read entropy value."
    exit 1
  fi

  # Calculate the delta
  if (( i == 0 )); then
    DELTA_ENTROPY=0
  else
    DELTA_ENTROPY=$((CURRENT_ENTROPY - PREVIOUS_ENTROPY))
  fi

  # Update totals
  TOTAL_DELTA=$((TOTAL_DELTA + DELTA_ENTROPY))
  PREVIOUS_ENTROPY=$CURRENT_ENTROPY

  # Print the current row
  print_row "$CURRENT_TIME" "$CURRENT_ENTROPY" "$DELTA_ENTROPY"

  sleep $INTERVAL
done

# Summary output
echo "-----------------------------------------------"
echo "Overall Δ Entropy: $TOTAL_DELTA"

i could also mention some of the additional, more specialised monitors such as perf, wavemon, conntrack, systemd-cgtop, iftop, vnstat, and iotop, but i'd be here all day. one of them, powertop, monitors and displays system power usage; massively handy for a laptop user! it can also help to 'calibrate' the system, using powertop --auto-tune. I can't recommend it highly enough.






$ xclip -o | wc -w
837

Log in or register to write something here or to contact authors.