In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use sar and kSar to find Linux performance bottlenecks", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to use sar and kSar to find Linux performance bottlenecks" this article.
The sar command is used to collect, report, or save activity information for UNIX / Linux systems. It saves the selected counters to the / var/log/sa/sadd file of the operating system. From the collected data, you can get a lot of information about your server:
CPU utilization rate
Memory pages and usage
Network Icano and Transmission Statistics
Process creation activity
All block device activity
Interrupts per second, etc.
The output of the sar command can be used to identify the server bottleneck. However, it can be difficult to analyze the information provided by the sar command, so use the kSar tool. The kSar tool can plot the output of the sar command as an easy-to-understand chart based on a time period.
Sysstat package
The sar, sa1, and sa2 commands are all part of the sysstat package. It is a collection of performance monitoring tools included in Linux.
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Sar: displaying data
Sa1 and sa2: collect and save data for later analysis. The sa2 shell script writes a report every day in the / var/log/sa directory. The sa1 shell script writes daily system activity information to a file in the form of binary data.
Sadc-the system activity data collector. You can configure various options by modifying the sa1 and sa2 scripts. They are located in the following directory:
/ usr/lib64/sa/sa1 (64-bit) or / usr/lib/sa/sa1 (32-bit)-it calls sadc to record the report to / var/log/sa/sadX format.
/ usr/lib64/sa/sa2 (64-bit) or / usr/lib/sa/sa2 (32-bit)-it calls sar to record the report to / var/log/sa/sarX format.
How do I install sar on my system?
On a CentOS/RHEL-based system, enter the following yum command to install sysstat:
# yum install sysstat
The sample output is as follows:
Loaded plugins: downloadonly, fastestmirror, priorities,: protectbase SecurityLoading mirror speeds from cached hostfile * addons: mirror.cs.vt.edu * base: mirror.ash.fastserv.com * epel: serverbeach2.fedoraproject.org * extras: mirror.cogentco.com * updates: centos.mirror.nac.net0 packages excluded due to repository protectionsSetting up Install ProcessResolving Dependencies-- > Running transaction check--- > Package sysstat.x86_64 0base 7.0.2-3.el5 set to be updated-- > Finished Dependency Resolution Dependencies Resolved = Package Arch Version Repository Size====Installing: sysstat x86 * 64 7.0.2-3.el5 base 173k Transaction Summary====Install 1 Package (s) Update 0 Package (s) Remove 0 Package (s) Total download size: 173kIs this ok [y kIs this ok N]: yDownloading Packages:sysstat-7.0.2-3.el5.x86_64.rpm | 173kB 00:00Running rpm_check_debugRunning Transaction TestFinished Transaction TestTransaction Test SucceededRunning Transaction Installing : sysstat 1 take 1 Installed: sysstat.x86_64 0Rose 7.0.2-3.el5 Complete! Profile for sysstat
Edit the / etc/sysconfig/sysstat file to specify how many days the log file will be saved (up to one month):
# vi / etc/sysconfig/sysstat
The sample output is as follows:
# keep log for 28 days# the default is 7HISTORY=28
Save and close the file.
Find the sar default cron job
The default cron job is located at / etc/cron.d/sysstat:
# cat / etc/cron.d/sysstat
The sample output is as follows:
# run system activity accounting tool every 10 minutes*/10 * root / usr/lib64/sa/sa1 1 "generate a daily summary of process accounting at 2315 5323 * root / usr/lib64/sa/sa2-A tells sadc to report disk statistics
Use a text editor to edit the / etc/cron.d/sysstat file, such as the vim command, and type as follows:
# vi / etc/cron.d/sysstat
Update this file as in the following example to record all hard disk statistics (the-d option forces the statistics for each block device, and the-I option forces the statistics for all system outages):
# run system activity accounting tool every 10 minutes*/10 * root / usr/lib64/sa/sa1-I-d 1 "generate a daily summary of process accounting at 2315 5323 * root / usr/lib64/sa/sa2-A
On CentOS/RHEL 7.x you need to pass the-S DISK option to collect data from block devices. Pass the-S XALL option to collect the data listed below:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Magnetic disk
Zoning
System interruption
SNMP
IPv6
# Run system activity accounting tool every 10 minutes*/10 * root / usr/lib64/sa/sa1-S DISK 1'0 * root / usr/lib64/sa/sa1 6006 & # Generate a daily summary of process accounting at 23 root 23 * root / usr/lib64/sa/sa2-A # Run system activity accounting tool every 10 minutes
Save and close the file.
Open the service of the CentOS/RHEL version of 5.x/6.x
Enter the following command:
Chkconfig sysstat onservice sysstat start
The sample output is as follows:
Calling the system activity data collector (sadc):
For CentOS/RHEL 7.x, run the following command:
# systemctl enable sysstat# systemctl start sysstat.service# systemctl status sysstat.service
Sample output:
● sysstat.service-Resets System Activity Logs Loaded: loaded (/ usr/lib/systemd/system/sysstat.service; enabled; vendor preset: enabled) Active: active (exited) since Sat 2018-01-06 16:33:19 IST 3s ago Process: 28297 ExecStart=/usr/lib64/sa/sa1-- boot (code=exited, status=0/SUCCESS) Main PID: 28297 (code=exited, status=0/SUCCESS) Jan 06 16:33:19 centos7-box systemd [1]: Starting Resets System Activity Logs...Jan 06 16:33:19 centos7-box systemd [1]: Started Resets System Activity Logs. How to use sar? How do I view statistics?
Use the sar command to display the output of the cumulative activity counter selected in the operating system. In this example, run the sar command line to get a report on CPU usage in real time:
# sar-u 3 10
Sample output:
Linux 2.6.18-164.2.1.el5 (www-03.nixcraft.in) 12 PM all 14 Swiss 09:49:47 PM CPU% user% nice% system% iowait% steal% idle09:49:50 PM all 5.66 0.00 1.22 0.04 0.00 93.0809 PM all 12.29 0.00 1.93 0.04 0.00 85.7409 Swiss PM all 9.30 1.61 0.00 0.00 0.00 : 49:59 PM all 10.86 0.00 1.51 0.04 0.00 87.5809:50:02 PM all 14.21 0.00 3.27 0.04 0.00 82.4709:50:05 PM all 13.98 0.00 4.04 0.04 0.00 81.9309:50:08 PM all 6.60 6.89 1.26 0.00 0.00 85.2509:50:11 PM all 7.25 0.00 1.55 0.04 0.00 91.1509 : 50:14 PM all 6.61 0.00 1.09 0.00 0.00 92.3109:50:17 PM all 5.71 0.00 0.96 0.00 0.00 93.33Average: all 9.24 0.69 1.84 0.03 0.00 88.20
Where:
3 indicates the interval
10 represents the number of times
To view the statistics created by the process, enter:
# sar-c 3 10
To view Icano and transfer rate statistics, enter:
# sar-b 3 10
To view memory page statistics, enter:
# sar-B 3 10
To view block device statistics, enter:
# sar-d 3 10
To view statistics for all interrupts, enter:
# sar-I XALL 3 10
To view network device-specific statistics, enter:
# sar-n DEV 3 1 sar-n EDEV 3 10
To view CPU-specific statistics, enter:
# sar-P ALL# Only 1st CPU stats# sar-P 1 3 10
To view statistics on queue length and average load, enter:
# sar-Q 3 10
To view memory and swap space usage statistics, enter:
# sar-r 3 1 sar-R 3 10
To view the status of inode, files, and other kernel table statistics, enter:
# sar-v 3 10
To view system switching activity statistics, enter:
# sar-w 3 10
To view exchange statistics, enter:
# sar-W 3 10
To view an Apache process with a PID of 3256, enter:
# sar-x 3256 3 10kSar introduction
Sar and sadf provide output based on the command line interface. This output may make novice users / system administrators feel helpless. Therefore, you need to use kSar, a Java application that graphically displays your sar data. It also allows you to export data in PDF/JPG/PNG/CSV format. You can load data in three ways: local files, running local commands, and commands that run remotely through SSH. KSar can handle the sar output of the following operating systems:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Solaris 8, 9 and 10
Mac OS/X 10.4 +
Linux (Systat Version > = 5.0.5)
AIX (4.35.3)
HPUX 11.00 +
Download and install kSar
Visit the official website to get the source code of the * version. To download the source code using wget, type:
How does $wget https://github.com/vlsi/ksar/releases/download/v5.2.4-snapshot-652bf16/ksar-5.2.4-SNAPSHOT-all.jar run kSar?
First of all, make sure that JAVA jdk is installed on your machine and works properly. Enter the following command to start kSar:
$java-jar ksar-5.2.4-SNAPSHOT-all.jar
KSar welcome screen
Next you will see the main window of kSar and a panel with two menus.
KSar-the main window
On the left is a list of available charts that kSar has parsed based on the data. The window on the right will show the chart you selected.
How to use kSar to generate sar diagrams?
First, you need to collect statistics for the sar command from a server named server1. Enter the following command:
[server1] # LC_ALL=C sar-A > / tmp/sar.data.txt
Next, use the scp command to copy from the local desktop to the remote computer:
[desktop] $scp user@server1.nixcraft.com:/tmp/sar.data.txt / tmp/
Switch to the kSar window and click "Data" > "Load data from text file" > Select sar.data.txt from / tmp/ > Click the "Open" button.
The chart type tree now appears in the left panel and a graph is selected:
Linux kSar Processes for server1
Linux Disk I/O Stats Using kSar
Linux Memory paging and its utilization stats
Zoom in and out
You can interactively scale part of the image by moving it. Click and press the mouse in the upper-left corner of the image you want to zoom to the lower-right corner of the area you want to zoom, and you can select the area you want to zoom. Return to the unscaled state, click and drag the mouse anywhere except the lower right corner, you can also click and select the zoom option.
Understanding kSar images and sar data
I strongly recommend that you read the man page of the sar and sadf commands:
$man sar$ man sadf case study: identify CPU bottlenecks in Linux servers
Using the sar command and the kSar tool, you can get detailed snapshots of memory, CPU, and other subsystems. For example, if CPU usage persists above 80% for a long period of time, there may be a CPU bottleneck. With sar-x ALL, you can find processes that consume a lot of CPU.
The output of the mpstat command (part of the sysstat package) will also help you understand CPU usage. But you can use kSar to analyze this information easily.
After finding out the bottleneck of CPU...
Make the following adjustments to CPU:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Make sure there are no unwanted processes running in the background. Turn off all unwanted services on the Linux.
Use cron to run tasks (for example, backups) during off-peak hours.
Use the top and ps commands to find all non-critical background jobs / services. Use the renice command to adjust low-priority jobs.
Use the taskset command to set the CPU used by the process (uninstall the CPU used), that is, bind the process to a different CPU. For example, run the MySQL database on the desktop CPU and run Apache on the slave CPU.
Make sure your system uses * drivers and firmware.
Add additional CPU to the system if possible.
Use faster CPU for single-threaded applications (for example, Lighttpd web server applications).
Use multiple CPU for multithreaded applications (for example, MySQL database server applications).
Use multiple compute nodes for a web application and set up a load balancer.
Isag-Interactive system activity Recorder (alternative tool)
The isag command graphically shows the system activity data stored in binaries when you previously ran the sar command. The isag command references sar and extracts its data to draw a graph. Isag has fewer options than kSar.
These are all the contents of the article "how to use sar and kSar to find Linux performance bottlenecks". 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.