MAL - Memória Auxiliar do Lutieri

sexta-feira, novembro 17, 2006

Data e hora em logs

Sempre me deparei em alguns logs com a seguinte informação. Ex. de log do squid(access.log):

1161403560.693 13 10.1.1.20 TCP_HIT/200 313 GET http://groups.google.com.br/groups/img/dot_clear.gif - NONE/- image/gif

O problema todo é que esse primeiro valor corresponde a data e hora do acesso. Se você utiliza o sarg, por exemplo, ele pega esse valores transforma na forma humanamente legível e coloca em seus relatórios.

Essa semana vagando pelo site do gentoo encontrei um dica de como converter esses valores para uma forma legível. Segue o treco do texto com as dicas de conversão. Se você não entende inglês não tem problema apenas utilize algum dos comando em negrito:


Jorge Almeida wanted to know if the cryptic numbers (e.g., "1161911504") at the beginning of each line in his emerge log were dates, and if so, how to render them human readable. Harm Geerts confirmed that the figure was Unix time ("the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds") and suggested translating it using Python.

Code Listing 2.1: Converting from UNIX time with python

$ python -c "import time; print time.ctime(1161911504)"

Bo Ørsted Andresen suggested using awk, instead.

Code Listing 2.2: Converting from UNIX time with awk #1

$ tail /var/log/emerge.log | awk -F: '{print strftime("%D %X %Z", $1),$2}'

Peter Ruskin amended this to be shorter and less internationally ambiguous in its output.

Code Listing 2.3: Converting from UNIX time with awk #2

$ tail /var/log/emerge.log | awk -F: '{print strftime("%c", $1),$2}'

The last (and to Jorge most suitable) solution was Richard Fish's.

Code Listing 2.4: Converting from UNIX time using date

$ date -d @1161911504


Essa última eu acho a mais interessante mas fica a seu critério a escolha.

Só por curiosidade esse valor enorme (1161403560.693) é número de segundos transcorridos desde a meia noite da segunda-feira 1º de Janeiro de 1970.


Fonte: http://www.gentoo.org/news/en/gwn/20061030-newsletter.xml

Teh mais....

0 Comentários:

Postar um comentário

<< Home



Chat with Lutieri G. B.

Subscribe in a reader