Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux View hardware Information what is the use of the super command sar and the visualization tool ksar

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces Linux to view hardware information super command sar and visualization tool ksar is how to use, the content is very detailed, interested friends can refer to, hope to be helpful to you.

I. Overview

Sar (System Activity Reporter, system activity report) is a statistical tool for the running status of the system under Linux, which can report the activities of the system from many aspects, including: the reading and writing of files, the use of system calls, disk ID O, CPU efficiency, memory usage, process activities and IPC-related activities. He is an omnipotent little expert.

II. Installation

Under ubuntu:

Root@ubuntu:/home/peng# apt-get install sysstat

Root@ubuntu:/home/peng# sar-r Cannot open / var/log/sysstat/sa07: No such file or directory Please check if data collecting is enabled

You will encounter the following error after execution. 07 in sa07 is the date of the day because the file was not created. Solution:

Root@ubuntu:/home/peng# chmod otakw / etc/default/sysstat root@ubuntu:/home/peng# vim / etc/default/sysstat

Third, command syntax

1. Type is the type of metric data we want to obtain. The-n here represents monitoring some network information.

-a: file read and write status-A: sum of all reports-B: paging status-b: display statistics for Imax O and transfer rate-c: output process statistics Processes created per second-d: block device status-F [MOUNT]: file system statistics-H: swap space utilization-I {| SUM | ALL | XALL}: interrupt information status-n: report network status-P: set CPU-Q: queue length and average load-R: output memory page statistics-r [ALL]: output memory and swap Space statistics-S: exchange space utilization information-u [ALL]: output CPU usage statistics-v: output inode, Statistics for files and other kernel tables-W: output system exchange activity information-w: task creation and system conversion information-y: terminal device activity

two。 Type parameters some types have parameters and some do not. The DEV here represents the monitoring of network card information.

3. Interval time between each report (seconds)

4. Times

Displays the number of times the report is reported. For example, if the interval is 2 and the number of samples is 3, the sar command will block for 12 seconds.

Help root@ubuntu:/home/peng# sar-- help Usage: sar [options] [[]] Options are: [- A] [- B] [- b] [- C] [- D] [- d] [- F [MOUNT]] [- H] [- h] [- p] [- Q] [- R] [- r [ALL]] [ -S] [- t] [- u [ALL]] [- V] [- V] [- W] [- w] [- y] [--sadc] [- I {[ | SUM | ALL | XALL}] [- P {[,...] | ALL}] [- m {[,...] | ALL}] [- n {[ | ALL}] [- j {ID | LABEL | PATH | UUID |.}] [- f [] |-o [] |-[0-9] +] [- I] [- s []] [- e [] 4. Examples

There are mainly the following kinds of resource monitoring under Linux: disk, CPU, network, memory, IO and so on.

1. CPU information

Let's start with the cpu message. As the brain of the computer, as a commander, we have to monitor its every move. In fact, there are three types of monitoring for CPU: utilization, load, and interruption.

(1) CPU utilization

Using sar-u, let's take a look at its execution results. You can see that the usage of each type is the same as in the top command.

Root@ubuntu:/home/peng# sar-u 11 Linux 4.15.0-112-generic (ubuntu) 03 take 07 Universe 2021 _ x86 six hundred 641 CPU 05:28:09 AM CPU% user% system% iowait% steal% idle 05:28:10 AM all 1.01 0.00 2.02 0.00 96.97 Average: All 1.01 0.00 2.02 0.00 0.00 96.97

Field description

% user # CPU usage of user space

% nice CPU utilization of processes whose priorities have been changed

CPU utilization of% system kernel space

% percentage of iowait CPU waiting for IO

CPU used by virtual machine CPU of steal virtual machine

% idle idle CPU

In the above display, excessively high% iowait and% idle,%iowait indicate that there is an CPU O bottleneck, that is, the disk IO cannot meet the business requirements. If the% idle is too low, the CPU utilization is serious, and you need to determine whether the CPU is a bottleneck based on memory usage and other conditions.

(2) report the usage status of each CPU: root@ubuntu:/home/peng# sar-p 1 3 Linux 4.15.0-112-generic (ubuntu) 03 CPU 2021 _ x86 pound 641 CPU 05:29:21 AM CPU% user% system% iowait% idle 05:29:22 AM all 1.00 0.00 0.00 0.00 0.00 99.00 05:29:23 AM all 1.02 0.00 0.00 0.00 98.98 05:29:24 AM all 1.01 0.00 0.00 0.00 97.98 Average: all 1.01 0.00 0.34 0.00 0.00 98.65 field description

