nginxのためのZeroMQロガーモジュール
ZeroMQ, zero-em-queue, はメッセージ交換のためのプロトコルです。任意の言語あるいはプラットフォームを使ってimproc, IPC, TCP, TPIC あるいはマルチキャストを経由して通信することが簡単です。非同期で小さなライブラリのみを必要とします。
注意
このモジュールはnginxのソースと一緒に配布されません。 インストレーションの説明を見てください。
このモジュールは既にプロダクションの準備ができています。
これはZeroMQ ライブラリと統合されたnginxロガーモジュールです。
nginx-log-zmq は1つ以上の異なるエンドポイントに対して1つ以上のPUB/SUB購買者のためにデータを記録する非常に効果的な方法を提供します。これはデータの収集および処理にとても便利でしょう。
The message format can be the same as the tradicional log format which gives a interesting way to tail
data via the network or exploring other text formats like JSON. 伝統的なログと同様に、各リクエスト毎に更新されるnginx変数を使うことができます。
全てのメッセージは非同期的に送信され、通常のnginxサーバの挙動をブロックしません。予想通りに接続はネットワークの障害に対して回復力があります。
http {
# simple message to an IPC endpoint with 4 threads and 1000 queue elements
log_zmq_server main "/tmp/main.ipc" ipc 4 1000;
log_zmq_endpoint main "/topic/";
log_zmq_format main '{"remote_addr":"$remote_addr"}'
# send messages to a subscriber listening at 127.0.0.1:5556
log_zmq_server secondary 127.0.0.1:5556 tcp 4 1000;
# set secondary endpoint
log_zmq_endpoint secondary "/endpoint/";
# set format using multiline
log_zmq_format secondary '{"request_uri":"$request_uri",'
' "status":"$status"}';
server {
location /status {
# mute all messages from log_zmq for this location
log_zmq_off all;
}
location /endpoint {
# mute main messages from log_zmq for this location
log_zmq_off main;
}
}
}
構文: | log_zmq_server <definition_name> <address> <ipc|tcp> <threads> <queue size> |
---|---|
デフォルト: | no |
コンテキスト: | http |
接続するサーバ(PUB/SUB サブスクライバ)を設定します。
以下のオプションが必要です:
definition_name <name> - nginxがこのロガーのインスタンスを識別するために使用する名前。
address <path>|<ipaddress>:<port> - サブスクライバのアドレス。IPCプロトコルを使う場合は、unixソケットのための<path>
を指定する必要があります。TCPプロトコルを使う場合は、ZeroMQサブスクライバがlistenする<ipaddress>
と <port>
を指定する必要があります。
protocol <ipc|tcp> - 通信のために使われるプロトコル。
threads <integer> - 使用するI/Oスレッドの数。
queue_size <integer> - メッセージが送信されるのを待つための最大キューサイズ。
構文: | log_zmq_endpoint <definition_name> “<topic>” |
---|---|
デフォルト: | no |
コンテキスト: | http |
Configures the topic for the ZeroMQ messages.
definition_name <name> - nginxがこのロガーのインスタンスを識別するために使用する名前。
topic <topic> - メッセージのためのトピック。これは各送信されるメッセージの前に追加される文字列(nginxの変数も可能です)です。例えば、メッセージ “hello” を “/talk:” トピックに送信する場合、メッセージは “/talk:hello” として終了するでしょう。
例:
http {
log_zmq_server main "/tmp/example.ipc" 4 1000;
# send a message for for an topic based on response status
log_zmq_endpoint main "/remote/$status";
}
構文: | log_zmq_format <definition_name> “<format>” |
---|---|
デフォルト: | no |
コンテキスト: | http |
ZeroMQ メッセージのフォーマットを設定します。
definition_name <name> - nginxがこのロガーのインスタンスを識別するために使用する名前。
format <format> - メッセージのためのフォーマット。これは PUB/SUB サブスクライバに送信される実際のメッセージを定義します。標準のlog_format ディレクティブと同じルールに従います。ここでnginx変数を使うことが可能で、複数の行にまたがって分割することもできます。
http {
log_zmq_format main '{"line1": value,'
' "line2": value}';
}
構文: | log_zmq_off<definition_name>|all |
---|---|
デフォルト: | no |
コンテキスト: | 場所 |
現在のコンテキストでの ZeroMQ ロギングを止める。
definition_name <name> 無音にするロガーのインスタンスの名前。特別なall
の名前が使われた場合、全てのロガーのインスタンスが無音になります。
このモジュールを含むnginxバイナリをビルドするには:
./configure --prefix=/usr/local/nginx --add-module=/path/to/nginx-log-zmq
make
make install
nginxの以下のバージョンがこのモジュールで動作すると知られています:
The MIT License (MIT)
Copyright (c) 2014 SAPO - PT Comunicações S.A
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.