initial module

This commit is contained in:
2026-05-07 22:57:00 +03:30
commit 1e5deb18b3
27 changed files with 5271 additions and 0 deletions

90
dockerized/Dockerfile Normal file
View File

@@ -0,0 +1,90 @@
ARG DEBIAN_VERSION=bookworm
ARG NGINX_VERSION=1.28.0
FROM debian:${DEBIAN_VERSION}-slim AS builder
ARG NGINX_VERSION
ARG NGINX_CONFIGURE_ARGS="--with-compat --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_v2_module --with-http_gzip_static_module"
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
libpcre2-dev \
libssl-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src
RUN curl -fsSLO "https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" \
&& tar -xzf "nginx-${NGINX_VERSION}.tar.gz" \
&& rm "nginx-${NGINX_VERSION}.tar.gz"
COPY . /usr/src/ngx_http_monitoring_module
WORKDIR /usr/src/nginx-${NGINX_VERSION}
RUN ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/sbin/nginx \
--modules-path=/usr/local/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
${NGINX_CONFIGURE_ARGS} \
--add-dynamic-module=/usr/src/ngx_http_monitoring_module \
&& make -j"$(nproc)" \
&& make install \
&& mkdir -p /usr/local/nginx/modules \
&& cp objs/ngx_http_monitoring_module.so /usr/local/nginx/modules/
FROM debian:${DEBIAN_VERSION}-slim AS runtime
ARG NGINX_VERSION
LABEL org.opencontainers.image.title="ngx_http_monitoring_module nginx image" \
org.opencontainers.image.description="Nginx built with ngx_http_monitoring_module and embedded monitoring dashboard" \
org.opencontainers.image.version="${NGINX_VERSION}"
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
libpcre2-8-0 \
libssl3 \
zlib1g \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd --system --gid 101 nginx \
&& useradd --system --gid nginx --no-create-home --home /nonexistent \
--shell /usr/sbin/nologin --uid 101 nginx \
&& mkdir -p /var/cache/nginx/client_temp \
/var/cache/nginx/proxy_temp \
/var/cache/nginx/fastcgi_temp \
/var/cache/nginx/uwsgi_temp \
/var/cache/nginx/scgi_temp \
/var/log/nginx \
/etc/nginx/conf.d \
&& chown -R nginx:nginx /var/cache/nginx /var/log/nginx
COPY --from=builder /usr/local/nginx /usr/local/nginx
COPY --from=builder /usr/local/sbin/nginx /usr/local/sbin/nginx
COPY dockerized/nginx.conf /etc/nginx/nginx.conf
EXPOSE 8080
STOPSIGNAL SIGQUIT
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD /usr/local/sbin/nginx -t -q && \
test -r /usr/local/nginx/modules/ngx_http_monitoring_module.so
CMD ["/usr/local/sbin/nginx", "-g", "daemon off;"]

67
dockerized/README.md Normal file
View File

@@ -0,0 +1,67 @@
# Dockerized Nginx Image
This folder builds an Nginx image with `ngx_http_monitoring_module` compiled and loaded as a dynamic module.
## Build
From the repository root:
```sh
docker build -f dockerized/Dockerfile -t ngx-http-monitoring-module:local .
```
Or:
```sh
sh dockerized/build.sh
```
To choose a different Nginx version:
```sh
NGINX_VERSION=1.28.0 sh dockerized/build.sh
```
## Run
```sh
docker run --rm -p 8080:8080 ngx-http-monitoring-module:local
```
Open:
```text
http://127.0.0.1:8080/monitor
```
## Docker Compose
```sh
cd dockerized
docker compose up --build
```
## Smoke Test
With the container running:
```sh
sh dockerized/test.sh
```
## Image Layout
- Nginx binary: `/usr/local/sbin/nginx`
- Module: `/usr/local/nginx/modules/ngx_http_monitoring_module.so`
- Config: `/etc/nginx/nginx.conf`
- Listen port: `8080`
The supplied `nginx.conf` enables:
- `/monitor`
- `/monitor/api`
- `/monitor/live`
- `/monitor/metrics`
- `/monitor/health`
This demo config allows access from any client. Restrict `location /monitor` before exposing the container outside a trusted network.

15
dockerized/build.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -eu
IMAGE="${IMAGE:-ngx-http-monitoring-module:local}"
NGINX_VERSION="${NGINX_VERSION:-1.28.0}"
cd "$(dirname "$0")/.."
docker build \
--build-arg "NGINX_VERSION=$NGINX_VERSION" \
-f dockerized/Dockerfile \
-t "$IMAGE" \
.
echo "Built $IMAGE"

View File

@@ -0,0 +1,12 @@
services:
nginx-monitor:
build:
context: ..
dockerfile: dockerized/Dockerfile
args:
NGINX_VERSION: "1.28.0"
image: ngx-http-monitoring-module:local
container_name: ngx-http-monitoring-module
ports:
- "8080:8080"
restart: unless-stopped

57
dockerized/nginx.conf Normal file
View File

@@ -0,0 +1,57 @@
load_module /usr/local/nginx/modules/ngx_http_monitoring_module.so;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 65535;
multi_accept on;
}
http {
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
access_log /var/log/nginx/access.log;
monitor_refresh_interval 1s;
monitor_history 5m;
monitor_resolution 1s;
monitor_shm_size 8m;
monitor_collect_system on;
monitor_collect_nginx on;
monitor_collect_network on;
monitor_access_log on;
monitor_max_top_urls 100;
server {
listen 8080;
server_name _;
location /monitor {
monitor on;
monitor_dashboard on;
monitor_api on;
monitor_sse on;
monitor_rate_limit 240;
monitor_cors "*";
}
location = / {
default_type text/plain;
return 200 "ngx_http_monitoring_module docker image\nopen /monitor for the dashboard\n";
}
location = /workload {
default_type application/json;
return 200 "{\"status\":\"ok\",\"source\":\"dockerized-nginx\"}\n";
}
}
}

13
dockerized/run.sh Normal file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env sh
set -eu
IMAGE="${IMAGE:-ngx-http-monitoring-module:local}"
NAME="${NAME:-ngx-http-monitoring-module}"
PORT="${PORT:-8080}"
docker rm -f "$NAME" >/dev/null 2>&1 || true
docker run \
--name "$NAME" \
-p "$PORT:8080" \
"$IMAGE"

22
dockerized/test.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env sh
set -eu
BASE_URL="${BASE_URL:-http://127.0.0.1:8080}"
curl -fsS "$BASE_URL/" >/dev/null
curl -fsS "$BASE_URL/monitor" >/dev/null
curl -fsS "$BASE_URL/monitor/api" >/dev/null
curl -fsS "$BASE_URL/monitor/api/system" >/dev/null
curl -fsS "$BASE_URL/monitor/api/nginx" >/dev/null
curl -fsS "$BASE_URL/monitor/api/network" >/dev/null
curl -fsS "$BASE_URL/monitor/api/disk" >/dev/null
curl -fsS "$BASE_URL/monitor/api/processes" >/dev/null
curl -fsS "$BASE_URL/monitor/api/upstreams" >/dev/null
curl -fsS "$BASE_URL/monitor/api/connections" >/dev/null
curl -fsS "$BASE_URL/monitor/api/requests" >/dev/null
curl -fsS "$BASE_URL/monitor/metrics" >/dev/null
curl -fsS "$BASE_URL/monitor/health" >/dev/null
timeout 3 curl -fsS -N "$BASE_URL/monitor/live" >/dev/null || true
echo "Dockerized module endpoints are reachable at $BASE_URL"