how to get requests parameter at nginx access

Viewed 796

We want to get the requests count at access.log that hits the web server. At present, at our nginx.conf file, we converted the log format to JSON and added stub status at server section to get more information. The configuration of Logging settings and server block at HTTP section looks like:

log_format  json  '{'
                    '"remote_addr": "$remote_addr",'
                    '"remote_user": "$remote_user",'
                    '"timestamp": "$time_iso8601",'
                    '"request": "$request",'
                    '"status": "$status",'
                    '"request_time": "$request_time",'
                    '"body_bytes_sent": "$body_bytes_sent",'
                    '"http_referer": "$http_referer",'
                    '"http_user_agent": "$http_user_agent",'
                    '"http_x_forwarded_for": "$http_x_forwarded_for",'
                    '"upstream_response_time": "$upstream_response_time",'
                    '"connection":"$connection",'
                    '"connection_requests": "$connection_requests",'
                    '"connections_active": "$connections_active",'
                    '"connections_reading": "$connections_reading",'
                    '"connections_writing": "$connections_writing",'
                    '"connections_waiting": "$connections_waiting"'
                    '}';

access_log /var/log/nginx/access.log json;
error_log /var/log/nginx/error.log;

We have added stub_status at server section like:

server {
    location /nginx_status {
        stub_status on;

        access_log on;
        allow 127.0.0.1;
        deny all;
    }
}

By changing to this configuration, we are getting the logs in the json format. Below we are showing the access.log:

{"remote_addr": "xx.x.xx.xxx","remote_user": "-","timestamp": "2017-11-22T10:09:36+00:00","request": "GET /static/images/favicon.ico?v=2 HTTP/1.1","status": "200","request_time": "0.000","body_bytes_sent": "2366","http_referer": "-","http_user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36 Google Favicon","http_x_forwarded_for": "xxx.xxx.x.xx","upstream_response_time": "-","connection":"44827","connection_requests": "1","connections_active": "2","connections_reading": "0","connections_writing": "0","connections_waiting": "1"}

Now the issue is, we are having $connection_requests, which we get the requests per connection. But, we need the number of requests that hit the server.
Is there any parameter or variable which returns the number of requests?.
If there is no parameter, can you help us to find out the way to get those number of requests?.

Thank you...

0 Answers
Related