CareerByteCode
ByteBlogby CareerByteCode
📰 Published in Chennai FutureTech Voices

SRE in Practice | Day 12: Linux Monitoring and USE

Check CPU, memory, disk, and network the structured way. Eight hands-on labs, each with every command explained in plain words and a guide to reading the result.

SRE in Practice | Day 12: Linux Monitoring and USE
📚 Part 12 of 12 in SRE in Practise - 30 days

✍️ Translate this blog into Hindi, Tamil or Telugu

What you will learn

  • The USE method and why it finds bottlenecks quickly
  • How to read load average, vmstat, free, df, and ps in plain terms
  • The difference between a busy CPU and a CPU waiting on disk
  • Eight labs, each with plain-language explanations and how to read the result, ending in a working checker script

Safety first: All commands are read-only or touch only files under /tmp/sre-lab that you create. Run them on a system you are authorized to use. Never run cleanup or deletion commands on real data until you have reviewed a dry run, and do not paste logs containing credentials or customer data into public posts.


In one minute: When a Linux server feels slow, do not guess. For every resource (CPU, memory, disk, network) ask three questions: Utilization (how busy is it?), Saturation (is work waiting in a queue?), and Errors (is anything failing?). This is the USE method. Think of a checkout counter: utilization is how long the cashier is busy, saturation is the length of the queue, and errors are the cards that get declined.

1. The USE method

The USE method, described by performance engineer Brendan Gregg, gives you a short checklist so you do not forget a resource. You go through each resource and check the three things. It finds most common bottlenecks quickly.

2. How to read the key numbers

Load average (the three numbers from uptime) is the average number of tasks that wanted to run, over the last 1, 5, and 15 minutes. On Linux it also counts tasks waiting for disk. Divide it by the number of CPU cores. Around 1.0 per core means the CPUs are fully used. Much more than that means work is queuing. If the 1-minute number is higher than the 15-minute number, load is rising; if lower, it is falling.

🛍️✨ From the author · ByteStoreLinux & Cloud Administration Consultation | AWS & Azure Infrastructure Supportβ‚Ή499View offer →

CPU percentages in vmstat: us is user work, sy is kernel work, id is idle, wa is waiting for disk or network I/O (a high number means the disk is the bottleneck, not the CPU), and st is time stolen by the hypervisor on a VM.

Memory: do not panic about low free memory. Linux uses spare memory to cache files, which is good. The number to watch is available, which is how much could be used by programs without swapping. Constant swapping (si and so above zero) is the real warning sign.

Disk: two things can fill up: space (df -h) and inodes, the file entries (df -i). Either can stop an application from writing.

3. A production-style example

This is an illustrative scenario. A web application on a Linux VM becomes slow at 14:00. Following USE: load per core is 3.2 (CPU saturated?), but vmstat shows us at 12% and wa at 70%. The CPUs are mostly idle, waiting for the disk. A check of disk space shows 97% used, and a log directory has grown by gigabytes. The fix is to clear the old logs and add log rotation, not to add CPUs. Without USE, the high load number could easily have led to the wrong fix.

4. Hands-on labs

Safety notes: All commands are read-only or touch only files under /tmp/sre-lab that you create. Run them on a system you are authorized to use. Never run cleanup or deletion commands on real data until you have reviewed a dry run, and do not paste logs containing credentials or customer data into public posts. Two labs briefly use one CPU core on purpose, for at most 8 seconds, using the timeout command. Do not run them on a busy production server.

Setup

mkdir -p /tmp/sre-lab && cd /tmp/sre-lab

Lab 1: Is the CPU queue growing? (load average)

Goal: Read the load average and turn it into a number per core.

Why it matters: It is the fastest first look at whether a machine is overloaded.

uptime
awk -v c=$(nproc) '{printf "load1=%s load5=%s load15=%s cores=%d per_core=%.2f\n",
                    $1, $2, $3, c, $1/c}' /proc/loadavg

Expected output

 10:15:02 up 12 days,  3:41,  1 user,  load average: 0.08, 0.05, 0.01
load1=0.08 load5=0.05 load15=0.01 cores=2 per_core=0.04

How to read the result: Your numbers will differ. A per_core value of 0.04 means the CPUs are nearly idle. Values near 1.0 mean full. Values like 3.0 mean three times more work than the CPUs can do at once, so tasks are waiting. Compare the three numbers too: if load1 is much larger than load15, the problem is new.

Lab 2: CPU: see idle versus busy with vmstat

Goal: Watch the CPU go from idle to busy and learn the vmstat columns.

Why it matters: vmstat is available on almost every Linux system and shows CPU, memory, and I/O in one line per second.

vmstat 1 3                                   # a quiet machine: 3 samples

timeout 6 sh -c 'while :; do :; done' &      # busy loop for 6 seconds
sleep 0.5; vmstat 1 4; wait 2>/dev/null

