In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use the sar command in linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The sar command is simple, and its parameters are mainly divided into four parts. Among them, the second part and the third and fourth parts are optional, that is, there is only one parameter left, that is, the type. There are a lot of values for this parameter, so let's put aside for a moment and take a look at the simple meaning of the above command.
Type, that is, which type of metric data we want to obtain. The-n here represents monitoring some network information.
Type parameters, some types have parameters and some do not. The DEV here represents the monitoring of network card information.
Time interval, indicating how many seconds the data is sampled. 1 here is 1 second.
The number of times, indicating the number of samples. For example, if the interval is 3 and the number of samples is 4, then the sar command will block for 12 seconds.
Let's take a peek at its output.
# sar-n DEV 1 2 03:10:29 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s% ifutil 03:10:30 PM lo 30.00 30.00 2.09 2.09 0.00 0.00 0.00 03:10:30 PM eth0 6.00 2.00 0.38 0.32 0.00 0.00 0.00 03:10:30 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s% ifutil 03:10:31 PM lo 39.00 2.95 2.95 0.00 0.00 0.00 03:10:31 PM Eth0 11.00 12.00 0.72 5.26 0.00 0.00 0.00 Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s% ifutil Average: lo 33.00 33.00 2.38 2.38 0.00 0.00 0.00 0.00 Average: eth0 9.33 8.33 0.60 2.39 0.00 0.00 0.00
A very regular two-dimensional array, unlike the arrogant display of the top command (top-b-n 1 can output current information). You can easily use a tool like sed,awk to deal with it.
By understanding the various parts of this command, we can rest assured and boldly look at the specific parameters and what they are. Whether we can catch this bird or not, this is the first move.
The reason why the sar command stands at the top of the chain of disdain is that its parameters are very rich. We no longer need all kinds of commands such as iostat, top, vmstat and so on. We only need one sar to unify the world.
There are only the following types of resource monitoring under Linux. There are disks, CPU, network, memory, IO and so on. I'm sorry, sar can monitor it, it's so supercilious.
Next, let's take a stroll.
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.
(1) Utilization, using sar-u, let's take a look at its implementation results. You can see that the usage of each type is the same as the meaning of the top command.
# sar-u 1 03:37:39 PM CPU% user% nice% system% iowait% steal% idle 03:37:40 PM all 0.25 0.50 0.50 0.00 98.75 Average: all 0.25 0.50 0.50 0.00 0.00 98.75
(2) load, using sar-Q, similarly, the parameter meaning of top is similar. In addition to the load value, it also shows the length of the waiting queue, which is very helpful for troubleshooting queuing problems.
# sar-Q 1 03:40:15 PM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 03:40:16 PM 0 468 0.02 0.04 0.00 Average: 0468 0.02 0.04 0.00
(3) interrupt, use 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.
# sar-I SUM 1 2 03:44:36 PM INTR intr/s 03:44:37 PM sum 1118.00 03:44:38 PM sum 1024.00 Average: sum 1071.00
(4) context switching, using sar-w, which is often confused with sar-W, which monitors the use of swap swap partitions, so be careful.
# sar-w 1 04:08:33 PM proc/s cswch/s 04:08:34 PM 0.00 1686.00
two。 Memory information
After watching the CPU, then look at the memory. When the CPU runs full, the machine may slow down, but when the memory is full, it will kill people.
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.
# sar-r 1 03:48:39 PM kbmemfree kbavail kbmemused% memused kbbuffers kbcached kbcommit% commit kbactive kbinact kbdirty 03:48:40 PM 1663884 2650804 78.45 1001040 6954428 90.06 4915476 582184 100 Average: 1663884 2650804 6057692 78.45 010040 6954428 90.06 4915476 582184 100
(2) swap exchange 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.
# sar-S 1 1 04:05:22 PM kbswpfree kbswpused% swpused kbswpcad% swpcad 04:05:23 PM 00 0.00 0.00 Average: 00 0.00 0 0.00
(3) Kernel usage, mainly using 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.
# sar-v 1 04:10:17 PM dentunusd file-nr inode-nr pty-nr 04:10:18 PM 115135 3776 111146 3 04:10:19 PM 115145 3776 111151 3 04:10:20 PM 115149 3776 111155 3
(4) sar can also monitor memory paging information, it has a cow x name sar-B, to see its effect.
# sar-B 04:15:39 PM pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s% vmeff 04:15:40 PM 20.00 10.00 0.00 1.00 0.00 0.00 0.00 04:15:41 PM 16.00 0.00 0.00 0.00. 00 0.00 0.00 0.00 04:15:42 PM 20.00 186.00 0.00 0.00 0.00
3. Icano information
IO information monitoring is also a loud sar-b, but the b here becomes lowercase.
# sar-b 1 2 04:17:25 PM tps rtps wtps bread/s bwrtn/s 04:17:26 PM 6.00 4.00 2.00 32.00 23.00 04:17:27 PM 5.00 5.00 0.00 48.00 0.00 Average: 5.50 4.50 1.00 40.00 11.50
If you want to find a problem, you should cooperate with iowait to find it.
You might say that there are only five options for the output, which is not as much as the iostat output! Is there a bird? This is because you haven't used sar-d yet. let's see how it works. Hehe, it's just a copy of iostat.
# sar-d 1 04:18:47 PM DEV tps rkB/s wkB/s areq-sz aqu-sz await svctm% util 04:18:48 PM dev253-0 4.00 16.00 0.00 4.00 0.00 0.50 1.75 0.70 04:18:49 PM dev253-05.00 84.00 0. 00 16.80 0.00 0.60 1.80 0.90
4. Network information
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.
DEV network card
EDEV network card (error)
NFS NFS client
NFSD NFS server
SOCK Sockets (socket) (v4)
IP IP stream (v4)
EIP IP stream (v4) (error)
ICMP ICMP stream (v4)
EICMP ICMP stream (v4) (error)
TCP TCP stream (v4)
ETCP TCP stream (v4) (error)
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)
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.
5. How to install
We have introduced various linux commands, such as top, vmstat, mpstat, iostat... Wait, wait.
After our introduction above. It turns out that none of this works. If you want to be able to count, you have to look at the sar command.
Sar (System ActivityReporter) is the most comprehensive system performance analysis tool for Linux, which can monitor various resources such as CPU, memory, network, Icano, file read and write, system calls and so on.
The sar command is also a command in the sysstat toolkit, and if you can't execute it, you need to install it like this.
Yum install sysstat
Sar has a very big advantage over commands like top, that is, it can display historical indicators.
So after you start the installation, try to execute sar. It turned out to be wrong.
[root@localhost ~] # sar Cannot open / var/log/sa/sa08: No such file or directory
This needs to be done in a little while, because it doesn't have data yet. There will be all bread and milk.
The Endsar command can see the history. So where are these files stored? We can find them in the / var/log/sa directory. But unfortunately, vim opens these files, it is garbled!
You can export them using the following command. The following number is usually the date of the day.
Sar-A-f / var/log/sa/sa21 > monitor
The monitor file can be opened using either a graphical tool or a text editor. Here, take kSar as an example (a java portable GUI), choose to load the monitor file, you can have the following effect.
With the powerful command sar, you can know the parameters of the system like the back of your hand. Compared with the sar command, other commands are really scum. First, because sar can see history, and second, because sar is powerful. But I use those orders very much, even if they are scum. There are also two reasons, one is that I am used to it and do not want to change it, and the other is that the parameters of the sar command of Niu x are really a little anti-human and really difficult to remember.
The above is all the contents of the article "how to use sar commands in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.