Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

System Performance Monitoring Commands (Memory, Disk I/O, CPU)

Notes 1

Memory Usage Monitoring

Virtual memory extends physical memory using disk space, where inactive memory pages are swapped out to disk to free up RAM for active processes. When needed again, these pages are read back into memory transparently to the user. On Linux systems, virtual memory typically refers to swap partitions, which are organized into 4KB pages.

Each process requests virtual memory upon startup. The kernel either grants or denies the request. Actual memory usage (RSS) reflects how much physical RAM a process currently occupies. The ps command displays both virtual size (VSZ) and resident set size (RSS).

The free command provides an overview of system memory consumption:

free -h

To examine memory usage per process:

pmap -d <PID>

Use ps to list processes with detailed memory metrics:

ps -eo pid,comm,args,pcpu,rsz,vsz,stime,user,uid

Filter results for specific users or processes:

ps -eo pid,comm,args,pcpu,rsz,vsz,stime,user,uid | grep root | sort -nrk5

To identify top memory-consuming processes:

ps -auxf | sort -nr -k 4 | head -10

Disk I/O and Network Monitoring

For I/O performance analysis, use iostat:

iostat -x

Key metrics to monitor include rkB/s and wkB/s, indicating read and write throughput in kilobytes per second respectively.

CPU Performance Diagnostics

Critical CPU metrics include load average and utilization percentage:

  • CPU utilization above 50% warrants attention.
  • Above 70%, immediate investigation is required.
  • At 90% or higher, the system is under severe stress.

Load average exceeding the number of CPU cores indicates increasing workload. If it exceeds twice the core count, the system is heavily loaded.

Diagnostic approach:

  1. Identify processes with high CPU usage.
  2. Locate threads within those processes consuming most CPU.
  3. Capture thread stack traces.
  4. Analyze execution flow.

Example simulation of 100% CPU load:

stress --cpu 1 --timeout 600

Monitor with top and observe the process with highest CPU usage. Note its PID and analyze threads:

top -Hp <PID>

Capture thread dump using:

jstack -l <PID> > ./thread_dump.log

Additional utilities for CPU monitoring:

List top CPU-consuming processes:

ps -auxf | sort -nr -k 3 | head -10

Check system load:

watch -d uptime

Monitor individual CPU usage:

mpstat -P ALL 5

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Spring Boot MyBatis with Two MySQL DataSources Using Druid

Required dependencies application.properties: define two data sources and poooling Java configuration for both data sources MyBatis mappers for each data source Controller endpoints to verify both co...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.