{"id":15043872,"url":"https://github.com/lax/traffic-accounting-nginx-module","last_synced_at":"2026-05-31T07:01:07.644Z","repository":{"id":896307,"uuid":"649961","full_name":"Lax/traffic-accounting-nginx-module","owner":"Lax","description":"Monitor the incoming and outgoing traffic metrics in realtime for NGINX","archived":false,"fork":false,"pushed_at":"2026-05-31T05:23:05.000Z","size":777,"stargazers_count":286,"open_issues_count":4,"forks_count":79,"subscribers_count":17,"default_branch":"master","last_synced_at":"2026-05-31T06:15:43.762Z","etag":null,"topics":["nginx","observability","realtime","traffic-accounting","traffic-metrics"],"latest_commit_sha":null,"homepage":"https://github.com/Lax/traffic-accounting-nginx-module","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2010-05-06T08:35:37.000Z","updated_at":"2026-05-31T04:34:57.000Z","dependencies_parsed_at":"2022-08-16T11:20:46.895Z","dependency_job_id":null,"html_url":"https://github.com/Lax/traffic-accounting-nginx-module","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/Lax/traffic-accounting-nginx-module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lax%2Ftraffic-accounting-nginx-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lax%2Ftraffic-accounting-nginx-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lax%2Ftraffic-accounting-nginx-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lax%2Ftraffic-accounting-nginx-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lax","download_url":"https://codeload.github.com/Lax/traffic-accounting-nginx-module/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lax%2Ftraffic-accounting-nginx-module/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33722156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nginx","observability","realtime","traffic-accounting","traffic-metrics"],"created_at":"2024-09-24T20:49:44.506Z","updated_at":"2026-05-31T07:01:07.617Z","avatar_url":"https://github.com/Lax.png","language":"C","funding_links":["https://opencollective.com/traffic-acctiong-nginx-module","https://opencollective.com/traffic-acctiong-nginx-module/contribute","https://opencollective.com/traffic-acctiong-nginx-module/organization/0/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/1/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/2/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/3/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/4/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/5/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/6/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/7/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/8/website","https://opencollective.com/traffic-acctiong-nginx-module/organization/9/website"],"categories":[],"sub_categories":[],"readme":"# traffic-accounting-nginx-module\n\nMonitor the incoming and outgoing traffic metrics in realtime for `NGINX`.\n\n**Now accounting module supports both `HTTP` and `STREAM` subsystems**\n\nA realtime traffic and status code monitor solution for NGINX,\nwhich needs less memory and cpu than other realtime log analyzing solutions.\nUseful for traffic accounting based on NGINX config logic (by location / server / user-defined-variables).\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FLax%2Ftraffic-accounting-nginx-module.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FLax%2Ftraffic-accounting-nginx-module?ref=badge_shield)\n[![Financial Contributors on Open Collective](https://opencollective.com/traffic-acctiong-nginx-module/all/badge.svg?label=financial+contributors)](https://opencollective.com/traffic-acctiong-nginx-module) \n\n## Why?\n\nRealtime log analysis solutions,\nwhich requires multiple machines for storage and analysis,\nare too heavy for application monitoring.\n\nAn cost-effective solution is in need to monitor the traffic metrics/status of application requests.\nThis solution should be accurate, sensitive, robust, light weight enough, and not affected by traffic peaks.\n\n## How it works?\n\nThis module keeps a list of **metrics** identified by `accounting_id` in its context.\n\nWhen a new **request** hits the server, the module will try to find its `accounting_id`, calculate statistics, and **aggregate** them into the corresponding metrics by `accounting_id`.\n\nFor each time period (defined by `interval`), a timer event is triggered, those metrics are rotated and exported to log files or sent to remote log servers.\n\n\n---\n\n# Quickstart\n\nDownload pre-build binaries from [Releases](https://github.com/Lax/traffic-accounting-nginx-module/releases),\nplace them into `./modules` sub-directory of `nginx`.\n\nAdd following lines at the beginning of `nginx.conf`:\n\n```\nload_module modules/ngx_http_accounting_module.so;\n```\n\nReload nginx config with `nginx -s reload`. *Done!*\n\n*Alternatively, you can install this module manually with the Nginx source, see the [installation instructions](#Installation)*\n\n---\n\n## Dashboard\n\n**Dashboard - Visualize with Grafana**\n![Accounting Dashboard](http://lax.github.io/traffic-accounting-nginx-module/images/accounting-dashboard.png)\n\n---\n\n# Configuration\n\nEdit your nginx.conf.\n\nExample:\n\n```nginx\nhttp{\n    # turn on accounting function\n    accounting  on;\n    accounting_log  logs/http-accounting.log;\n    ...\n    server {\n        server_name example.com;\n\n        accounting_id  $http_host;  # set accounting_id string by variable\n\n        location / {\n            accounting_id  accounting_id_str;  # set accounting_id string by location\n\n            ...\n        }\n\n        location /api {\n            accounting_id  API_PC;   # for pc\n\n            if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {\n                accounting_id  API_MOBILE;   # for mobile\n            }\n\n            ...\n        }\n    }\n\n}\n```\n\n# Directives\n\naccounting\n--------------------\n**syntax:** *accounting on | off*\n\n**default:** *accounting off*\n\n**context:** *http, stream*\n\naccounting_log\n--------------------\n**syntax:** *accounting_log \\\u003c/path/to/log/file\u003e \\[level]*\n\n**default:** *-*\n\n**context:** *http, stream*\n\nConfigures logging.\n\nSupport both local `file` path, or `stderr`, or `syslog:`.\nThe second parameter is the log level.\nFor more details of supported params, refer to [this page from nginx.org](http://nginx.org/en/docs/ngx_core_module.html#error_log).\n\nIf not specified, accounting log will be written to `/dev/log`.\n\naccounting_id\n--------------------\n**syntax:** *accounting_id \\\u003caccounting_id\u003e*\n\n**default:** *accounting_id default*\n\n**context:** *http, stream, server, location, if in location*\n\nSets the `accounting_id` string by user defined variable.\n\nThis string is used to determine which `metrics` a request/session should be aggregated to.\n\naccounting_interval\n------------------------\n**syntax:** *accounting_interval \\\u003cseconds\u003e*\n\n**default:** *accounting_interval 60*\n\n**context:** *http, stream*\n\nSpecifies the reporting interval.  Defaults to 60 seconds.\n\naccounting_perturb\n------------------------\n**syntax:** *accounting_perturb on | off*\n\n**default:** *accounting_perturb off*\n\n**context:** *http, stream*\n\nRandomly staggers the reporting interval by 20% from the usual time.\n\n# Usage\n\nThis module can be configured to writes metrics to local file, remote log server or local syslog device.\n\nOpen-source log-aggregation software such as logstash also support syslog input, which will help you establish a central log server.\nSee [samples/logstash/](samples/logstash/) for examples. [**Recommended**]\n\nTo collect logs with local syslog,\nrefer [Lax/ngx_http_accounting_module-utils](http://github.com/Lax/ngx_http_accounting_module-utils) to for sample configuration / utils.\n\n## docker / docker-compose\nTo demonstrate with docker-compose, run\n\n```\ndocker-compose build\ndocker-compose up -d\n```\n\nOpen Grafana (address: `http://localhost:3000`) in your browser.\n\nCreate and configurate elasticsearch datasource with options:\n```\nType: elasticsearch\nURL: http://elasticsearch:9200\nVersion: 5.6+\nMin time interval: 1m\n```\n\nThen import accounting dashboard from  [`samples/accounting-dashboard-grafana.json`](samples/accounting-dashboard-grafana.json).\n\n\n## Metrics log format\n\n```\n# HTTP\n2018/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\n2018/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\n\n# Stream\n2018/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\n```\n\nEach line of the log output contains `metrics` for a particular `accounting_id`,\nwhich contains a list of key-values.\n\n|  key name       |  meanings of values |\n|-----------------|---------------------|\n| `pid`           | pid of nginx worker process |\n| `from` / `to`   | metric was collected from the `period` between these timestamps |\n| `accounting_id` | identify for the accounting unit, set by `accounting_id` directive |\n| `requests`      | count of total requests processed in current period (HTTP module only) |\n| `sessions`      | count of total sessions processed in current period (Stream module only) |\n| `bytes_in`      | total bytes received by the server |\n| `bytes_out`     | total bytes send out by the server |\n| `latency_ms`    | sum of all requests/sessions' `$session_time`, in `millisecond` |\n| `upstream_latency_ms`  | sum of `$upstream_response_time`, in `millisecond` |\n| `200` / `302` / `400` / `404` / `500` ... | count of requests/sessions with status code `200`/`302`/`400`/`404`/`500`, etc. Notice the differences between http codes and stream codes |\n\n\n---\n## Installation\n\n### Step 1\n\nThere are several ways to integrate traffic accounting functions into NGINX.\n\n* Download pre-build binaries from [Releases](https://github.com/Lax/traffic-accounting-nginx-module/releases).\n\n* Build the binaries from sources\n\n```\n# grab nginx source code from nginx.org, then cd to /path/to/nginx-src/\ngit clone https://github.com/Lax/traffic-accounting-nginx-module.git\n\n# to build as `static` module\n./configure --prefix=/opt/nginx --with-stream --add-module=traffic-accounting-nginx-module\nmake \u0026\u0026 make install\n\n\n# to build as `dynamic` module\n# both HTTP and STREAM module, target module file name is ngx_http_accounting_module.so\n./configure --prefix=/opt/nginx --with-stream --add-dynamic-module=traffic-accounting-nginx-module\n\n# only HTTP module, target module file name is ngx_http_accounting_module.so\n#./configure --prefix=/opt/nginx --add-dynamic-module=traffic-accounting-nginx-module\n\n# only STREAM module, target module file name is ngx_stream_accounting_module.so\n#./configure --prefix=/opt/nginx --without-http --add-dynamic-module=traffic-accounting-nginx-module\n\nmake modules\n```\n\n### Step 2 (dynamic module only)\n\nAdd the following lines at the beginning of `nginx.conf`:\n\n```\nload_module modules/ngx_http_accounting_module.so;\n\n# for STREAM only build\n#load_module modules/ngx_stream_accounting_module.so;\n```\n\n### Step 3\n\n```\nhttp {\n  accounting        on;\n  accounting_log    logs/http-accounting.log;\n  accounting_id     $hostname;\n\n  ...\n}\n\nstream {\n  accounting        on;\n  accounting_log    logs/stream-accounting.log;\n  accounting_id     $hostname;\n\n  ...\n}\n```\n\n## Visualization\n\nVisualization with `Kibana` or `Grafana` is easy.\nSee [samples/](samples/) for examples.\n\n---\n\n# Branches\n\n* master : main development branch.\n* tag v0.1 or v2-freeze-20110526 : legacy release. works with nginx version(0.7.xx, 0.8.xx), nginx 0.9 is not tested. didn't work with nginx above 1.0.x.\n\n# Contributing\n\n1. Fork it ( https://github.com/Lax/traffic-accounting-nginx-module/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n[Known issues](https://github.com/Lax/traffic-accounting-nginx-module/issues?q=)\n\n# Author\n\nLiu Lantao [Github@Lax](https://github.com/Lax)\n\n[Contributors](https://github.com/Lax/traffic-accounting-nginx-module/graphs/contributors)\n\n## Contributors\n\n### Code Contributors\n\nThis project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].\n\u003ca href=\"https://github.com/Lax/traffic-accounting-nginx-module/graphs/contributors\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/contributors.svg?width=890\u0026button=false\" /\u003e\u003c/a\u003e\n\n### Financial Contributors\n\nBecome a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/traffic-acctiong-nginx-module/contribute)]\n\n#### Individuals\n\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/individuals.svg?width=890\"\u003e\u003c/a\u003e\n\n#### Organizations\n\nSupport this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/traffic-acctiong-nginx-module/contribute)]\n\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/0/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/0/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/1/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/1/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/2/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/2/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/3/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/3/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/4/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/4/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/5/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/5/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/6/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/6/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/7/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/7/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/8/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/8/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/9/website\"\u003e\u003cimg src=\"https://opencollective.com/traffic-acctiong-nginx-module/organization/9/avatar.svg\"\u003e\u003c/a\u003e\n\n# License\n\n[BSD-2-Clause](LICENSE)\n\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FLax%2Ftraffic-accounting-nginx-module.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FLax%2Ftraffic-accounting-nginx-module?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flax%2Ftraffic-accounting-nginx-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flax%2Ftraffic-accounting-nginx-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flax%2Ftraffic-accounting-nginx-module/lists"}