CPU: statistics for all CPU

CPU usage statistics for% user user mode

% nice CPU usage statistics for processes that have changed priority

% percentage of iowait CPU waiting for IO data

% percentage of physical CPU occupied by vCPU of steal virtual machine

% CPU percentage of idle idle

(3) the CPU load uses sar-Q, which is similar to the parameter meaning of top. In addition to the load value, it also shows the length of the waiting queue, which is very helpful for troubleshooting queuing problems. Root@ubuntu:/home/peng# sar-Q 11 Linux 4.15.0-112-generic (ubuntu) 03 take 07 Universe 2021 _ x86 six hundred 641 CPU 05:30:20 AM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 05:30:21 AM 0440 0.01 0.02 0.00 Average: 0440 0.01 0.02 0.00 0 field description

Length of runq-sz run queue (number of processes waiting to run, CP per core cannot exceed 3)

The number of processes (processes) and threads (threads) in the plist-sz process list

The average CPU load of the last minute of ldavg-1, which is the average of the load of multicore CPU in the past minute added and divided by the number of cores, 5 minutes, 15 minutes, and so on.

Average CPU load for the last 5 minutes of ldavg-5

Average CPU load for the last 15 minutes of ldavg-15

(4) interrupt

Using sar-I, note that I is uppercase. Because there are different conversion methods, so the interrupt parameters are divided into default, SUM, ALL and so on.

Root@ubuntu:/home/peng# sar-I SUM 12 Linux 4.15.0-112-generic (ubuntu) 03 take 07 CPU 05:31:01 AM INTR intr/s 05:31:02 AM sum 250.52 05:31:03 AM sum 338.38 Average: sum 294.90 (5) context switch

Using sar-w, it is often confused with sar-W (pay attention to case), which monitors the use of swap swap partitions, so be careful.

Root@ubuntu:/home/peng# sar-w 1 Linux 4.15.0-112-generic (ubuntu) 03 take 07 CPU 05:31:53 AM proc/s cswch/s 05:31:54 AM 0.00 05:31:55 AM 0.00 734.38 05:31:56 AM 0.00 582.65 05:31:57 AM 0.00 886.462. Memory information

Memory is mainly divided into the following parts, we usually monitor, mainly physical memory, virtual memory, kernel and so on.

(1) memory utilization

Use the sar-r command. Some versions of sar may have sar-R, but lowercase is generally sufficient.

Root@ubuntu:/home/peng# sar-r 11 Linux 4.15.0-112-generic (ubuntu) 03Universe 641 CPU 05:32:54 AM kbmemfree kbmemused% commit kbactive kbinact kbdirty 05:32:55 AM 281108 1736408 86.07 109040 675176 3345488 110.93 730964 591392 0 Average: 281108 1736408 86.07 109040 675176 3345488 110.93 730964 591392 0 Field description

Kbmemfree: the amount of free memory available

Kbmemused: the amount of memory used (excluding memory used by the kernel)

% memused: percentage of memory used

Kbbuffers: the amount of memory used by the kernel buffer (buffer)

Kbcached: the amount of memory used by kernel cache (cache) data

Kbswpfree: the amount of free swap space available

Kbswpused: the amount of swap space used

% swpused: percentage of swap space used

Kbswpcad: the amount of memory used by the cache of swap space

Kbcommit ensures the minimum memory required for the normal operation of the current system, that is, the minimum memory needed to ensure that the memory does not overflow (physical memory + Swap partition)

The value of commit is a percentage of kbcommit to total memory (physical memory + swap partition).

(2) swap switching partition

For swap partitions, you can use sar-S. The effect is as follows. If you want to see the usage of the swap partition (non-capacity case), switch to the sar-W command.

Root@ubuntu:/home/peng# sar-S 11 Linux 4.15.0-112-generic (ubuntu) 03 take 07 CPU 05:34:15 AM kbswpfree kbswpused% swpused kbswpcad% swpcad 05:34:16 AM 962556 35840 3.59 2808 7.83 Average: 962556 35840 3.59 2808 7.83 (3) Kernel usage

Mainly use the sar-v command. V is generally used for version display in other commands, and the sar command is used to output some information about the slab area, which can be said to be a maverick and unusual.

