[rrd-users] Timestamp problem (OT)
Karl Fischer
rrd-users at ficos.de
Tue Feb 24 19:23:09 CET 2009
Alex van den Bogaerdt wrote:
> 'unixtime' is a bash function I've written:
>
> unixtime ()
> {
> /bin/date -ud 1970-01-01\ 00:00\ +0000\ +${1}sec +%Y-%m-%dT%H:%M:%SZ
> }
>
>
> (if someone knows a better function: please do share!)
Alex,
if one conversion is all you need, your tiny function is perfect.
I've written a slightly more sophisticated perl script for that purpose
which offers some more functionality/flexibility:
(find it attched for whoever might find it useful):
You can call it in 3 ways: as a filter, with files or timestamp arguments.
And you can define different time formats like "%Y-%m-%dT%H:%M:%SZ"
(the above is implemented as ZULU)
Especially when looking at logfiles with timestamps (eg. squid)
or when using rrdfetch this becomes quite handy:
# rrdtool fetch ntp.rrd AVERAGE -r 60 -s NOW-300 | unixtime -us
ntpdiff
2009-02-24 18:09:00 UTC (1235498940): 1.6131666667e-02
2009-02-24 18:10:00 UTC (1235499000): -1.4716250000e-02
2009-02-24 18:11:00 UTC (1235499060): -4.6193333333e-04
2009-02-24 18:12:00 UTC (1235499120): 8.1344333333e-03
2009-02-24 18:13:00 UTC (1235499180): 8.6324000000e-03
2009-02-24 18:14:00 UTC (1235499240): nan
# unixtime -h
usage: unixtime [-f format] [-t timezone] [-suz] [arguments]
options:
-?: this help
-h: this help
-f: define the strftime format
-s: add the replaced timestamp in ()
-t: use the timezone specified
-u: use UTC timezone (default: local timezone)
-z: print ZULU time
unixtime can be used as a filter:
eg: rrdtool fetch ... | unixtime [options]
or with filenames as arguments:
eg: unixtime [options] file1 file2 ... filen
or with timestamps as arguments:
unixtime [options] 1232182800 1232182860 ...
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: unixtime
Url: http://lists.oetiker.ch/pipermail/rrd-users/attachments/20090224/bbcabb64/attachment.ksh
More information about the rrd-users
mailing list