Reputation: 139
On centos, can sar command display both date and time? I found sar can only display time as :
17:42:40 CPU %user %nice %system %iowait %steal %idle
17:42:42 all 0.31 0.00 0.69 0.06 0.00 98.93
I expect this:
2017-03-28 17:42:40 CPU %user %nice %system %iowait %steal %idle
Anyone knows how to get this format?
Upvotes: 2
Views: 6156
Reputation: 11
The man page states, by setting an env as S_TIME_FORMAT=ISO
,
"The sar command will use the ISO 8601 format (YYYY-MM-DD) instead".
http://sebastien.godard.pagesperso-orange.fr/
First you might want to check if this does the job.
However, this did not work in my environment (sysstat version 10.1.5, installed via yum, on CentOS Linux release 7.6.1810).
Here is a workaround I found:
sar
can output logs in a binary format containing both date and time (-o
option).
Then, you can extract information from it using sadf
.
Try, for example,
$ sar -o sartestlog 1
This saves a binary log file named sartestlog
.
The last argument "1" stands for sample rate (in seconds).
Then run, for example,
$ sadf -- -P 0 sartestlog
.
This will show your logical CPU 0's usage with the desired datetime timestamp.
Replace -P 0
with what you would pass in to sar
command to get relevant metrics.
I'm answering to a bit old question, but still hope this will be helpful for someone!
Upvotes: 1
Reputation: 327
In the sar output first it displays the date like below
===============
Linux 2.6.32-642.12.1.e16.x86_64 (ap.pm.pk) 2017-05-03 . _x86_64 . (24 CPU)
12:00:01 AM CPU %usr %nice %sys %iowait %steal %irq %soft %guest %idle
12:10:01 AM all 30.70 0.00 2.2 2.95 0.00 0.00 0.21 0.00 63.88
===============
To check older/previous date sar report we need run sar command on the var/log/sysstat/sa* file
sar -f /var/log/sysstat/sa13
Here 13 is date
Upvotes: 0