Coder Social home page Coder Social logo

ngx_stats's Introduction

ngx_stats

Watch live nginx stats from your servers

Installation

  1. Install nginx configured with --add-module=/path/to/lua-nginx-module
  2. Clone ngx_stats in path specified by lua_package_path policy
cd /etc/nginx/lua/
git clone [email protected]:StudioSol/ngx_stats.git stats

Overview

Nginx Lua module to capture and show stats. stats/log.lua module collect statistics for requests across location with log_by_lua_file 'stats/log.lua'; directive. stats/show.lua response for JSON reply.

Configure nginx:

user www-data;
worker_processes  1;
error_log  /var/log/nginx/error.log error;
pid        /var/run/nginx.pid;
events {
    worker_connections  61440;
}

http {
    access_log  off;

    lua_shared_dict ngx_stats 10m;
    lua_package_path '/etc/nginx/lua/?.lua;;';
    lua_package_cpath '/etc/nginx/lua/?.so;;';
    init_by_lua_file /etc/nginx/lua/stats/init.lua;

    proxy_cache_path /var/tmp/cache_http levels=1:1:1
        keys_zone=g_cache:64m
        max_size=1024m inactive=4h;

    server {
        listen 80;
        server_name example.com;
        set $stats_group "example.com";
        log_by_lua_file /etc/nginx/lua/stats/log.lua;
        location / {
            proxy_pass "http://127.0.0.1:8080";
            proxy_cache g_cache;
        }
        location = /status.json {
            default_type 'application/json';
            content_by_lua_file /etc/nginx/lua/stats/show.lua;
        }
    }
    server {
        listen 80;
        server_name  sub.example.com;
        set $stats_group "sub.example.com";
        log_by_lua_file /etc/nginx/lua/stats/log.lua;
        location / {
            proxy_pass "http://127.0.0.1:8081";
            proxy_cache g_cache;
        }
    }
    server {
        listen 80 default_server;
        server_name  _;
        log_by_lua_file /etc/nginx/lua/stats/log.lua;
        return 404;
    }
}

Result

  • See result in example.com/status.json
  • All requests that do not have $stats_group, are displayed in the group: other
{
    "stats_start": 1397069333.819,
    "example.com": {
        "cache": {
            "expired": 812415,
            "updating": 1526,
            "miss": 13276642,
            "hit": 24260426,
            "stale": 162
        },
        "upstream_requests_total": 14090608,
        "request_time": {
            "sum": 803899.9091289
        },
        "status": {
            "3xx": 2,
            "4xx": 238784,
            "5xx": 18619,
            "2xx": 38109854
        },
        "upstream_resp_time_sum": 636378.56698991,
        "requests_total": 38367259
    },
    "sub.example.com": {
        "cache": {
            "expired": 911851,
            "updating": 1187,
            "miss": 1742453,
            "hit": 61705830,
            "stale": 1061
        },
        "upstream_requests_total": 2657158,
        "request_time": {
            "sum": 1607474.1242547
        },
        "status": {
            "3xx": 538834,
            "4xx": 1080163,
            "5xx": 1693,
            "2xx": 62743490
        },
        "upstream_resp_time_sum":105318.85199993,
        "requests_total": 64364180
    },
    "other": {
        "status": {
            "4xx":4169
        },
        "requests_total": 4169,
        "request_time": {
            "sum": 51761.917998552
        }
    }
}

See Also

ngx_stats's People

Contributors

ciceroverneck avatar dmyerscough avatar anson2048 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.