"리눅스 CPU 사용률 확인"의 두 판 사이의 차이

 
(사용자 4명의 중간 판 24개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==방법==
==방법1: mpstat==
===명령어===
{{소스헤더|명령어}}
<source lang='bash'>
<source lang='bash'>
top -n 1 | grep -i cpu\(s\)| awk '{print $5}' | tr -d "%id," | awk '{printf("%f\n", 100-$1)}'
mpstat | tail -1 | awk '{print 100-$NF}'
</source>
</source>


===실행 예시===
{{소스헤더|실행예시}}
<source lang='dos'>
<source lang='console'>
[root@localhost ~]# top -n 1 | grep -i cpu\(s\)| awk '{print $5}' | tr -d "%id," | awk '{printf("%f\n", 100-$1)}'
# mpstat
1.300000
Linux 3.10.0-862.14.4.el7.x86_64 (centos7)      11/14/2019      _x86_64_        (1 CPU)
 
07:36:08 AM  CPU    %usr  %nice    %sys %iowait    %irq  %soft  %steal  %guest  %gnice  %idle
07:36:08 AM  all    0.44    0.00    0.39    0.21    0.00    0.03    0.00    0.00    0.00  98.93
</source>
<source lang='console'>
# mpstat | tail -1 | awk '{print 100-$NF}'
1.07
</source>
</source>
→ CPU 사용률은 1.3 %이다.
:→ CPU 사용률은 1.07%이다.<ref>mpstat은 소수점 둘째 자리까지 확인 가능. 1.07% = 100% - 98.93%</ref>


==변수에 담기==
==방법2: top ★==
===명령어===
{{소스헤더|명령어}}
<source lang='bash'>
<source lang='bash'>
PBUSY=`top -n 1 | grep -i cpu\(s\)| awk '{print $5}' | tr -d "%id," | awk '{printf("%f\n", 100-$1)}'`
top -b -n1 | grep -Po '[0-9.]+ id' | awk '{print 100-$1}'
</source>
</source>


===실행 예시===
{{소스헤더|실행예시}}
<source lang='dos'>
<source lang='console'>
[root@localhost ~]# PBUSY=`top -n 1 | grep -i cpu\(s\)| awk '{print $5}' | tr -d "%id," | awk '{printf("%f\n", 100-$1)}'`
root@centos7:~# top -b -n1 | grep -Po '[0-9.]+ id'
[root@localhost ~]# echo $PBUSY
93.8 id
1.300000
root@centos7:~# top -b -n1 | grep -Po '[0-9.]+ id' | awk '{print 100-$1}'
6.2
</source>
</source>
 
:→ CPU 사용률은 6.2 %이다.<ref>top은 소수점 첫째 자리까지 확인 가능</ref>


==같이 보기==
==같이 보기==
* [[리눅스 프로세스 CPU 사용률]]
* [[리눅스 프로세스 CPU 사용률]]
* [[리눅스 코어별 CPU 사용률 확인]]
* [[리눅스 CPU 유휴율]]
* [[리눅스 CPU 유휴율]]
* [[리눅스 메모리 사용률]]
* [[리눅스 메모리 사용률]]
* [[top]]
* [[리눅스 top]]
* [[sar]]
* [[리눅스 sar]] (시간대별 CPU 사용률 조회가능)
* [[CPU 부하량]](load average)
 
==참고==


[[분류:리눅스]]
[[분류:리눅스]]
[[분류:CPU]]
[[분류:CPU]]

2019년 11월 14일 (목) 16:49 기준 최신판

1 방법1: mpstat[ | ]

명령어
mpstat | tail -1 | awk '{print 100-$NF}'
실행예시
# mpstat
Linux 3.10.0-862.14.4.el7.x86_64 (centos7)      11/14/2019      _x86_64_        (1 CPU)

07:36:08 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
07:36:08 AM  all    0.44    0.00    0.39    0.21    0.00    0.03    0.00    0.00    0.00   98.93
# mpstat | tail -1 | awk '{print 100-$NF}'
1.07
→ CPU 사용률은 1.07%이다.[1]

2 방법2: top ★[ | ]

명령어
top -b -n1 | grep -Po '[0-9.]+ id' | awk '{print 100-$1}'
실행예시
root@centos7:~# top -b -n1 | grep -Po '[0-9.]+ id'
93.8 id
root@centos7:~# top -b -n1 | grep -Po '[0-9.]+ id' | awk '{print 100-$1}'
6.2
→ CPU 사용률은 6.2 %이다.[2]

3 같이 보기[ | ]

4 참고[ | ]

  1. mpstat은 소수점 둘째 자리까지 확인 가능. 1.07% = 100% - 98.93%
  2. top은 소수점 첫째 자리까지 확인 가능
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}