Nginx Lua module to collect and show statistics.
See nginx.conf for example.
collect_statuses.lua module collect statistics for requests across location with log_by_lua_file 'collect_stats.lua'; directive.
show_stat.lua response for JSON reply.
For a start, you need nginx with HttpLuaModule, and lua json lib installed (liblua5.1-json for ubuntu).
/usr/share/nginx/, in example below)Update your nginx.conf:
lua_shared_dict stat_dict 1M; in http sectionlua_package_path '/usr/share/nginx/?.lua;;'; in http sectionlog_by_lua_file '/usr/share/nginx/collect_stats.lua'; directive in location from which to you want collect statistic/usr/share/nginx/content_by_lua_file 'show_stat.lua' directive insidedocker build -t ngx_stat_img .docker run -p 80:80 --name=ngx_stat -d ngx_stat_imgLast command return container id, so you can use it to check logs by docker logs _container_id_.
To check that it is works go to http://localhost and other location like http://localhost/304 or http://localhost/500,
and on http://localhost/show_stat/ to get statistic page or curl http://localhost/stat to get JSON.
You also can run container with test suite:
docker build -t ngx_test_img .docker run -i -t --link=ngx_stat:web ngx_test_imgLast command should return result of tests.
You can just pull image from index.docker.io by docker pull shoonoise/lua-nginx-statistics.
You may want to use lua cjson module instead of liblua5.1-json for performance purpose.
Just install cjson from ppa and replace local json = require("json") to local json = require("cjson")
in lua scripts.
Set $stat_counter nginx variable in config to group statuses.
For example set $stat_counter $uri to collect statuses for each uri separately.
Content type
Image
Digest
sha256:9c338d9f0…
Size
231.8 MB
Last updated
almost 11 years ago
docker pull shoonoise/lua-nginx-statistics