Performance monitoring tool in Linux

To display the overall resource usage of the system, run the top command

Top-19:55:08 UP 22 days, 3:12, 1 User, load Average: 0.01, 0.08, 0.07 Tasks: 77 total, 1 running, 76 sleeping, 0 stopped, 0 zombie %Cpu(s): 1.3US, 0.7SY, 0.0Ni, 97.0ID, 1.0wa, 0.0hi, 0.0Si, 0.0st KiB Mem: 1016380 total, 76076 free, 864172 used, 76132 buff/cache KiB Swap: 0 total, 0 free, 0 Used.35740 Avail Mem PID USER PR NI VIRT RES SHR S %CPU % Mem TIME+ COMMAND 579 root 20 0 586424 42072 148 S 0.3 4.1 32:11.25 YDService 2051 root 20 0 741344 10944 1456 S 0.3 1.1 72:05.36 barad_agent 11108 root 20 0 143948 1260 220 S 0.3 0.1 20:35.96 redis-server 23059 mysql 20 0 1421440 411764 0 S 0.3 40.5 19:36.60 mysqld 1 root 20 0 41048 2316 1180 S 0.0 0.2 1:14.65 systemd 2 root 20 00 0 S 0.0 0.0 0:00. .Copy the code

It is divided into two parts: the first part is system statistics, and the second part is process information.

You can use the top command to view the CPU usage and memory usage of each process in the system from a macro view.

Monitor memory and CPU — vmstat command

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0  78252    544  75832    0    0   227    18   18   12  1  0 99  0  0
Copy the code

You can specify the sampling period and sampling times. For example, run vmstat 1 3

The vmstat tool looks at memory, interactive partitions, I/O operations, context switches, clock interrupts, and CPU usage.

Monitor I/O using the — iostat command

Linux 3.10.0-514.26.2.el7.x86_64 (VM_0_6_centos) 03/22/2019-x86_64_ (1 CPU) AVG-CPU: %user % Nice % System % IOwait % Steal %idle 0.55 0.00 0.40 0.36 0.00 98.70 Device: TPS kB_read/s kB_wrtn/s kB_read kB_wrtn SCD0 0.00 0.00 0.00 316 0 VDA 6.52 228.32 18.13 435180743 34554796Copy the code

Sampling period and sampling times can also be specified.

Disk I/O can easily become a performance bottleneck. You can use iostat to quickly determine whether a large number of I/O operations are generated in the system.

Multifunctional diagnostic – pidstat tool

Pidstat -p 29839 -u 1 3, -u Specifies to monitor the CPU usage.

Linux 3.10.0-514.26.2.el7.x86_64 (VM_0_6_centos) 03/22/2019 _x86_64_ (1 CPU) 08:22:50 PM UID PID %usr %system %guest %CPU CPU Command 08:22:51 PM 0 29839 0.00 0.00 0.00 0 Java 08:22:52 PM 0 29839 0.00 0.00 0.00 0 Java 08:22:53 PM 0 29839 0.00 0.00 0.00 0 Java Average: 0 29839 0.00 0.00 0.00 - JavaCopy the code

Pidstat -p 29839 -d 1 3, -d Specifies to monitor the I/O usage.

Linux 3.10.0-514.26.2.el7.x86_64 (VM_0_6_centos) 03/22/2019 _x86_64_ (1 CPU) 08:26:12pm UID PID kB_rd/s kB_wr/s KB_ccwr/S Command 08:26:13 PM 0 29839 0.00 0.00 Java 08:26:14 PM 0 29839 0.00 0.00 Java 08:26:15 PM 0 29839 0.00 0.00 Java Average: 0 29839 0.00 0.00 JavaCopy the code

Pidstat -p 29839 -r 1 3, -d Specifies to monitor the memory usage.

Linux 3.10.0-514.26.2.el7.x86_64 (VM_0_6_centos) 	03/22/2019 	_x86_64_	(1 CPU)

08:27:34 PM   UID       PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
08:27:35 PM     0     29839      0.00      0.00 2359408 316676  31.16  java
08:27:36 PM     0     29839      0.00      0.00 2359408 316676  31.16  java
08:27:37 PM     0     29839      0.00      0.00 2359408 316676  31.16  java
Average:        0     29839      0.00      0.00 2359408 316676  31.16  java
Copy the code

The Pidstat tool is an excellent all-in-one tool. It can not only monitor CPU, I/O, and memory resources, but also locate problems to related threads for easy application troubleshooting.

Windows performance monitoring tool

Task manager

Right-click in the bottom bar of the desktop, or use the Ctrl + Alt + Del combo to exhale.

