Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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).
share|improve this answer
    
Thanks! Very useful! –  user56193 May 16 at 19:53

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!

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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