CPU 과부하 시 메시지 경고

6604 단어
먼저 top 명령의 사용 방법을 소개합니다. top 프로그램은 시스템을 실행하는 동적 실시간 보기를 제공합니다. 시스템 요약 정보와 현재 루트나 프로세스의 목록을 표시할 수 있습니다.
$ top -h
  procps-ng 3.3.12
Usage:
  top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]

-hv Help/Version 둘 다 인쇄 버전 등 도움말 정보
명령행 매개 변수에서 기본값을 변경할 수 있는 다음 옵션을 제공합니다
-b    Batch-mode         
-c    Command-line/Program-name       command
-H    Threads-mode        top      。          ,               。        “H”  
-i    Idle-process           “  ” ,            CPU        
-O    Output-field-names
-S    Cumulative-time     
-s    Secure-mode     

-d    Delay-time     
-n        
-w        

기본값은 다음과 같습니다.
Global-defaults
              A - Alt display      Off (full-screen)
            * d - Delay time       1.5 seconds
            * H - Threads mode     Off (summarize as tasks)
              I - Irix mode        On  (no, `solaris' smp)
            * p - PID monitoring   Off (show all processes)
            * s - Secure mode      Off (unsecured)
              B - Bold enable      On  (yes, bold globally)
           Summary-Area-defaults
              l - Load Avg/Uptime  On  (thus program name)
              t - Task/Cpu states  On  (1+1 lines, see `1')
              m - Mem/Swap usage   On  (2 lines worth)
              1 - Single Cpu       Off (thus multiple cpus)
           Task-Area-defaults
              b - Bold hilite      Off (use `reverse')
            * c - Command line     Off (name, not cmdline)
            * i - Idle tasks       On  (show all tasks)
              J - Num align right  On  (not left justify)
              j - Str align right  Off (not right justify)
              R - Reverse sort     On  (pids high-to-low)
            * S - Cumulative time  Off (no, dead children)
            * u - User filter      Off (show euid only)
            * U - User filter      Off (show any uid)
              V - Forest view      On  (show as branches)
              x - Column hilite    Off (no, sort field)
              y - Row hilite       On  (yes, running tasks)
              z - color/mono       On  (show colors)

CPU 사용을 모니터링하려면 top -bi -n 1 아래 명령watch top -bi -n 1의 출력을 살펴볼 수 있습니다.
Every 2.0s: top -bi -n 1                                                                                                                                   MyServer: Fri Oct 18 08:45:14 2019

top - 08:45:14 up 36 days,  1:50,  5 users,  load average: 0.07, 0.05, 0.01
Tasks: 146 total,   1 running, 144 sleeping,   1 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.0 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2062096 total,   350188 free,   316304 used,  1395604 buff/cache
KiB Swap:   524284 total,   523764 free,      520 used.  1550992 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND

내가 한 라인을 열고 공전할 때
Every 2.0s: top -bi -n 1                                                                                                                                   MyServer: Fri Oct 18 08:45:55 2019

top - 08:45:55 up 36 days,  1:51,  5 users,  load average: 0.12, 0.06, 0.01
Tasks: 148 total,   1 running, 146 sleeping,   1 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.0 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2062096 total,   339368 free,   327092 used,  1395636 buff/cache
KiB Swap:   524284 total,   523764 free,      520 used.  1540204 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 5595 d         20   0 3100664  33628  24520 S 100.0  1.6   0:04.71 java

물론 top -cbi -n 1 전체 명령줄을 표시할 수 있습니다
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 4584 root      20   0 3142032 158940  27872 S   0.3  7.7   1:00.08 java -cp .:bin:SpringDependent/emcat/ref/tomcat-annotations-api-9.0.26.jar:SpringDependent/emcat/ref/tomcat-embed-core-+

정규 표현식을 사용하여 CPU와 메모리를 일치시킵니다
^.*\s+(\d+\.\d+)\s+(\d+.\d+)\s+.*$

프로젝트 주소:https://github.com/develon2015/CPUWarning
  174 CPU:100.0       Mem: 1.7
  175 CPU:100.0       Mem: 1.7
CPU       100.1840909090909 %
CPU    (100.0%),                       
     -- (Sat Oct 19 00:53:28 EDT 2019)
         [email protected] : CPU      ->    CPU    (100.1840909090909%),         .
top - 00:53:27 up 36 days, 17:58,  5 users,  load average: 0.97, 0.39, 0.15
Tasks: 148 total,   1 running, 147 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.0 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2062096 total,   134600 free,   362592 used,  1564904 buff/cache
KiB Swap:   524284 total,   523508 free,      776 used.  1515476 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
13211 d         20   0 3100664  34784  25480 S 100.0  1.7   2:02.85 java

FROM CPUWarning.
  0   CPU:106.7       Mem: 1.7
  1   CPU:106.7       Mem: 3.0999999999999996
  2   CPU:93.8        Mem: 1.7
  3   CPU:93.8        Mem: 1.7
  4   CPU:106.7       Mem: 1.7
  5   CPU:100.0       Mem: 1.7
  6   CPU:100.0       Mem: 1.7
  7   CPU:100.0       Mem: 1.7
  8   CPU:106.7       Mem: 1.7

...

  158 CPU:6.7 Mem: 2.9
  159 CPU:0.0 Mem: 0.0
  160 CPU:0.0 Mem: 0.0
  161 CPU:0.0 Mem: 0.0
  162 CPU:0.0 Mem: 0.0
  163 CPU:0.0 Mem: 0.0
CPU       36.94268292682926 %
     -- (Sat Oct 19 00:55:28 EDT 2019)
        (CPU 0.0 %) -- (Sat Oct 19 00:55:30 EDT 2019)
 top - 00:55:30 up 36 days, 18:00,  5 users,  load average: 0.35, 0.40, 0.18
Tasks: 146 total,   1 running, 145 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.0 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2062096 total,   134324 free,   362808 used,  1564964 buff/cache
KiB Swap:   524284 total,   523508 free,      776 used.  1515260 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND

        (CPU 0.0 %) -- (Sat Oct 19 00:55:33 EDT 2019)
 top - 00:55:32 up 36 days, 18:00,  5 users,  load average: 0.32, 0.39, 0.18
Tasks: 146 total,   1 running, 145 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.0 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2062096 total,   134324 free,   362808 used,  1564964 buff/cache
KiB Swap:   524284 total,   523508 free,      776 used.  1515260 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND

https://github.com/develon2015/CPUWarning

좋은 웹페이지 즐겨찾기