SoFunction
Updated on 2025-03-04

How to view various system metric commands for Linux

Linux to view various system indicators and commands

In Linux systems, viewing various system metrics (such as CPU usage, memory usage, disk usage, network status, etc.) can be achieved through the following commonly used commands:

1. Check CPU usage

top

  • Displays the overall health status of the system in real time, including CPU, memory usage and information about each process.
  • according to1The keys can show the usage of each CPU core.

htop

  • topEnhanced version, providing a more friendly interface and more features (need to be installed).

mpstat

  • Displays the usage of each CPU, usually withsysstatToolkits are used together.
  • Example:mpstat -P ALL 1Displays usage per second for each CPU core.

2. Check memory usage

free -h

  • Displays the system's memory usage, including total, used, idle, and swap partition usage.
  • -hOptions indicate the display of data in a human-readable format (for example: MB, GB).

vmstat

  • Displays comprehensive statistics on system memory, swap partitions, and CPU resources.
  • Example:vmstat 1 5The system status is output once a second for 5 seconds.

3. Check disk usage

df -h

  • Displays the file system's disk space usage, including the total capacity, used, and available space for each partition.
  • -hOptions indicate the display of data in a human-readable format.

du -sh *

  • Displays the disk usage of each file or subdirectory in the specified directory and summarizes the output.
  • -sExpress a summary,-hRepresents are displayed in human-readable format.

iostat

  • Displays I/O statistics of disk devices, usually withsysstatToolkits are used together.
  • Example:iostat -x 1Detailed I/O statistics are displayed every second.

4. Check network status

ifconfigorip addr

  • Displays the configuration information of the network interface
  • Including IP address, subnet mask, etc.

netstat -tuln

  • Displays the currently open port and listening status of the system
  • Includes TCP and UDP ports

ss -tuln

  • netstatFaster alternatives
  • Show open ports and listening status

ping

  • Check network connectivity.
  • Example:ping Test connectivity to Google.

traceroute

  • Tracks the path of the packet from the local machine to the destination address.
  • Example:traceroute

5. Check the system load

uptime

  • Displays the system's running time and load average.

toporhtop

  • Display system load information in real time.

sar

  • System activity reports that can record and play back load data, usually withsysstatToolkits are used together.

6. View process information

ps aux

  • Displays all processes currently running on the system and their details.

toporhtop

  • Displays the system's processes and CPU and memory usage in real time.

pstree

  • Displays the process and its parent-child relationship in a tree structure.

Experience

These commands provide a comprehensive view of the system's various indicators and are the basic tools for daily operation and maintenance and problem investigation. When continuous monitoring is required, it can also be combinedwatchCommands to refresh the command output regularly, for example:watch -n 1 df -h

Here is a rumor to help you quickly remember the commands used to view various indicators of Linux system:

  • topCheck the overall CPU busy,
  • htopMore friendly interface;
  • mpstatNuclear dosage,
  • All data can be seen clearly.
  • freeCheck memory,vmstatMore comprehensive;
  • Disk spacedfBright,duView file lines;
  • iostatCheck I/O busy,
  • ifconfigConnect to the Internet,netstatFull ports.
  • uptimeCheck the load,
  • sarPlayable,
  • ps auxCheck the process,
  • pstreeFather and son appear.

Remember these commands one by one in a rumor, and have few worries about operation and maintenance management!

In Linux systems, to check the running status of a Java program, you can use the following commonly used commands to help you determine whether the Java program is suspended or is running normally:

1. Use the ps command

View Java Processes

usepsThe command lists the currently running Java processes.

Example:ps aux | grep java

Output example:

user      1234  0.0  2.1 561234 45123 ?        Sl   08:30   0:01 java -jar 

This command will display the followingjavaAll processes of the word. Check the CPU and memory usage of the process (especially%CPUand%MEMcolumn), if they are zero and the process has no output for a long time, the program may have been suspended.

2. Use the top or htop command

Real-time monitoring of Java processes

  • runtoporhtopCommand, then pressMThe keys can be sorted by memory usage, or pressPKey press CPU usage sort.
  • Find in the listjavaprocess, observe its CPU and memory usage.
  • If the Java process is found to have a CPU usage of 0% and the memory usage is stable, it may indicate that the program is in a suspended state.

3. Use the jps command

List all Java processes

jpsIt is a tool that comes with Java, which is used to list the currently running Java processes and their main class names.

Example:jps -l

Output example:

1234 

passjpsYou can quickly confirm whether the Java application is running, but it cannot directly determine whether the process is suspended.

4. Use the jstack command

View Java thread stack

  • jstackIt can generate thread stack information for Java processes, suitable for checking for deadlocks or suspended threads.
  • Example:jstack <pid>,in<pid>It is the process ID of the Java process (can be passedpsorjpsget).
  • Check the output for possible signs of deadlock or thread waiting for a long time.

5. Use the jstat command

Monitor JVM performance

  • jstatIt can monitor the JVM's memory usage, garbage collection activities and other information to help judge the health status of Java applications.
  • Example:jstat -gc <pid>Displays GC (garbage collection) statistics to help analyze whether the program is suspended due to memory problems.

6. Use the netstat command

Check the network connection of Java programs

  • If a Java program involves network communication, you can use itnetstatCheck its network connection status.
  • Example:netstat -anp | grep javaCheck all network connections related to Java processes to confirm that they are normal (such as large numbers of them exist.CLOSE_WAITstate connection).

7. Check the log

View the logs of Java applications

Check the application's log files (e.g.or), check for errors or exception stack information, which can often directly indicate the reason why the program is suspended.

Experience

To determine whether a Java program is suspended, you can use it in conjunction with itps, top/htop, jps, jstack, jstatetc. to observe the status of the process, CPU and memory usage, thread stack, and error information in the log file. These methods can help you quickly confirm whether a Java program is suspended and the possible reasons.

Here is a rumor to help you quickly remember the commands used to view the running status of Java programs on Linux:

  • psCheck the processgreptry to find,
  • topWatch the load keep running;
  • jpsList Java names,
  • jstackStack check exceptions;
  • jstatMonitoring GC is busy,
  • netstatAll connected states;
  • Check logs to see program failures.
  • Don’t panic with comprehensive analysis!

This rumor contains all the mentioned commands and corresponds in sequence to facilitate memory.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.