Skip to content
Snippets Groups Projects
Verified Commit 702be3ee authored by Florian Pritz's avatar Florian Pritz
Browse files

nginx: Add json log format


Signed-off-by: default avatarFlorian Pritz <bluewind@xinu.at>
parent 5ee78040
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,36 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
log_format json_main escape=json
'{'
'"remote_addr":"$remote_addr",'
'"host":"$host",'
'"remote_user":"$remote_user",'
'"time_local":"$time_local",'
'"request":"$request",'
'"status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"http_x_forwarded_for":"$http_x_forwarded_for",'
'"request_time":"$request_time"'
'}';
log_format json_reduced escape=json
'{'
'"remote_addr":"$remote_addr",'
'"host":"$host",'
'"remote_user":"$remote_user",'
'"time_local":"$time_local",'
'"request":"$request",'
'"status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"http_x_forwarded_for":"$http_x_forwarded_for",'
'"request_time":"$request_time"'
'}';
sendfile on;
keepalive_timeout 65;
client_max_body_size 16M;
......
......@@ -84,6 +84,11 @@ sub main {
#print "Got line: ".$line."\n";
$line = trim($line);
# json log format
if ($line =~ m/^{.*}$/) {
update_stats_for_line($values_per_host, $stat_per_host, $value_template, \$modified_hostlist, decode_json($line));
}
# main log format
if ($line =~ m/(?<remote_addr>\S+) (?<host>\S+) (?<remote_user>\S+) \[(?<time_local>.*?)\]\s+"(?<request>.*?)" (?<status>\S+) (?<body_bytes_sent>\S+) "(?<http_referer>.*?)" "(?<http_user_agent>.*?)" "(?<http_x_forwarded_for>\S+)"(?: (?<request_time>[\d\.]+|-))?/) {
update_stats_for_line($values_per_host, $stat_per_host, $value_template, \$modified_hostlist, \%+);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment