Dans mon fichier de configuration Apache, le format de logs est défini ainsi :
LogFormat « %h %l %u %t \ »%r\ » %>s %b \ »%{Referer}i\ » \ »%{User-Agent}i\ » » combined
Dans mon fichier access_log, j’ai des logs de ce genre :
::1 – – [01/Apr/2012:19:30:01 +0200] « GET /index.html HTTP/1.1 » 404 283 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:30:05 +0200] « GET / HTTP/1.1 » 403 4609 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:31:52 +0200] « GET /test.php HTTP/1.1 » 404 281 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:33:45 +0200] « GET /test.php HTTP/1.1 » 404 281 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:33:46 +0200] « GET /test.php HTTP/1.1 » 404 281 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:33:47 +0200] « GET /test.php HTTP/1.1 » 404 281 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:33:49 +0200] « GET /test.php HTTP/1.1 » 404 281 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:36:06 +0200] « GET /test.php HTTP/1.1 » 200 51377 « – » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:36:06 +0200] « GET /test.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1 » 200 2524 « http://localhost/test.php » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
::1 – – [01/Apr/2012:19:36:06 +0200] « GET /test.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.1 » 200 2146 « http://localhost/test.php » « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
Signification
Dans la documentation en ligne d’Apache, j’ai ceci :
%...h
: Remote host => ::1 dans notre cas, appel en local
%...l
Remote logname (from identd, if supplied). This will return a dash unless IdentityCheck
is set On
. => vide dans notre cas
%...u
Remote user (from auth; may be bogus if return status (%s
) is 401) => vide dans notre cas
%...t
Time the request was received (standard english format) => exemple : [01/Apr/2012:19:30:05 +0200]
%...r
First line of request => exemple : « GET /index.html HTTP/1.1 »
%...s
Status. For requests that got internally redirected, this is the status of the *original* request — %...>s
for the last. => exemple : 404
%...b
Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a ‘-
‘ rather than a 0 when no bytes are sent. => exemple : 283
%...{Foobar}i
The contents of Foobar:
header line(s) in the request sent to the server. Changes made by other modules (e.g. mod_headers
) affect this.
=> exemple : « Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 »
Compter les différents statuts retournés par Apache
Si vous avez lu mon dernier article, cela vous semblera très simple à faire. Je repère la colonne qui m’intéresse, ici c’est la colonne numéro 9 en rouge. J’utilise du awk pour n’afficher qu’une colonne bien précise puis je trie et compte le nombre de codes retournés par Apache.
cat /var/log/httpd/access_log | awk ‘{ print $9 }’ | sort | uniq -c
Cela donne :
5 200
2 304
17 403
18 404
=> 5 fois le code 200, 2 fois le code 304, 17 fois le code 403, 18 fois le code 404.
Pour en savoir plus sur la signification des codes.