Giter Site home page Giter Site logo

allenluce / ngx_http_accounting_module Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lax/traffic-accounting-nginx-module

0.0 3.0 0.0 57 KB

Add traffic stat function to nginx. Useful for http accounting based on nginx configuration logic ( server / location / or anything else).

License: GNU General Public License v3.0

C 89.34% C++ 10.66%

ngx_http_accounting_module's Introduction

Installation

Configure ngx_http_accounting_module as nginx module with --add-module when build nginx.

cd /path/to/nginx-src/

git clone https://github.com/Lax/ngx_http_accounting_module.git -b v1.0

./configure --add-module=ngx_http_accounting_module

make && make install

Configuration

Edit your nginx.conf.

Example:

http{
    # turn on accounting function
    http_accounting  on;
    ...
    server {
        server_name example.com;

        # set accounting_id based on server, use variable
        http_accounting_id  $http_host;
        ...
        location / {
            # set accounting_id based on location
            http_accounting_id  accounting_id_str;
            ...
        }
    }
}

Directives

http_accounting

syntax: http_accounting on | off

default: http_accounting off

context: http

http_accounting_id

syntax: http_accounting_id <accounting_id>

default: http_accounting_id default

content: server, location

Specifies current request belongs to which accounting_id.

This directive was first introduced in the v0.1 release, and can use variable in v1.0 and above.

http_accounting_interval

syntax: http_accounting_interval

default: http_accounting_interval 60

context: http

Specifies the reporting interval. Defaults to 60 seconds.

http_accounting_perturb

syntax: http_accounting_perturb on | off

default: http_accounting_perturb off

context: http

Randomly staggers the reporting interval by 20% from the usual time.

Usage

This module writes statistics to syslog. You should edit your syslog configuration.

For sample configuration / utils, see: Lax/ngx_http_accounting_module-utils

Sample syslog output

Apr  8 11:19:46 localhost NgxAccounting: pid:8555|from:1428463159|to:1428463186|accounting_id:default|requests:10|bytes_in:1400|bytes_out:223062|latency_ms:1873|upstream_latency_ms:1873|200:9|302:1

The output contains a list of k/v for the accounting metrics, in the sequence of:

key meaning
pid pid of nginx worker process
from / to metric was collected between these timestamps
accounting_id identify for the accounting unit, you name it with http_accounting_id directive
requests count of total requests processed
bytes_in total bytes receiverd by the server
bytes_out total bytes send out by the server
latency_ms a sum of $request_time, in millisecond
upstream_latency_ms a sum of $upstream_response_time, in millisecond
200 / 302 / 400 / 404 / 500 ... count of requests which response is with http code 200/302/400/404/500, etc

Branches

  • master : new feathers
  • v2-freeze-20110526 : works with nginx version(0.7.xx, 0.8.xx), nginx 0.9 is not tested. didn't work with nginx above 1.0.x.

Author

Liu Lantao Github

License

GPLv3

ngx_http_accounting_module's People

Contributors

lax avatar splitice avatar steinnes avatar

Watchers

James Cloos avatar Allen Luce 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.