nginx-module-vts 是一個很不錯的nginx 模塊,咱們能夠用來,方便的分析系統的請求狀態
同時支持基於prometheus 的監控, 我參考openresty 的docker鏡像已經制做了一個集成模塊
的鏡像 dalongrong/openresty-nginx-module-vtshtml
version: "3" services: api: build: ./ image: dalongrong/demo-ngx-vts ports: - "8080:80" g: image: grafana/grafana ports: - "3000:3000" p: image: prom/prometheus volumes: - "./prometheus.yml:/etc/prometheus/prometheus.yml" ports: - "9090:9090"
FROM dalongrong/openresty-nginx-module-vts COPY nginx.conf usr/local/openresty/nginx/conf/ EXPOSE 80 EXPOSE 443 EXPOSE 88
nginx.confnginx
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; vhost_traffic_status_zone; real_ip_header X-Forwarded-For; real_ip_recursive on; upstream backend-app { server 10.15.0.66:80 weight=20 max_fails=2 fail_timeout=30s; } server { listen 80; charset utf-8; location / { index index.html index.htm; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $remote_addr; client_body_buffer_size 10M; client_max_body_size 10G; proxy_buffers 1024 4k; proxy_read_timeout 300; proxy_next_upstream error timeout http_404; proxy_pass http://backend-app; } location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; } location /alert { default_type text/html; content_by_lua_block{ ngx.say([[<script>alert("error")</script>]]) } } location /ip { default_type text/html; content_by_lua_block{ ngx.say(ngx.var.remote_addr) } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 88; server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
scrape_configs: - job_name: nginx metrics_path: /status/format/prometheus static_configs: - targets: ['api:80']
docker-compose up -d
nginx-module-vts 是一個很方便的模塊,集成進openresty 中,咱們能夠快速的實現系統的信息監控,同時模塊的文檔也很全,相似的也
有一個基於opentracing 的模塊nginx-opentracinggit
https://github.com/rongfengliang/openresty_nginx-module-vts_prometheus_grafana
https://github.com/vozlt/nginx-module-vts
https://github.com/rongfengliang/openresty-nginx-module-vts
http://www.javashuo.com/article/p-awbalpfg-ez.htmlgithub