10.1 Use w to view system load
The Linux w command is used to display the user information currently logged into the system.
Execute this command to know who the users are currently logged into the system and what programs they are executing.
Execute the w command alone to display all users. You can also specify a user name to display information about only one user.
Syntax
w [-fhlsuV] [user name]
Parameter description:
-f Turns on or off showing where the user is logged into the system from.
-h Do not display header information columns for each column.
-l Use verbose format list, this is the default.
-s Use a concise format listing, do not display user login time, terminal phase jobs and CPU time spent by programs.
-u Ignore the name of the program to execute, and information about how much CPU time the program is spending.
-V Display version information.
Example
shows the current user
w
/ / Display the current user, do not display the login location
19:50:14 up 9:27, 4 users, load average: 0.31, 0.26, 0.18
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty7 :0 Thu12 31:39m 10:10 0.60s gnome-session
root pts/0 :0.0 17:09 2:18m 15.26s 0.15s bash
root pts/1 192.168.1.17 18:51 1.00s 1.24s 0.14s -bash
root pts/2 192.168.1.17 19:48 60.00s 0.05s 0.05s -bash
Don't show login location
w -f
19:53:59 up 9:31, 4 users, load average: 0.05, 0.16, 0.15
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root tty7 Thu12 31:43m 10:10 0.60s gnome-session
root pts/0 17:09 2:21m 15.26s 0.15s bash
root pts/1 18:51 0.00s 1.04s 0.14s -bash
root pts/2 19:48 4:45 0.05s 0.05s -bash
Show in lite mode
w -s
19:54:37 up 9:31, 4 users, load average: 0.24, 0.19, 0.16
USER TTY FROM IDLE WHAT
root tty7 :0 31:43m gnome-session
root pts/0 :0.0 2:22m bash
root pts/1 192.168.1.17 0.00s -bash
root pts/2 192.168.1.17 5:23 -bash
don't show title
w -h
root tty7 :0 Thu12 31:44m 10:10 0.60s gnome-session
root pts/0 :0.0 17:09 2:23m 15.26s 0.15s bash
root pts/1 192.168.1.17 18:51 0.00s 1.05s 0.14s -bash
root pts/2 192.168.1.17 19:48 5:54 0.05s 0.05s -bash
10.2 The vmstat command
• The meaning of the vmstat command is to display the virtual memory status (“Viryual Memor Statics”), but it can report the overall operating status of the system such as processes, memory, and I/O.
• -a: Display the active inner page;
-f: Display the total number of processes created after startup;
-m: Display slab information;
-n: Display header information only once;
-s: Display event counters and memory status in tabular form;
- d: report disk status;
-p: display the specified hard disk partition status;
-S: unit of output information
• vmstat monitors system status
• Vmstat 1 prints every 1s
Vmstat 1 5 prints every 1s, 5 times
[root@radius ~]# vmstat 1 6
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 60408 479876 443120 8139484 0 0 0 49 1 1 0 0 100 0 0
0 0 60408 479920 443120 8139488 0 0 0 36 861 1416 0 0 100 0 0
0 0 60408 479808 443120 8139488 0 0 0 1600 863 1387 0 0 99 0 0
0 0 60408 480316 443120 8139504 0 0 0 40 772 1273 0 1 99 0 0
0 0 60408 480084 443120 8139480 0 0 0 364 744 1226 0 0 100 0 0
0 0 60408 479712 443120 8139480 0 0 0 28 698 1175 0 0 100 0 0
Field description:
Procs (process)
• r: The number of processes in the run queue, this value can also determine whether to increase the CPU. (long-term greater than 1)
• b: The number of processes waiting for IO.
Memory (memory)
• swpd: Use virtual memory size, if the value of swpd is not 0, but the value of SI and SO is 0 for a long time, this situation will not affect the system performance.
• free: Free physical memory size.
• buff: The size of the memory used for buffering.
• cache: The size of the memory used for the cache. If the value of the cache is large, it means that there are many files in the cache. If the frequently accessed files can be located in the cache, the read IO bi of the disk will be very small.
Swap
• si: The size written from the swap area to the memory per second, transferred from the disk to the memory.
• so: The size of memory written to the swap area per second, transferred from memory to disk.
Note: When the memory is sufficient, the two values are both 0. If the two values are greater than 0 for a long time, the system performance will be affected, and the disk IO and CPU resources will be consumed. When some friends see that the free memory (free) is very small or close to 0, they think that the memory is not enough. They can't just look at this, but also combine si and so. If there is very little free, but si and so are also very small. (most of the time it is 0), then don't worry, the system performance will not be affected at this time.
IO (the block size of the current Linux version is 1kb) •
bi: the number of blocks read per second
• bo: the number of blocks written per second
1024k), you can see that the value of CPU waiting in IO will be larger.
system
• in: Interrupts per second, including clock interrupts.
• cs: context switches per second.
Note: The larger the above 2 values, the more CPU time you will see consumed by the kernel.
CPU (expressed as a percentage)
• us: User process execution time percentage (user time)
When the value of us is relatively high, it means that the user process consumes a lot of CPU time, but if the usage exceeds 50% for a long time, then we should consider optimizing the program algorithm or speed up.
• sy: Kernel system process execution time percentage (system time)
When the value of sy is high, it means that the system kernel consumes a lot of CPU resources, which is not a benign performance, and we should check the reason.
• wa: When the value of the IO waiting time percentage
wa is high, it indicates that the IO waiting is serious, which may be caused by a large number of random accesses on the disk, or there may be a bottleneck (block operation) on the disk.
• id: idle time percentage
• Related lines: r, b, swpd, si, so, bi, bo, us, wa
10.3 top command
The top command can dynamically view the overall operation of the system in real time. It is a practical tool that integrates multi-party information to monitor system performance and operation information. The interactive interface provided by the top command can be managed with hotkeys.
Syntax
top (option)
option
-b: operate in batch mode;
-c: display the complete command;
-d: screen refresh interval;
-I: ignore the failure process;
-s: secret mode;
-S: accumulation mode ;
-i<time>: set the interval time;
-u<user name>: specify the user name;
-p<process number>: specify the process;
-n<times>: the number of times of cyclic display.
top interactive command
Some interactive commands that can be used during the execution of the top command. These commands are all single-letter, and some of them may be blocked if the -s option is used on the command line.
h: display a help screen, giving some brief command summaries;
k: kill a process;
i: ignore idle and zombie processes, this is a switch command;
q: quit the program;
r: rearrange the priority level of a process ;
S: switch to accumulation mode;
s: change the delay time between two refreshes (unit is s), if there is a decimal, it will be converted to ms. Enter 0 value and the system will refresh continuously, the default value is 5s;
f or F: add or delete items from the current display;
o or O: change the order of displayed items;
l: switch to display the average load and startup time information;
m: Switch to display memory information;
t: switch to display process and CPU status information;
c: switch to display command name and complete command line;
M: sort by resident memory size;
P: sort by CPU usage percentage size;
T: sort by time/cumulative time ;
w: Write the current settings to the ~/.toprc file.
Example
top - 09:44:56 up 16 days, 21:23, 1 user, load average: 9.59, 4.75, 1.92
Tasks: 145 total, 2 running, 143 sleeping, 0 stopped, 0 zombie
Cpu(s): 99.8%us, 0.1%sy, 0.0%ni, 0.2%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 4147888k total, 2493092k used, 1654796k free, 158188k buffers
Swap: 5144568k total, 56k used, 5144512k free, 2013180k cached
Explanation:
• top - 09:44:56[current system time],
• 16 days[system has been running for 16 days],
• 1 user[user currently logged in],
• load average: 9.59, 4.75, 1.92[system load , the average length of the task queue]
• Tasks: 145 total[total number of processes],
• 2 running[number of running processes],
• 143 sleeping[number of sleeping processes],
• 0 stopped[number of stopped processes],
• 0 zombie[number of frozen processes],
• Cpu(s): 99.8%us[% of CPU occupied by user space],
• 0.1%sy[% of CPU occupied by kernel space],
• 0.0%ni[changed priority in user process space % of CPU occupied by high-level processes],
• 0.2%id[Percentage of idle CPU], 0.0%wa[Percentage of CPU time waiting for input and output],
• 0.0%hi[],
• 0.0%st[],
• Mem: 4147888k total [total physical memory],
• 2493092k used[total physical memory used],
• 1654796k free[total free memory],
• 158188k buffers[memory used as kernel cache]
• Swap: 5144568k total[swap total amount],
• 56k used[total swap area used],
• 5144512k free[total free swap area],
• 2013180k cached[total buffered swap area],
10.4 The sar command
• yum install -y sysstat
• sar -n DEV network card traffic
• sar -q system negative
• sar -b disk read and write
• sar -f /var/log/sa/saxx historical file
Sa binary file can only be viewed through the sar command call
Sar can be seen the next day. You can view it with cat. The
sar command is a statistical tool for system running status under Linux. It displays the specified operating system status counter to the standard output device. The sar tool will sample the current state of the system, and then express the current operating state of the system by calculating data and ratios. Its characteristic is that it can continuously sample the system and obtain a large amount of sampling data. Both sampled data and analysis results can be stored in a file, which consumes very little system resources.
Syntax
sar (option) (parameter)
option
-A: display all report information;
-b: display I/O rate;
-B: display page feed status;
-c: display process creation activity;
-d: display each block The status of the device;
-e: Set the end time of the display report;
-f: Extract the report from the specified file;
-i: Set the interval time for the refresh of the status information;
-P: Report the status of each CPU;
-R: Display the memory status ;
-u: Display CPU utilization;
-v: Display status of inodes, files, and other kernel tables;
-w: Display swap partition status;
-x: Display the status of a given process.
Parameters
• Interval time: the interval time (seconds) for each report;
• Count: Displays the count of the report.
Example
to view the usage of memory and swap space:
[root@aiker02 ~]# sar -r
Linux 3.10.0-514.26.2.el7.x86_64 (aiker02) 04/26/2018 _x86_64_ (1 CPU)
12:00:01 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
12:10:01 AM 75980 1807744 95.97 142196 1424580 297316 15.78 848388 762212 1204
12:20:01 AM 75328 1808396 96.00 142200 1425140 297316 15.78 849252 761948 660
12:30:01 AM 74528 1809196 96.04 142200 1425696 297316 15.78 850040 761728 192
12:40:01 AM 71752 1811972 96.19 142200 1428412 297316 15.78 850868 763576 1164
12:50:01 AM 75308 1808416 96.00 142200 1424864 297316 15.78 843508 767408 772
01:00:01 AM 72608 1811116 96.15 142200 1427372 297316 15.78 844344 769108 712
01:10:01 AM 71984 1811740 96.18 142200 1427940 297316 15.78 845120 768856 1144
01:20:01 AM 71140 1812584 96.22 142204 1428492 297316 15.78 845944 768616 484
01:30:01 AM 70456 1813268 96.26 142204 1429048 297316 15.78 846752 768384 848
01:40:01 AM 70028 1813696 96.28 142204 1429640 297316 15.78 847552 768112 1192
01:50:01 AM 69056 1814668 96.33 142204 1430168 297316 15.78 848360 767856 296
02:00:01 AM 68424 1815300 96.37 142208 1430724 297316 15.78 849192 767632 692
02:10:01 AM 90376 1793348 95.20 142216 1407568 303348 16.10 828128 768216 1116
02:20:01 AM 87560 1796164 95.35 142228 1410176 303348 16.10 829088 769956 360
02:30:01 AM 80008 1803716 95.75 142232 1414848 306632 16.28 832644 773748 1092
02:40:01 AM 73348 1810376 96.11 142232 1415464 315948 16.77 838908 773512 1028
The kbmemfree and kbmemused fields show the unused and used space of memory, respectively, followed by the percentage of used space (%memused field). The kbbuffers and kbcached fields respectively display the data access amount in the buffer and system domain, in KB.
Observe the system components for 10 minutes and sort the data:sar -o temp 60 10
[root@aiker02 ~]# sar -o temp 60 10
Linux 3.10.0-514.26.2.el7.x86_64 (aiker02) 04/26/2018 _x86_64_ (1 CPU)
08:55:11 PM CPU %user %nice %system %iowait %steal %idle
08:56:11 PM all 0.43 0.00 0.33 0.07 0.00 99.16
08:57:11 PM all 0.40 0.00 0.28 0.07 0.00 99.25
10.5 nload command
yum install -y epel-release
yum install -y nload
nload
Device eth0 [172.18.111.154] (1/2):
===================================================================================
Incoming:
Curr: 3.66 kBit/s
Avg: 6.59 kBit/s
Min: 952.00 Bit/s
Max: 48.77 kBit/s
Ttl: 2.13 GByte
Outgoing:
Curr: 8.57 kBit/s
Avg: 14.32 kBit/s
Min: 4.70 kBit/s
Max: 52.80 kBit/s
Ttl: 865.76 MByte