Accept cookies for analytics, social media, and advertising, or learn more and adjust your preferences. These cookies are on by default for visitors outside the UK and EEA. Privacy Notice.
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 <on|off> |
---|---|
デフォルト: | off |
コンテキスト: | http, stream |
構文: | 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 <seconds> |
---|---|
デフォルト: | 60 |
コンテキスト: | http, stream |
レポートの間隔を指定します。デフォルトは60秒です。
構文: | accounting_interval <on|off> |
---|---|
デフォルト: | off |
コンテキスト: | http, stream |
レポート間隔を通常の時間から20%ランダムにずらします。
構文: | accounting_id <accounting_id> |
---|---|
デフォルト: | “default” |
コンテキスト: | http, stream, server, location, if in location |
ユーザ定義変数によって accounting_id 文字列を設定します。この文字列は、リクエスト/セッションを集約するメトリクスを決定するために使われます。