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 to
1
The keys can show the usage of each CPU core.
htop
:
-
top
Enhanced version, providing a more friendly interface and more features (need to be installed).
mpstat
:
- Displays the usage of each CPU, usually with
sysstat
Toolkits are used together. - Example:
mpstat -P ALL 1
Displays 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.
-
-h
Options 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 5
The 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.
-
-h
Options 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.
-
-s
Express a summary,-h
Represents are displayed in human-readable format.
iostat
:
- Displays I/O statistics of disk devices, usually with
sysstat
Toolkits are used together. - Example:
iostat -x 1
Detailed I/O statistics are displayed every second.
4. Check network status
ifconfig
orip 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
:
-
netstat
Faster 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.
top
orhtop
:
- Display system load information in real time.
sar
:
- System activity reports that can record and play back load data, usually with
sysstat
Toolkits are used together.
6. View process information
ps aux
:
- Displays all processes currently running on the system and their details.
top
orhtop
:
- 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 combinedwatch
Commands 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:
-
top
Check the overall CPU busy, -
htop
More friendly interface; -
mpstat
Nuclear dosage, - All data can be seen clearly.
-
free
Check memory,vmstat
More comprehensive; - Disk space
df
Bright,du
View file lines; -
iostat
Check I/O busy, -
ifconfig
Connect to the Internet,netstat
Full ports. -
uptime
Check the load, -
sar
Playable, -
ps aux
Check the process, -
pstree
Father 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:
useps
The 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 followingjava
All processes of the word. Check the CPU and memory usage of the process (especially%CPU
and%MEM
column), 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:
- run
top
orhtop
Command, then pressM
The keys can be sorted by memory usage, or pressP
Key press CPU usage sort. - Find in the list
java
process, 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:
jps
It 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
passjps
You 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:
-
jstack
It 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 passedps
orjps
get). - Check the output for possible signs of deadlock or thread waiting for a long time.
5. Use the jstat command
Monitor JVM performance:
-
jstat
It 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 it
netstat
Check its network connection status. - Example:
netstat -anp | grep java
Check all network connections related to Java processes to confirm that they are normal (such as large numbers of them exist.CLOSE_WAIT
state 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
, jstat
etc. 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:
-
ps
Check the processgrep
try to find, -
top
Watch the load keep running; -
jps
List Java names, -
jstack
Stack check exceptions; -
jstat
Monitoring GC is busy, -
netstat
All 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.