Converts the output of the NGINX stub_status module to Prometheus format so that basic metrics can be scraped from a /metrics endpoint.
The NGINX JavaScript module is used to filter the stub_status response.
$ curl -i http://localhost:8080/metrics
| # Builds NGINX from the QUIC+HTTP/3 development branch | |
| # - Based on the official NGINX docker image, including all modules built by default | |
| # - OpenSSL replaced with LibreSSL to support QUIC's TLS requirements (statically linked) | |
| # | |
| # docker build --no-cache -t nginx:quic . | |
| # docker run -d -p 443:443 -p 443:443/udp nginx:quic | |
| # | |
| # Note that a suitable configuration file and TLS certificates are required for testing! | |
| # See <https://quic.nginx.org/readme.html> for more info |
| FROM nginx AS build | |
| WORKDIR /src | |
| RUN apt-get update && \ | |
| apt-get install -y git gcc make mercurial libperl-dev libpcre3-dev zlib1g-dev libxslt1-dev libgd-ocaml-dev libgeoip-dev | |
| RUN git clone -b openssl-3.0 https://github.com/openssl/openssl openssl-3.0 && \ | |
| hg clone https://hg.nginx.org/nginx && \ | |
| hg clone http://hg.nginx.org/njs | |
| RUN cd nginx && \ | |
| auto/configure `nginx -V 2>&1 | sed "s/ \-\-/ \\\ \n\t--/g" | grep "\-\-" | grep -ve opt= -e param=` \ |
Converts the output of the NGINX stub_status module to Prometheus format so that basic metrics can be scraped from a /metrics endpoint.
The NGINX JavaScript module is used to filter the stub_status response.
$ curl -i http://localhost:8080/metrics
Moved to GitHub repo https://github.com/lcrilly/unitc
| #!/bin/bash | |
| NJS_VER="" | |
| RBT=0 | |
| UNIT_VER="" | |
| SUFFIX=() | |
| PATCH_FILES=() | |
| CONFIGURE_OPTIONS="" | |
| STARTDIR=$PWD | |
| WORKDIR=/tmp/build_unit.$$ |
The NGINX Unit control API includes a /status endpoint for usage statistics. This is a solution for exposing these metrics in Prometheus format.
The application (run by Unit) queries the /status URI on the control socket and converts the JSON response into Prometheus text format. PHP and Python implementations are available.
These instructions assume an existing Unit installation with a working configuration. We will add a new listener on the default prometheus port (9090) and route it directly to the Prometheus app.
Step 0. Install the preferred Unit language module (unit-php or unit-python)
| # This Dockerfile builds NGINX Unit from source, including njs, and | |
| # by applying any .patch files found in the current directory. The | |
| # latest Docker Official Image is used to select the code branch and | |
| # copies the configure arguments so that the lanauge module in the | |
| # Docker Image is compatible with the new unitd binary. | |
| # | |
| # Build by specifying the tag of the most suitable Docker Official Image | |
| # from <https://hub.docker.com/_/unit/tags> as | |
| # docker build --build-arg TAG=php -t unit:test . | |
| # |
| #!/usr/bin/env bash | |
| # | |
| # oas2nginx.sh (c) NGINX, Inc. [v0.5 13-Jan-2020] Liam Crilly <[email protected]> | |
| # | |
| # Converts OpenAPI/Swagger spec into nginx.conf snippet (server context) as per | |
| # https://www.nginx.com/blog/deploying-nginx-plus-as-an-api-gateway-part-1/ | |
| # Requires shyaml for YAML processing: https://github.com/0k/shyaml | |
| # Defaults | |
| # |