Is there any way to get my server’s load and memory usage history from commandline?
Yes, it’s possible by using the commandline utility SAR. System Activity Reporter is abbreviated as SAR. It is an important tool to monitor server’s different important metrics at different points of time. Using SAR it will be possible to monitor the performance of various Linux subsystems (CPU, Memory, I/O..) in real time. If you had a problem with your server performance, you can check the resource usage history by using SAR utility. There are a lot of options are available with SAR. Here I’m explaining the usage of load average andmemory usage analysing steps.
sysstat - daemon
SAR for load monitoring purpose
sar -q
The above command will report load averages at different times. (It fetch data from /var/log/sa(sysstat)/sa*, where sa* represent the date like sa10,sa11,sa12etc).
Examples
>> sar -q
It simply list current day’s load averages starting from 12:00:00, with 10 minute interval.
>> sar -q 1 5
It list load averages 5 times from when we enter this with an interval of 1 sec.
>> sar -q -f /var/log/sa/sa23
Previous dates details are stored in the directory “/var/log/sa/”. The switch “f” along with the command SAR can fetch previous days details.
SAR for memory monitoring purpose
sar -r
Report memory details.
Examples
>> sar -r
It simply list current day’s memory usage averages starting from 12:00:00, with 10 minute interval.
>> sar -r 1 5
It list memory usage averages 5 times from when we enter this with an interval of 1 sec.
>> sar -r -f /var/log/sa/sa23
Fetch data from /var/log/sa/sa23.
That’s it!!