Root@ubuntu:/home/peng# sar-v 1 Linux 4.15.0-112-generic (ubuntu) 03 take 07 Universe 2021 _ x86 inch 641 CPU 05:34:46 AM dentunusd file-nr inode-nr pty-nr 05:34:47 AM 47183 6816 53938 17 05:34:48 AM 47183 6816 53938 17 Field description

The number of entries that dentunusd does not use in buffered directory entries

Number of file handles used by the system for file-nr

Number of indexes already used by inode-nr

Number of pty used by pty-nr

(4) Monitoring memory paging information, mainly using the sar-B command. Notice his pronunciation! It's awesome!) The implementation results are as follows: root@ubuntu:/home/peng# sar-B Linux 4.15.0-112-generic (ubuntu) 03Universe 07Unip. 2021 _ x86milli641 CPU 01:51:34 AM LINUX RESTART (1 CPU) 01:55:01 AM pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s% vmeff 02:05:01 AM 0.00 0.29 23.98 0.00 10.50 0.00 0.00 0.00 02:15:01 AM 0.00 0.23 1.03 0.00 1.90 0.00 0.00 0.00 02:25:01 AM 0.00 0.47 1.73 0.00 2.71 0.00 0. 00 0.00 0.00 (5) View statistics for the swap partition of the system: root@ubuntu:/home/peng# sar-W Linux 4.15.0-112-generic (ubuntu) 03Greater 07AM 2021 _ x86mm 641 CPU 01:51:34 AM LINUX RESTART (1 CPU) 01:55:01 AM pswpin/s pswpout/s 02:05:01 AM 0.00 02:15:01 AM 0 .00 0.00 02:25:01 AM 0.00 0.00 02:35:01 AM 0.00 0.00 02:45:01 AM 0.00 02:55:01 AM 0.00 field description

The number of swap pages (swap page) from the swap partition to the system of pswpin/s per second

The number of exchange pages (swap page) exchanged from the system to swap by pswpout/s per second

(6) check the statistics of root@ubuntu:/home/peng# sar O and transfer rate root@ubuntu:/home/peng# sar-b Linux 4.15.0-112-generic (ubuntu) 03Accord 2021 _ x86hammer 641 CPU 01:51:34 AM LINUX RESTART (1 CPU) 01:55:01 AM tps rtps wtps bread/s bwrtn/s 02:05:01 AM 0.04 0.00 0.04 0.00 0.59 02:15:01 AM 0.03 0.00 0.03 0.00 0.47 field description

Total IO per second of tps disks, equal to tps in iostat

Total number of IO read from disk by rtps per second

Total number of wtps IO written to disk per second

Total number of blocks read from disk by bread/s per second

Total number of blocks written to disk by bwrtn/s per second

(7) disk usage details Statistics root@ubuntu:/home/peng# sar-d Linux 4.15.0-112-generic (ubuntu) 03 Universe 07tick 2021 _ x86mm 641 CPU 01:51:34 AM LINUX RESTART (1 CPU) 01:55:01 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm% util 02:05:01 AM dev7-0 .00 0.00 0.00 0.00 02:05:01 AM dev8-0 0.04 0.00 0.59 13.54 0.00 0.00 0.00 field description

The name of the DEV disk device. If you do not add-p, a device name similar to dev253-0 will be displayed, so the name shown with-p is more direct.

Tps: the total number of transfers per second

Total number of sectors read by rd_sec/s per second

Total number of sectors written by wr_sec/s per second

Average data size (sector) of avgrq-sz per disk Istroke O operation

Average length of the avgqu-sz disk request queue

Await the average elapsed time of each request from the request disk operation to the completion of the system processing, including the request queue waiting time in milliseconds (1 second equals 1000 milliseconds), equal to seek time + queue time + service time

The service processing time of svctm IPUBO, that is, excluding the time in the request queue

The percentage of CPU occupied by% util Icano requests. The higher the value is, the slower the Icano is.

3. Icano information

IO information monitoring is also a loud sar-b, but the b here becomes lowercase.

Root@ubuntu:/home/peng# sar-b 12 Linux 4.15.0-112-generic (ubuntu) 03Universe 07Universe 2021 _ x86tiny 641 CPU 05:41:22 AM tps rtps wtps bread/s bwrtn/s 05:41:23 AM 0.00 0.00 0.00 05:41:24 AM 2.06 0.00 2. 06 0.00 65.98 Average: 1.02 0.00 1.02 0.00 32.65 field description

