traffic-accounting-nginx-module
traffic-accounting-nginx-module copied to clipboard
QUESTION: Any practical way to use this module with multiple Independent servers?
I've builded a CDN to deliver static content to my users. To deliver the content, I'm using NGINX. But now I also would like to count traffic usage for each user (webdav users are meant here)
The problem is that each of my servers work independently, there is no Kubernetes or so that manages the servers or is able to aggregate logs from different servers. Is there any practical way where I can use the module in that way, that it doesn't matter on which server the traffic occurs? Besides, I'm using a load balancer in front, where I have no influence onto the configs it runs, so I really can only work with the NGINX servers at the backend for the traffic accounting.
Currently, my architecture looks like this:
User Request <-> Load balancer <-> NGINX Servers
Or can I simply get rid of this problem by simply using a single dedicated syslog server?
Thanks in advance
The accounting_log directive supports adding a log output to remote central syslog server with UDP or TCP protocol.
See here for an example: https://github.com/Lax/traffic-accounting-nginx-module/blob/master/samples/http.conf#L6
The support parameters are the same as Nginx logging directives: https://nginx.org/en/docs/syslog.html
On the central syslog server, you can receive and save the logs with a normal syslog implement(rsyslog, syslog-ng), or use any other logging server such as logstash, to receive and process the logs. See an example in this folder: https://github.com/Lax/traffic-accounting-nginx-module/tree/master/samples
syslog(UDP)
NGINX -----------------------> syslogd / logstash / or your own UDP server
Do you maybe have an example on how to log looks like in the end? I want to parse the used bandwidth per WebDAV User. Thanks in advance
The final log looks like this:
# HTTP
2018/05/14 14:18:18 [notice] 5#0: pid:5|from:1526278638|to:1526278659|accounting_id:HTTP_ECHO_HELLO|requests:4872|bytes_in:438480|bytes_out:730800|latency_ms:0|upstream_latency_ms:0|200:4872
2018/05/14 14:18:18 [notice] 5#0: pid:5|from:1526278638|to:1526278659|accounting_id:INDEX|requests:4849|bytes_in:421863|bytes_out:1857167|latency_ms:0|upstream_latency_ms:0|301:4849
# Stream
2018/05/14 14:18:22 [notice] 5#0: pid:5|from:1526278642|to:1526278659|accounting_id:TCP_PROXY_ECHO|sessions:9723|bytes_in:860343|bytes_out:2587967|latency_ms:4133|upstream_latency_ms:3810|200:9723
In the NGINX config file, use accounting_log, let the result transfer to a syslog: target. It's similar to error_log of NGINX (reference)
accounting_log syslog:server=192.168.1.1:29124 ;
I was using logstash to collect the log, find the config file here