Expected output

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 1  0      0 3992236   3684  48412    0    0   427     5   40    0  0  1 99  0  0  0
 0  0      0 3992216   3684  48412    0    0     4     0   26   34  0  0 100  0  0  0
 0  0      0 3992204   3684  48468    0    0     0     0   32   41  0  0 100  0  0  0
(second command, during the busy loop)
 1  0      0 3991924   3684  48556    0    0     0     0  258   38 100  0  0  0  0  0
 1  0      0 3991924   3684  48556    0    0     0     0  255   21 100  0  0  0  0  0

How to read the result: Look at the right-hand columns. id (idle) is 99-100 while the machine is quiet. During the busy loop, us jumps to 100 and id falls to 0: the CPU is fully used. r is the number of tasks wanting to run. On this one-core machine r stays at 1. If r is much larger than your core count, the CPU is saturated. wa stayed 0 here, meaning no disk waiting. Your vmstat may not have the last gu column, and the numbers on your machine will differ.

Try it yourself: Run two busy loops at once by repeating the timeout line twice before vmstat. Notice r goes to 2 on a one-core machine: one task is always waiting. That is saturation.

Lab 3: Memory: free versus available

Goal: Learn which memory number matters.

Why it matters: Beginners often see "free" memory near zero and think something is wrong. It usually is not.

free -m
free -m | awk 'NR==2{printf "available: %d MB (%.0f%% of total)\n", $7, $7/$2*100}'

Expected output

               total        used        free      shared  buff/cache   available
Mem:            3990         186        3898          16          51        3803
Swap:              0           0           0
available: 3803 MB (95% of total)

How to read the result: Here 95% of memory is available, so memory is healthy. If available dropped under about 10%, or if the swap row showed heavy use with si/so activity in vmstat, memory would be the bottleneck. A big buff/cache number is normal. Linux fills spare RAM with cached files and gives it back when programs need it.

Lab 4: Disk: find what is using the space

Goal: Practise the two checks you need when a disk fills: how full, and what is big.

Why it matters: A full disk is one of the most common causes of outages, and it is easy to find.

df -h /
df -i /
mkdir -p /tmp/sre-lab/disk && cd /tmp/sre-lab/disk
dd if=/dev/zero of=small.bin  bs=1M count=1  status=none
dd if=/dev/zero of=medium.bin bs=1M count=5  status=none
dd if=/dev/zero of=large.bin  bs=1M count=20 status=none
du -ah /tmp/sre-lab/disk | sort -rh | head -4

Expected output

/dev/vda        252G  9.1G  9.6G  49% /
/dev/vda       16777216 196760 16580456    2% /
27M     /tmp/sre-lab/disk
20M     /tmp/sre-lab/disk/large.bin
5.0M    /tmp/sre-lab/disk/medium.bin
1.0M    /tmp/sre-lab/disk/small.bin

How to read the result: The first line says the disk is 49% full, and the second says only 2% of inodes are used. Both are fine. The bottom list is the habit to learn: when a disk is nearly full, run du -ah on the suspect folder and sort. The biggest items are at the top. Clean up the practice files afterwards with rm -r /tmp/sre-lab/disk.

Lab 5: Processes: who is using the CPU?

Goal: Find the program responsible when the CPU is busy.

Why it matters: Knowing the machine is busy is only half the answer. You need to know what is busy.

🛍️✨ From the author · ByteStoreCareer gap analysis and Mentoring - Basic Planβ‚Ή299View offer →
timeout 8 sh -c 'while :; do :; done' &
sleep 1
ps -eo pid,comm,%cpu,%mem --sort=-%cpu | head -4
wait 2>/dev/null

Expected output

  PID COMMAND         %CPU %MEM
  138 sh              99.0  0.0
    1 process_api      0.4  0.1
   28 kworker/u4:1-ev  0.2  0.0

How to read the result: The top process is the practice loop (sh), using 99% of a core. In real life, the top line would be your culprit: a runaway script, a stuck application, or a backup job. Next you would look at that process's logs or stop it, but only with approval on production.

Lab 6: Network: errors and drops

Goal: Check whether the network interfaces are reporting problems.

Why it matters: Network problems often show up as dropped packets or errors long before a full outage.

awk 'NR>2{gsub(":"," ")
       printf "%-6s rx_bytes=%s rx_errs=%s rx_drop=%s ", $1, $2, $4, $5
       printf "tx_bytes=%s tx_errs=%s tx_drop=%s\n", $10, $12, $13}' /proc/net/dev
nc -zv 127.0.0.1 9 2>&1 | head -2

Expected output

lo     rx_bytes=0 rx_errs=0 rx_drop=0 tx_bytes=0 tx_errs=0 tx_drop=0
eth0   rx_bytes=20705 rx_errs=0 rx_drop=3 tx_bytes=14819 tx_errs=0 tx_drop=0
nc: connect to 127.0.0.1 port 9 (tcp) failed: Connection refused

How to read the result: These counters only go up, so what matters is the change over time. A small constant like rx_drop=3 is usually harmless, but a number that grows quickly means trouble. The nc line shows what a failed connection looks like: Connection refused means the machine answered but nothing is listening on that port. A timeout instead would suggest a firewall or routing problem. Interface names (eth0, ens5) differ between systems.

