3

I have a problem in sadf between ubuntu and centos. The thing is how the date is displayed in both.

Ubuntu:

root@db1:/usr/local/nagios/libexec/nrpe_local# sadf | head -10
db1.oas3.realmedia.xstrat.us  300   2014-05-15 03-05-01 UTC all     %%user  0.14
db1.oas3.realmedia.xstrat.us  300   2014-05-15 03-05-01 UTC all     %%nice  0.00

Centos:

[root@ui1 jboss]# sadf | head -5
ui1.oas3.realmedia.xstrat.us    595     1400123401      all     %user   1.00
ui1.oas3.realmedia.xstrat.us    595     1400123401      all     %nice   0.00

I need to display time in ubuntu as it's displayed in centos (epoch time).

I haven't have lucky to find some configuration file that could fix this issue.

6

You should check sadf manpage to know exactly what option will show seconds since epoch time, There is a difference between versions of sysstat.

With my Ubuntu 12.04.4 LTS:

$ sadf -V
sysstat version 10.0.3
(C) Sebastien Godard (sysstat <at> orange.fr)

With this version, option to show epoch time is -T:

-T     Display timestamp (UTC - Coordinated Universal Time) in  seconds
       from the epoch.

But with sysstat 8.1.2-2, this option is -D.

-D     This  option  is  equivalent to option -d below, except that the
       timestamp  is  always  expressed  in  seconds  since  the  epoch
       (00:00:00 UTC 01/01/1970).
| improve this answer | |
0

In ubuntu the option that worked for me is -T:

root@db1:/usr/local/nagios/libexec/nrpe_local# sadf -T | head -10 db1.oas3.realmedia.xstrat.us 300 1400123101 all %%user 0.14 db1.oas3.realmedia.xstrat.us 300 1400123101 all %%nice 0.00

Thanks a lot!

| improve this answer | |
0

If, for whatever strange reason, the flag suggested by Gnouc doesn't exist on your system, you can always use date to parse the sadf output and convert to epoch time:

$ sadf | perl -plae '/.+? .+? (.+?) (.+?)/; $d=$1; $t=$2; $d=~s/-/\//g; 
                    $t=~s/-/:/g; $k=`date -d "$d $t $F[4]" +%s`; chomp($k); 
                    s/$F[2] $F[3] $F[4]/$k/'
db1.oas3.realmedia.xstrat.us  300   1400205600 all     %%user  0.14
db1.oas3.realmedia.xstrat.us  300   1400205600 all     %%nice  0.00

or, if you don't need to keep the format exactly but can loose some whitespace:

$ sadf | while read a b date time zone rest; do 
    date=$(date -d "${date//-//} ${time//-/:} $zone" +%s); 
    printf "%s %s %s %s\n" "$a" "$b" "$date" "$rest"; 
 done
db1.oas3.realmedia.xstrat.us 300 1400123101 all     %%user  0.14
db1.oas3.realmedia.xstrat.us 300 1400123101 all     %%nice  0.00
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.