System Monitoring
After verifying the interfaces, itâs essential to monitor the system's performance to prevent any disruptions in operations. For this, we will log important system metrics to ensure everything runs optimally.
Open a Python script named system_monitor.py
within farm_operations
:
import os
def system_monitor():
print("Recording system metrics...")
os.system("top -b -n 1 > system_metrics.log")
if __name__ == "__main__":
system_monitor()
This script runs the top
command in batch mode to collect system metrics and redirect them into a log file named system_metrics.log
. Execute the script:
$ python3 system_monitor.py
Recording system metrics...
Check the contents of system_metrics.log
to verify the successful logging of system data:
$ 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
You will see an output similar to the top
command within the terminal.