Lab 7: Build a mini USE checker

Goal: Combine the checks into one script that says OK or WARN and returns an exit code.

Why it matters: A script like this is the first step toward automation (Day 4) and alerting (Day 13).

cat > usecheck.sh <<'EOF'
#!/usr/bin/env bash
# usage: ./usecheck.sh [max_load_per_core] [min_mem_available_%] [max_disk_used_%]
lim_load="${1:-1.0}"; lim_mem="${2:-10}"; lim_disk="${3:-85}"; bad=0
load=$(awk -v c="$(nproc)" '{printf "%.2f", $1/c}' /proc/loadavg)
mem=$(free | awk 'NR==2{printf "%.0f", $7/$2*100}')
disk=$(df -P / | awk 'NR==2{gsub("%","",$5); print $5}')
check() {   # name value limit mode(high|low = which side is bad)
  if awk -v v="$2" -v l="$3" -v m="$4" \
       'BEGIN{exit !((m=="high" && v>l) || (m=="low" && v<l))}'; then
    echo "WARN  $1 = $2 (limit $3)"; bad=1
  else
    echo "OK    $1 = $2 (limit $3)"
  fi
}
check "cpu load per core"  "$load" "$lim_load" high
check "memory available %" "$mem"  "$lim_mem"  low
check "disk used % on /"   "$disk" "$lim_disk" high
exit $bad
EOF
chmod +x usecheck.sh

./usecheck.sh; echo "exit=$?"
./usecheck.sh 0.0 99 1; echo "exit=$?"     # forces every warning

Expected output

OK    cpu load per core = 0.05 (limit 1.0)
OK    memory available % = 95 (limit 10)
OK    disk used % on / = 49 (limit 85)
exit=0
WARN  cpu load per core = 0.05 (limit 0.0)
WARN  memory available % = 95 (limit 99)
WARN  disk used % on / = 49 (limit 1)
exit=1

How to read the result: The first run shows a healthy machine and exit code 0. The second run forces every check to fail, so you know the script really warns and returns 1. Your values will differ. A script is not trustworthy until you have seen it fail.

Lab 8 (worksheet): USE for your own server

5. Common mistakes

  • Panicking about "free" memory instead of looking at "available"
  • Reading load average without dividing by the number of cores
  • Blaming the CPU when the real problem is disk waiting (high wa)
  • Checking disk space but forgetting inodes
  • Looking at one moment instead of the trend
  • Running load tests or heavy commands on a busy production server

6. Quick check: test yourself

  • What do U, S, and E stand for in the USE method?
  • A 4-core server has load average 8.0. Is it saturated, and how do you know?
  • vmstat shows id=5 and wa=80. Is the CPU the bottleneck?
  • Why is a small "free" memory number usually not a problem?
  • What two things can fill a disk?

Suggested answers: utilization, saturation, errors; load per core is 2.0, so about twice as many tasks want to run as there are cores, which means queuing; probably not, wa=80 means the CPU is mostly waiting for I/O, so check the disk; Linux uses spare memory for caching, and available is the number that matters; space and inodes.

7. Key takeaways

  • USE: check utilization, saturation, and errors for CPU, memory, disk, and network.
  • Divide load average by the core count, and compare 1, 5, and 15 minute values.
  • Look at available memory, not free memory, and watch swapping.
  • High wa means the disk or network is the bottleneck, not the CPU.
  • Always find the process, not just the symptom, and test your scripts on their failure path.

Glossary

Your turn: Which resource on your busiest server would you check first, and what would you look for?

Coming next, Day 13: actionable alerts.

Follow @leadwithsreeΒ for the daily posts in this 30-day journey.

📚 Sources
  1. careerbytecode.in/byteblog/sre-in-practice-day-11-metrics-logs-and-traces
Read next →SRE in Practice | Day 7: SLOs and SLAs⏱ 6 min

🛍️ Srilakshmi T's shelf

Courses, cohorts and more from the author
Srilakshmi T
Written by Srilakshmi T
Cloud and Linux SRE Engineer
🏅 Contributor writer

Cloud & Linux SRE Engineer with 5 years of IT experience, including Linux/Unix system administration and cloud platforms (AWS & Azure). Strong expertise in production support, reliability engineering, monitoring, automation, patching, and incident management across large-scale e

Visit my ByteStoreFreelancer - Cloud Engineer
Open to workHire me →

🌟 See Srilakshmi T's full profile: blogs, work and verified certificates

Get Srilakshmi T's next blog by email

One email a week when they publish. Add the weekly Best of ByteBlog too. No spam, unsubscribe with one click.

We email you once to confirm. By subscribing you agree to the privacy policy.

💬 Comments (0)

Top · Newest

Sign in to comment

More from Srilakshmi T

🛍️✨ From the author · ByteStoreLinux & Cloud Administration Consultation | AWS & Azure Infrastructure Supportβ‚Ή499View offer →