トラフィックの課金

traffic-accounting-nginx-moduleはアプリケーション リクエストのトラフィック メトリクス/ステータスを監視する費用対効果の高い解決策です。

使い方?

モジュールはコンテキスト内にaccounting_idで識別されるメトリクスのリストを保持します。

新しいリクエストがサーバに到達すると、モジュールは accounting_id を探し、統計を計算し、それらを accounting_id によって対応するメトリクスに集約します。

(間隔によって定義される)各期間ごとに、タイマー イベントが引き起こされ、それらのメトリクスはローテ―トされて、ログファイルに出力されるか、リモート ログ サーバに送信されます。

使い方

nginx 1.9.11 から、./configure コマンドライン上で、--add-module=PATH の代わりに--add-dynamic-module=PATH オプション を使って動的モジュールとしてこのモジュールをコンパイルすることができます。そして、load_module (httsp://nginx.org/en/docs/ngx_core_module.html#load_module) ディレクティブを使ってnginx.conf の中でモジュールを明示的にロードすることができます。

load_module modules/ngx_http_accounting_module.so; load_module modules/ngx_stream_accounting_module.so;

設定例

http {
    accounting      on;
    accounting_log  logs/http-accounting.log;

    server {
        ...

        accounting_id  $http_host;  # set accounting_id string by variable

        location / {
            ...

            accounting_id  "accounting_id_str";  # set accounting_id string by location
        }

        location /api {
            accounting_id  "API_PC";   # for pc

            if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
                accounting_id  "API_MOBILE";   # for mobile
            }

            ...
        }
    }
}

ディレクティブ

accounting

構文:accounting <on|off>
デフォルト:off
コンテキスト:http, stream

accounting_log

構文:accounting_log </path/to/accounting_log> [level]
デフォルト:-
コンテキスト:http, stream

error_log と同じ種類のログ ターゲットをサポートします: ローカルファイル、syslog、stderrおよびメモリ。error_log <https://nginx.org/en/docs/ngx_core_module.html#error_log>の概要を参照してください。

accounting_interval

構文:accounting_interval <seconds>
デフォルト:60
コンテキスト:http, stream

レポートの間隔を指定します。デフォルトは60秒です。

accounting_perturb

構文:accounting_interval <on|off>
デフォルト:off
コンテキスト:http, stream

レポート間隔を通常の時間から20%ランダムにずらします。

accounting_id

構文:accounting_id <accounting_id>
デフォルト:“default”
コンテキスト:http, stream, server, location, if in location

ユーザ定義変数によって accounting_id 文字列を設定します。この文字列は、リクエスト/セッションを集約するメトリクスを決定するために使われます。

著者

Lax/traffic-accounting-nginx-module#authorsを見てください

これらも見てください

段階的なセットアップをここで見つけることができます。

詳細については、githubを参照してください。

inserted by FC2 system