首页 > 系统 > Linux > 正文

Linux多功能诊断器-pidstat

2024-06-28 16:03:32
字体:
来源:转载
供稿:网友

    在linux下,中间件如weblogic,tomcat会进程资源飙高,如CPU,IO,memory。你可以用top,vmstat,iostat命令分别看,也可以用一个工具搞定就是pidstat,它不仅可以监控进程的性能情况,也可以监控线程的性能情况。

安装:CentOS/Fedora/RHEL版本的linux中则使用下面的命令  # yum install sysstat在Debian/Ubuntu系统中可以使用下面的命令来安装  # sudo apt-get install sysstat当然,也可以从这里下载 https://www.icewalkers.com/Linux/Software/59040/Sysstat.html写一个demo模拟CPU飙高的情况:

public class PIDTestCPU {    public static class CPUTask implements Runnable{        public void run() {            while(true){                double a=Math.random()*Math.random();            }        }    }    public static class IdleTask implements Runnable{        public void run(){            try{                while(true){                    Thread.sleep(2000);                }            }catch(Exception e){            }        }    }    public static void main(String[] args){        new Thread(new CPUTask()).start();        new Thread(new IdleTask()).start();        new Thread(new IdleTask()).start();        new Thread(new IdleTask()).start();    }}[root@localhost ~]# java PIDTestCPU[root@localhost ~]# jps11161 PIDTestCPU11239 Jps[root@localhost ~]# pidstat -p  11161  1 3 -u -tLinux 2.6.32-431.el6.x86_64 (localhost.localdomain)     02/09/2017      _x86_64_        (1 CPU)06:11:03 PM      TGID       TID    %usr %system  %guest    %CPU   CPU  Command06:11:04 PM     11161         -  100.00    0.00    0.00  100.00     0  java06:11:04 PM         -     11161    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11162    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11163    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11164    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11165    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11166    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11167    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11168    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11169    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11170    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11171   99.00    0.00    0.00   99.00     0  |__java06:11:04 PM         -     11172    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11173    0.00    0.00    0.00    0.00     0  |__java06:11:04 PM         -     11174    0.00    0.00    0.00    0.00     0  |__java十进制11171转换为十六进制2ba32017-02-09 18:11:54Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.45-b01 mixed mode):"DestroyJavaVM" PRio=10 tid=0x00007f7078006800 nid=0x2b9a waiting on condition [0x0000000000000000]   java.lang.Thread.State: RUNNABLE"Thread-3" prio=10 tid=0x00007f70780a7800 nid=0x2ba6 waiting on condition [0x00007f7069a64000]   java.lang.Thread.State: TIMED_WAITING (sleeping)        at java.lang.Thread.sleep(Native Method)        at PIDTestCPU$IdleTask.run(PIDTestCPU.java:13)        at java.lang.Thread.run(Thread.java:662)"Thread-2" prio=10 tid=0x00007f70780a5800 nid=0x2ba5 waiting on condition [0x00007f7069b65000]   java.lang.Thread.State: TIMED_WAITING (sleeping)        at java.lang.Thread.sleep(Native Method)        at PIDTestCPU$IdleTask.run(PIDTestCPU.java:13)        at java.lang.Thread.run(Thread.java:662)"Thread-1" prio=10 tid=0x00007f70780a3800 nid=0x2ba4 waiting on condition [0x00007f7069c66000]   java.lang.Thread.State: TIMED_WAITING (sleeping)        at java.lang.Thread.sleep(Native Method)        at PIDTestCPU$IdleTask.run(PIDTestCPU.java:13)        at java.lang.Thread.run(Thread.java:662)"Thread-0" prio=10 tid=0x00007f70780a1800 nid=0x2ba3 runnable [0x00007f7069d67000]   java.lang.Thread.State: RUNNABLE        at PIDTestCPU$CPUTask.run(PIDTestCPU.java:6)        at java.lang.Thread.run(Thread.java:662)"Low Memory Detector" daemon prio=10 tid=0x00007f7078088000 nid=0x2ba1 runnable [0x0000000000000000]   java.lang.Thread.State: RUNNABLE"C2 CompilerThread1" daemon prio=10 tid=0x00007f7078085800 nid=0x2ba0 waiting on condition [0x0000000000000000]   java.lang.Thread.State: RUNNABLE"C2 CompilerThread0" daemon prio=10 tid=0x00007f7078083000 nid=0x2b9f waiting on condition [0x0000000000000000]   java.lang.Thread.State: RUNNABLE"Signal Dispatcher" daemon prio=10 tid=0x00007f7078081000 nid=0x2b9e waiting on condition [0x0000000000000000]   java.lang.Thread.State: RUNNABLE"Finalizer" daemon prio=10 tid=0x00007f7078064000 nid=0x2b9d in Object.wait() [0x00007f707c22b000]   java.lang.Thread.State: WAITING (on object monitor)        at java.lang.Object.wait(Native Method)        - waiting on <0x00000000eb601300> (a java.lang.ref.ReferenceQueue$Lock)        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118)        - locked <0x00000000eb601300> (a java.lang.ref.ReferenceQueue$Lock)        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:171)"Reference Handler" daemon prio=10 tid=0x00007f7078062000 nid=0x2b9c in Object.wait() [0x00007f707c32c000]   java.lang.Thread.State: WAITING (on object monitor)        at java.lang.Object.wait(Native Method)        - waiting on <0x00000000eb6011d8> (a java.lang.ref.Reference$Lock)        at java.lang.Object.wait(Object.java:485)        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)        - locked <0x00000000eb6011d8> (a java.lang.ref.Reference$Lock)"VM Thread" prio=10 tid=0x00007f707805b800 nid=0x2b9b runnable "VM Periodic Task Thread" prio=10 tid=0x00007f7078093000 nid=0x2ba2 waiting on condition JNI global references: 888Heap def new generation   total 4736K, used 446K [0x00000000eb600000, 0x00000000ebb20000, 0x00000000f08a0000)  eden space 4224K,  10% used [0x00000000eb600000, 0x00000000eb66fb30, 0x00000000eba20000)  from space 512K,   0% used [0x00000000eba20000, 0x00000000eba20000, 0x00000000ebaa0000)  to   space 512K,   0% used [0x00000000ebaa0000, 0x00000000ebaa0000, 0x00000000ebb20000) tenured generation   total 10624K, used 0K [0x00000000f08a0000, 0x00000000f1300000, 0x00000000fae00000)   the space 10624K,   0% used [0x00000000f08a0000, 0x00000000f08a0000, 0x00000000f08a0200, 0x00000000f1300000) compacting perm gen  total 21248K, used 2590K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)   the space 21248K,  12% used [0x00000000fae00000, 0x00000000fb0879f0, 0x00000000fb087a00, 0x00000000fc2c0000)pidstat -p  11161  1 3 -u -tCPU监控:pidstat -p指定进程ID,-u表示对CPU使用率监控,参数1 3 表示每秒采集1次,共采集三次%usr: 进程在用户态运行所占cpu时间比率%system: 进程在内核态运行所占cpu时间比率%CPU: 进程运行所占cpu时间比率CPU: 指示进程在哪个核运行pidstat -p  11161  1 3 -d -tIO监控:pidstat -p指定进程ID,-d表示对磁盘IO使用率监控,参数1 3 表示每秒采集1次,共采集三次kB_rd/s: 每秒进程从磁盘读取的数据量(以kB为单位)kB_wr/s: 每秒进程向磁盘写的数据量(以kB为单位)pidstat -p  11161  1 3 -r -t内存监控:pidstat -p指定进程ID,-r表示对内存监控,参数1 3 表示每秒采集1次,共采集三次minflt/s:进程每秒不需要从磁盘中调出内存页的总数majflt/s:进程每秒需要从磁盘中调出内存页的总数,一般在内存使用紧张时产生VSZ:进程使用虚拟内存大小,单位KBrss:占用物理内存大小,单位KB%MEM:占用内存比率Average:         TGID       TID  minflt/s  majflt/s     VSZ    RSS   %MEM  CommandAverage:        11161         -      0.00      0.00 1059588  20552   2.03  javaAverage:            -     11161      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11340      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11341      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11342      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11343      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11344      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11345      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11346      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11347      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11348      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11349      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11350      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11351      0.00      0.00 1059588  20552   2.03  |__javaAverage:            -     11352      0.00      0.00 1059588  20552   2.03  |__java


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表