The task manager is a common and powerful tool that displays the network load on your system, CPU usage for any process, memory usage, and I/O usage.

Perfmon performance monitoring tool

You can open perfmon by using the Perfmon command in the Run dialog box on the Start menu, or by double-clicking Performance Monitor in the Administrative Tools in the Control panel;

Perfmon is also a performance monitoring tool that comes with Windows. The performance metrics you can monitor are numerous and powerful. This task is recommended when task management cannot meet requirements.

The Perfmon tool supports startup with the parameter /res, which is used specifically to monitor the usage of system resources: Perfmon /res

JDK performance monitoring tool

Look at the Java process — JPS command

JPS is similar to PS under Linux, but it is only used to list Java processes.

[root@VM_0_6_centos ~]# jps
28646 Jps
29839 jar
Copy the code

Run the jstat command to view vm running information

Jstat a tool for viewing runtime information about a Java application. The basic syntax is:

jstat -<option> [-t] [-h<lines>] <vmid> [<interval>] [<count>]
Copy the code
  • The option option can be composed of the following values:

    • -class: displays ClassLoader information
    • – Compiler: Displays JIT compilation information
    • -gc: displays heap information related to GC
    • -gccapacity: displays the capacity and usage of each generation
    • -gccause: displays information about garbage collection and the cause of the last or current garbage phone occurrence
    • -gcnew: displays new generation information
    • – gcnewCapacity: displays the size and usage of the new generation
    • -gcold: displays information about the old age
    • – gcoldCapacity: displays the size of the old age
    • – gcpermCapacity: displays the size of the permanent generation
    • -printcompilation: Outputs JIT compilation method information
  • The -t parameter can be preceded by a Timestamp column to show the running time of the program

  • When the -h argument can be periodically output, the number of lines to be output is followed by a header

  • The interval parameter specifies the statistical period, in milliseconds

  • Count is used to specify how many times the data is output

View GC related pair information output

[root@VM_0_6_centos ~]# jstat -gc 29839
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
4352.0 4352.0  0.0   1614.1 34816.0   3974.8   86828.0    74678.7   67632.0 64592.8 8240.0 7731.2    405    1.665   6      0.521    2.187
Copy the code

View the virtual machine parameter — jinfo command

Jinfo views the extended parameters of a running Java application, and even supports modifying some of the parameters at run time. The basic syntax is:

jinfo <option> <pid>
Copy the code

Option can be the following information:

  • -flag: displays the parameter values of a specified Java VM
  • – flag [+ | -] : setting specifies the Java virtual machine parameters of Boolean value
  • -flag= : Sets the values of specified Java VM parameters

For example, check the maximum age at which the current generation object advances to the old age object.

[root@VM_0_6_centos ~]# jinfo -flag MaxTenuringThreshold 29839
-XX:MaxTenuringThreshold=15
Copy the code

Export the heap to a file — jmap command

View the VM status.

[root@VM_0_6_centos ~]# jmap -heap 29839Attaching to process ID 29839, please wait... Debugger attached successfully. Server Compiler detected. JVM version is 25.201-B09 using ththread -local object allocation. Mark Sweep Compact GC Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 262144000 (250.0MB) NewSize = 5570560 (5.3125MB) MaxNewSize = 87359488 (83.3125MB) OldSize = 11206656 (10.6875MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 Heap Usage: New Generation (Eden + 1 Survivor Space): Capacity = 40108032 (38.25MB) Used = 7851408 (7.4876861572265625MB) Free = 32256624 (30.762313842773438MB) 19.57565008425245% informs the Eden Space: Capacity = 35651584 (34.0MB) Used = 6198592 (5.91143798828125MB) Free = 29452992 (28.08856201171875MB) 17.386582318474264%, informs the From Space: Capacity = 4456448 (4.25MB) Used = 1652816 (1.5762481689453125MB) Free = 2803632 (2.6737518310546875MB) 37.08819221047794%, informs the To Space: Capacity = 4456448 (4.25MB) Used = 0 (0.0MB) Free = 4456448 (4.25MB) 0.0% Used tenured generation: Capacity = 88911872 (84.79296875MB) Used = 76470984 (72.92841339111328MB) Free = 12440888 (11.864555358886719MB) 86.00761887006496% Used 26446 Interned Strings evicted 3202672 bytesCopy the code

Graphical VM monitoring tool JConsole

The JConsole tool is a graphical performance monitoring tool provided by the JDK. It is located in the %JAVA_HOME%/bin directory.

Once the Java application is connected, you can view the application overview;

Mission Control is a cool diagnostic tool

Mission Control is located in the %JAVA_HOME%/bin directory, after the Java program is connected;