├── .gitignore ├── BuildOpenResty.md ├── README.md ├── Snapshots.md ├── docker-compose.yml ├── docker ├── backend │ ├── Dockerfile │ ├── build.sh │ └── push.sh ├── grafana │ ├── Dockerfile │ ├── build.sh │ ├── datasource.yml │ ├── grafana.ini │ ├── nginx-api-dashboard.json │ ├── nginx-api-host-endpoint-url.json │ ├── nginx-api-host-endpoint.json │ ├── nginx-api-host.json │ ├── provisioning.yml │ └── push.sh ├── nginx │ ├── Dockerfile │ ├── buid.sh │ └── push.sh └── prometheus │ ├── Dockerfile │ ├── build.sh │ ├── nginx.alert.rule │ ├── nginx.counter.rule │ ├── nginx.errrate.rule │ ├── nginx.latency.rule │ ├── nginx.qps.rule │ ├── prometheus.yml │ └── push.sh ├── gitpush.sh ├── pictures ├── resty-lua-prometheus-snapshot01.png ├── resty-lua-prometheus-snapshot02.png ├── resty-lua-prometheus-snapshot03.png └── resty-lua-prometheus-snapshot04.png └── workdir ├── conf.d ├── backend.conf └── counter.conf ├── html ├── 50x.html └── index.html ├── lua ├── counter.lua └── prometheus.lua └── nginx.conf /.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | workdir/client_body_temp 3 | workdir/fastcgi_temp 4 | workdir/logs 5 | workdir/proxy_temp 6 | workdir/scgi_temp 7 | workdir/uwsgi_temp 8 | -------------------------------------------------------------------------------- /BuildOpenResty.md: -------------------------------------------------------------------------------- 1 | ### Build OpenResty from source 2 | ```shell 3 | su root 4 | apt install libpcre3-dev libssl-dev perl make build-essential curl -y 5 | 6 | export RESTY_HOME=/opt/openresty 7 | mkdir -p $RESTY_HOME/build 8 | cd $RESTY_HOME 9 | 10 | # build openresty 11 | wget https://openresty.org/download/openresty-1.13.6.2.tar.gz 12 | tar -xvf openresty-1.13.6.2.tar.gz 13 | cd openresty-1.13.6.2 14 | ./configure --prefix=$RESTY_HOME/build -j8 15 | make -j8 16 | make install 17 | $RESTY_HOME/build/nginx/sbin/nginx -V 18 | nginx version: openresty/1.13.6.2 19 | built by gcc 8.3.0 (Ubuntu 8.3.0-6ubuntu1) 20 | built with OpenSSL 1.1.1b 26 Feb 2019 21 | TLS SNI support enabled 22 | configure arguments: --prefix=/opt/openresty/build/nginx --with-cc-opt=-O2 ... --with-http_ssl_module 23 | $RESTY_HOME/build/nginx/sbin/nginx 24 | curl localhost 25 | 26 | ... 27 |

Thank you for flying OpenResty.

28 | ... 29 | 30 | pkill nginx 31 | ``` 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # prometheus-lua-nginx 2 | ![GitHub stars](https://img.shields.io/github/stars/zrbcool/prometheus-lua-nginx.svg?style=social) 3 | ![GitHub followers](https://img.shields.io/github/followers/zrbcool.svg?style=social) 4 | ## Overview 5 | Project **prometheus-lua-nginx** is a complete solution for openresty based api gateway monitoring, **prometheus-lua-nginx** use prometheus lua lib and openresty http request life cycle to inject monitoring code, it is async, high performance, and business awareness, it also have built-in grafana dashboard out of box, please see [Snapshots](https://github.com/zrbcool/prometheus-lua-nginx/blob/master/Snapshots.md) 6 | 7 | ## Concept 8 | How to measure your API performance? how stable your service are? 9 | 10 | The answer is metrics monitoring: 11 | 12 | From last one years, our best practise is the following metrics and dimensions 13 | - P99(latency percent 99%), P999, P90 this most important metrics, it will impact your users expirence about your apis. 14 | - Error rate 15 | - QPS 16 | 17 | Dimensions: 18 | - host, every web site use virtual host to isolate sub business systems 19 | - endpoint, endpoint is the root access point of your api like /myapi 20 | - fullurl, this is the detail of one specific api, not aggrated data, it will help you find out the service quality trends 21 | - SLA, correct response/all request * 100% during a timewindow 22 | - statuscode, method, scheme 23 | 24 | **prometheus-lua-nginx** use Prometheus to collect request latency metrics, below is the data model 25 | 26 | `{