Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Prometheus metric library for Nginx written in Lua
| Date | Stars |
|---|---|
| 2026-07-24 | 1562 |
| 2026-07-25 | 1562 |
| 2026-07-28 | 1562 |
| 2026-07-30 | 1562 |
| 2026-08-09 | 1563 |
| 2026-08-17 | 1564 |
| 2026-08-19 | 1565 |
| 2026-08-20 | 1563 |
| 2026-08-22 | 1562 |
| 2026-09-03 | 1563 |
| 2026-09-05 | 1563 |
| 2026-09-11 | 1563 |
| 2026-09-14 | 1563 |
| 2026-09-16 | 1564 |
| 2026-09-17 | 1566 |
| 2026-09-20 | 1566 |
Today
— stars today
This week
+3 stars this week
This month
+3 stars this month
Momentum
3.0
growth rate 0.19%/day
[](https://coveralls.io/github/knyar/nginx-lua-prometheus?branch=master)
# Prometheus metric library for Nginx
This is a Lua library that can be used with Nginx to keep track of metrics and
expose them on a separate web page to be pulled by
[Prometheus](https://prometheus.io).
## Installation
To use this library, you will need the [ngx_lua](
https://github.com/openresty/lua-nginx-module) nginx module. You can either use
a lua-enabled nginx-based server like [OpenResty](https://openresty.org/en/),
or a regular nginx server with the module enabled: for example, on Debian 10 you
can simply install `libnginx-mod-http-lua` (but please read the [known issues](
#known-issues) if you use a later Debian version).
The library file - `prometheus.lua` - needs to be available in `LUA_PATH`. If
this is the only Lua library you use, you can just point `lua_package_path` to
the directory with this git repo checked out (see example below).
OpenResty users will find this library in [opm](https://opm.openresty.org/package/knyar/nginx-lua-prometheus/). It
is also available via
[luarocks](https://luarocks.org/modules/knyar/nginx-lua-prometheus).
## Quick start guide
To track request latency broken down by server name and request count
broken down by server name and status, add the following to the `http` section
of `nginx.conf`:
```nginx
lua_shared_dict prometheus_metrics 10M;
lua_package_path "/path/to/nginx-lua-prometheus/?.lua;;";
init_worker_by_lua_block {
prometheus = require("prometheus").init("prometheus_metrics")
metric_requests = prometheus:counter(
"nginx_http_requests_total", "Number of HTTP requests", {"host", "status"})
metric_latency = prometheus:histogram(
"nginx_http_request_duration_seconds", "HTTP request latency", {"host"})
metric_connections = prometheus:gauge(
"nginx_http_connections", "Number of HTTP connections", {"state"})
}
log_by_lua_block {
metric_requests:inc(1, {ngx.var.server_name, ngx.var.status})
metric_latency:observe(tonumber(ngx.var.request_time), {ngx.var.server_name})
}
```
This:
* configures a shared dictionary for your metrics called `prometheus_metrics`
with a 10MB size limit;
* registers a counter called `nginx_http_requests_total` with two labels:
`host` and `status`;
* registers a histogram called `nginx_http_request_duration_seconds` with one
label `host`;
* registers a gauge called `nginx_http_connections` with one label `state`;
* on each HTTP request measures its latency, recording it in the histogram and
increments the counter, setting current server name as the `host` label and
HTTP status code as the `status` label.
Last step is to configure a separate server that will expose the metrics.
Please make sure to only make it reachable from your Prometheus server:
```nginx
server {
listen 9145;
allow 192.168.0.0/16;
deny all;
location /metrics {
content_by_lua_block {
metric_connections:set(ngx.var.connections_reading, {"reading"})
metric_connections:set(ngx.var.connections_waiting, {"waiting"})
metric_connections:set(ngx.var.connections_writing, {"writing"})
prometheus:collect()
}
}
}
```
Metrics will be available at `http://your.nginx:9145/metrics`. Note that the
gauge metric in this example contains values obtained from nginx global state,
so they get set immediately before metrics are returned to the client.
## API reference
### init()
**syntax:** require("prometheus").init(*dict_name*, [*options*]])
Initializes the module. This should be called once from the
[init_worker_by_lua_block](https://github.com/openresty/lua-nginx-module#init_worker_by_lua_block)
section of nginx configuration.
* `dict_name` is the name of the nginx shared dictionary which will be used to
store all metrics. Defaults to `prometheus_metrics` if not specified.
* `options` is a table of configuration options that can be provideExcerpt of 18,739 characters
Read on GitHub107
6
jinhua luo · China
2
2
2
kurt · @Kong
2
1
1
1
1
1
1
1
Wangchong Zhou · @kong · China
1
1
Eloy Coto · Red Hat · Spain
1
Shuyang Wu · United States
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:dec49808059aea93, topic:monitoring