Total IO per second of tps disks, equal to tps in iostat

Total number of IO read from disk by rtps per second

Total number of wtps IO written to disk per second

Total number of blocks read from disk by bread/s per second

Total number of blocks written to disk by bwrtn/s per second

The sar-d command is very similar to the iostat command, with more results.

Root@ubuntu:/home/peng# sar-d 1 Linux 4.15.0-112-generic (ubuntu) 03 take 07 CPU) 05:42:03 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm% util 05:42:04 AM dev7-0 0.00 0.00 0.00 0.00 0.00 0.00 05:42:04 AM dev8-0 0.00 0.00 0.00 Field description

The name of the DEV disk device. If you do not add-p, a device name similar to dev253-0 will be displayed, so the name shown with-p is more direct.

Tps: the total number of transfers per second

Total number of sectors read by rd_sec/s per second

Total number of sectors written by wr_sec/s per second

Average data size (sector) of avgrq-sz per disk Istroke O operation

Average length of the avgqu-sz disk request queue

Await the average elapsed time of each request from the request disk operation to the completion of the system processing, including the request queue waiting time in milliseconds (1 second equals 1000 milliseconds), equal to seek time + queue time + service time

The service processing time of svctm IPUBO, that is, excluding the time in the request queue

The percentage of CPU occupied by% util Icano requests. The higher the value is, the slower the Icano is.

4. Network information (1) Statistical network information sar-n

Next, let's look at the most complex network information. It is complex because it has so many parameters, such as the DEV mentioned above, which represents the network traffic.

Sadly, each output of these parameters is not the same. It may be that 26 letters can no longer cover so many parameters, so the sar command adds it under sar-n. Fortunately, when we usually use it, we can only deal with the DEV parameter.

The # sar-n option uses six different switches: DEV,EDEV,NFS,NFSD,SOCK,IP,EIP,ICMP,EICMP,TCP,ETCP,UDP,SOCK6,IP6,EIP6,ICMP6,EICMP6 and UDP6, DEV displays network interface information, EDEV displays statistics about network errors, NFS statistics information about active NFS clients, NFSD statistics NFS server information, SOCK displays socket information, ALL displays all five switches. They can be used alone or together.

(2) count at intervals of 1 second Total statistics for 1 time root@ubuntu:/home/peng# sar-n DEV 11 Linux 4.15.0-112-generic (ubuntu) 03 ifutil 07go 2021 _ x86mm 641 CPU 05:45:36 AM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s% ifutil 05:45:37 AM ens33 0.00 0.00 0.00 0.00 0.00 0.00 05:45:37 AM lo 0.00 0.00 0.00 Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s% ifutil Average: ens33 0.00 0.00 0.00 0.00 Average: lo 0.00 0.00 0.00 field description

The following average is the average after multiple statistics.

The name of the interface of the IFACE local network card

Packets accepted by rxpck/s per second

Database sent by txpck/s per second

Packet size accepted by rxKB/S per second, in KB

The size of packets sent by txKB/S per second in KB

Compressed packets accepted by rxcmp/s per second

Compressed packets sent by txcmp/s per second

Multicast packets received by rxmcst/s per second

(3) Statistics of network equipment communication failure information: root@ubuntu:/home/peng# sar-n EDEV 11 Linux 4.15.0-112-generic (ubuntu) 03Accord 2021 _ x86telecommunications 641 CPU 05:46:22 AM IFACE rxerr/s txerr/s coll/s rxdrop/s txdrop/s txcarr/s rxfram/s rxfifo/s txfifo/s 05:46:23 AM ens33 0.000. 00 0.00 0.00 0.00 05:46:23 AM lo 0.00 0.00 0.00 Average: IFACE rxerr/s txerr/s coll/s rxdrop/s txdrop/s txcarr/s rxfram / s rxfifo/s txfifo/s Average: ens33 0.00 0.00 0.00 Average: lo 0.00 0.00 0.00 field description

Name of IFACE network card

Corrupted packets received by rxerr/s per second

Number of packet errors sent by txerr/s per second

Coll/s the number of collisions per second when sending a packet, which occurs only in half-duplex mode

Rxdrop/s the number of network packets lost by the receiver of the network card device per second when the buffer is full

Txdrop/s the number of network packets lost by the sender of the network device per second when the buffer is full

Txcarr/s the number of carrier errors per second when sending a packet

The number of frame errors per second that occurred when the rxfram received the packet

