How to Find Linux System Load History | Arkit
Linux Server system load you can check using uptime and top command as well. If you would like to check the system load average and CPU usage. Find out the Linux system load history shell script.
Load average and CPU usage history can be found in the SAR report, however, it consists of so many other parameters.
Find Out Linux System Load History
Using the below command system load average can be captured.
# uptime | awk '{ print $6,$7,$8,$9,$10}' load average: 0.00, 0.01, 0.05
Using /proc/loadavg Here there are five columns, from left to Right 1 to 30 load averages 1 minute, 5 minutes, and 15 minutes. Kernel Enabled process number and last run PID number
$ cat /proc/loadavg 0.00 0.01 0.05 1/261 2551
the top command is one, you can capture the Load average
# top -b -n 2 -d1 | grep ^top |tail -n1 | awk '{ print $8,$9,$10,$11,$12}' load average: 0.00, 0.01, 0.05
Shell Script Capture system load, CPU Usage, and Memory Usage
#!/bin/bash ################################################## # # # Author: Ankam Ravi Kumar # # Website: server-computer.com # # Date: 23-02-2019 16:59:56 # # Purpose: Capture and Store System Load Average # # CPU Usage and Memory Usage # ################################################## # Log File Path LOGFILE=/var/log/systemload.log HOSTNAME=$(hostname) DATE=$(date "+%d-%m-%Y %H:%M:%S") SYSTEMLOAD=$(uptime | awk '{ print $8,$9,$10}') CPULOAD=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 |awk '{print $2}') MEMORYUSAGE=$(free -m |grep Mem: |tail -n1 |awk '{print $2,$3}') echo "$DATE $HOSTNAME LoadAverage: $SYSTEMLOAD CPU: $CPULOAD Memory: $MEMORYUSAGE" >> $LOGFILE
Execute and capture history
sh systemload.sh cat /var/log/systemload.log 23-02-2019 17:56:50 ServerComputer.localdomain LoadAverage: 0.00, 0.01, 0.05 CPU: 0.0 Memory: 1963 166 23-02-2019 18:53:42 ServerComputer.localdomain LoadAverage: 0.00, 0.01, 0.05 CPU: 1.0 Memory: 1963 166
You can schedule above script in crontab and capture details later you will find the evidence
# crontab -e */5 * * * * sh systemload.sh
That’s about this post. You can download the same shell script from my Github
Related Articles
AWS Certified Cloud Practitioner Full Video Course
Thanks for your wonderful Support and Encouragement