시스템 모니터링
인터페이스를 확인한 후에는 운영 중단을 방지하기 위해 시스템의 성능을 모니터링하는 것이 필수적입니다. 이를 위해 모든 것이 최적으로 실행되도록 중요한 시스템 메트릭을 로깅합니다.
farm_operations 내에서 system_monitor.py라는 Python 스크립트를 엽니다.
import os
def system_monitor():
print("Recording system metrics...")
os.system("top -b -n 1 > system_metrics.log")
if __name__ == "__main__":
system_monitor()
이 스크립트는 배치 모드에서 top 명령을 실행하여 시스템 메트릭을 수집하고 system_metrics.log라는 로그 파일로 리디렉션합니다. 스크립트를 실행합니다.
$ python3 system_monitor.py
Recording system metrics...
system_metrics.log의 내용을 확인하여 시스템 데이터의 성공적인 로깅을 확인합니다.
$ cat system_metrics.log
top - 00:33:14 up 15 days, 14:22, 0 users, load average: 0.04, 0.07, 0.10
Tasks: 16 total, 1 running, 15 sleeping, 0 stopped, 0 zombie
%Cpu(s): 6.2 us, 0.0 sy, 0.0 ni, 93.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 7802.7 total, 585.3 free, 3936.1 used, 3281.4 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 3555.6 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
216 labex 20 0 657480 56304 38872 S 6.7 0.7 0:00.63 node
1 root 20 0 11200 3780 3508 S 0.0 0.0 0:00.02 init.sh
21 root 20 0 40812 27976 10540 S 0.0 0.4 0:00.22 supervisord
22 root 20 0 15420 9396 7760 S 0.0 0.1 0:00.01 sshd
23 labex 20 0 2632 972 880 S 0.0 0.0 0:00.00 dumb-init
24 labex 20 0 721668 63708 38596 S 0.0 0.8 0:00.56 node
41 labex 20 0 951088 106276 41152 S 0.0 1.3 0:06.74 node
167 labex 20 0 994340 134536 41504 S 0.0 1.7 0:07.99 node
189 labex 20 0 848976 51504 38352 S 0.0 0.6 0:00.18 node
233 labex 20 0 14392 6488 4604 S 0.0 0.1 0:00.37 zsh
403 labex 20 0 377336 70216 11228 S 0.0 0.9 0:02.21 python
430 labex 20 0 38268 25560 9832 S 0.0 0.3 0:00.17 python
435 labex 20 0 14396 6588 4652 S 0.0 0.1 0:00.17 zsh
863 labex 20 0 21156 9408 6076 S 0.0 0.1 0:00.01 python
864 labex 20 0 11200 3652 3388 S 0.0 0.0 0:00.00 sh
865 labex 20 0 14176 3576 3220 R 0.0 0.0 0:00.00 top
터미널 내에서 top 명령과 유사한 출력을 보게 됩니다.