The number of buffer overflow errors per second when rxfifo receives a packet

The number of buffer overflow errors per second when a packet occurs in txfifo

(4) Statistics of socket connection information root@ubuntu:/home/peng# sar-n SOCK 11 Linux 4.15.0-112-generic (ubuntu) 03ax 07AM totsck tcpsck udpsck rawsck ip-frag tcp-tw 2021 _ x86x6x641 CPU 05:47:21 AM totsck tcpsck udpsck rawsck ip-frag tcp-tw 05:47:22 AM 1393 26 000 Average: 1393 26000 Field description

Total number of socket currently used by totsck

Total number of socket of TCP currently being used by tcpsck

Total number of socket of UDP currently being used by udpsck

Total number of skcket that rawsck is currently being used in RAW

The number of current IP shards of ip-frag

The number of connections in the TIME-WAIT state in the tcp-tw TCP socket

The use of the FULL keyword is equivalent to the combination of DEV, EDEV and SOCK.

(5) Statistics of TCP connections root@ubuntu:/home/peng# sar-n TCP 1 3 Linux 4.15.0-112-generic (ubuntu) 03Universe 07CPU) 05:48:05 AM active/s passive/s iseg/s oseg/s 05:48:06 AM 0.00 0.00 0.00 05:48:07 AM 0.00 0.00 .00 0.00 05:48:08 AM 0.00 0.00 0.00 Average: 0.00 0.00 0.00 field description

Active/s 's new active connection

Passive/s 's new passive connection

Segments accepted by iseg/s

Segment of oseg/s output

(6) Summary of sar-n usage

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

DEV Network Interface Statistics

EDEV network interface error

NFS NFS client

NFSD NFS server

SOCK Sockets (socket) (v4) socket use

IP IP stream (v4) IP Datagram statistics

EIP IP stream (v4) (error) IP error statistics

ICMP ICMP stream (v4)

EICMP ICMP stream (v4) (error)

TCP TCP stream (v4) TCP statistics

ETCP TCP stream (v4) (error) TCP error statistics

UDP UDP stream (v4)

SOCK6 Sockets (socket) (V6)

IP6 IP stream (V6)

EIP6 IP stream (V6) (error)

ICMP6 ICMP stream (V6)

EICMP6 ICMP stream (V6) (error)

UDP6 UDP stream (V6)

5. Ksar

Ksar can be used to analyze system performance data, and its advantage is that there is no need to collect performance data separately. The system has its own sar package, which can be displayed by Ksar through command conversion.

To install the software, you need to install java first, if you have already installed it, transfer it to step 5.

1. Download java

The download address for jdk-8u202-linux-x64.tar.gz is as follows:

Https://ch2-ctc-dd.tv002.com/down/d743c682d992b1c39f64ba78ce0d86e8/jdk-8u202-linux-x64.tar.gz?cts=dx-f-D121A237A240A189F43372&ctp=121A237A240A189&ctt=1615408146&limit=1&spd=65000&ctk=d743c682d992b1c39f64ba78ce0d86e8&chk=3bf885e6cb28751b351749779a461744-194042837&mtd=1

two。 Decompression

Copy jdk-8u202-linux-x64.tar.gz to ubuntu under / home/peng/jdk

Tar-zxvf jdk-8u202-linux-x64.tar.gz3. Set the environment variable $sudo vim / etc/profile

Add the following at the end of the file

28 # set java env 29 export JAVA_HOME=/home/peng/jdk/jdk1.8.0_202 30 export JRE_HOME=$ {JAVA_HOME} / jre 31 export CLASSPATH=.:$ {JAVA_HOME} / lib:$ {JRE_HOME} / lib 32 export PATH=$ {JAVA_HOME} / bin:$PATH

Make the environment variable effective

$sudo source / etc/profile4. Test java

The java version is 1.8.0,202.

5. Download ksar source code wget http://jaist.dl.sourceforge.net/project/ksar/ksar/5.0.6/ksar-5.0.6.zip unzip ksar-5.0.6.zip

Then extract it and go to the source root directory to execute the script:

Sh run.sh

You can start this software

Ksar

6. Operation

To execute the command, click Data- > Run local command

You can execute the following commands:

Sar-A

Click on the corresponding hardware information, you can view the corresponding hardware information content in a graphical form. Very intuitive and convenient.

About Linux view hardware information super command sar and visualization tool ksar is how to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report