NRDOT コレクター (推奨) またはOpenTelemetry Collector Contrib を使用してセルフホスト NGINX サーバーをOpenTelemetryで監視し、パフォーマンス メトリクスとテレメトリーデータをNew Relicに送信します。
あなたが始める前に
以下のものを用意してください:
有効なNew Relicライセンスキー
HTTPスタブステータスモジュールを有効にしたNGINX
Linux ホストにインストールされている次のいずれかのコレクター:
Linux ホストから次のネットワーク アクセス:
- NGINX HTTP スタブ ステータス エンドポイント
- New RelicのOTLP エンドポイント
NGINXの監視を設定する
お好みのコレクターを選択し、以下の手順に従ってください。
NRDOT コレクターを使用して NGINX サーバーを監視できます。 NRDOT コレクターは、 New Relic固有のコンポーネントを含む事前設定されたディストリビューションです。
NRDOT コレクターをインストールして構成するには、次の手順に従います。
ヒント
検証手順のいずれかが失敗した場合は、続行する前に不足しているコンポーネントをインストールしてください。NRDOT コレクターのインストールについてサポートが必要ですか? nrdot -collectors-releases リポジトリのインストレーション セクションを確認してください。
インストレーション使用時 export collector_distro="nrdot-collector"
NGINX スタブ ステータス エンドポイントからメトリクスを収集し、 New Relicに送信するように NRDOT コレクターを設定します。
重要
監視方法を選択してください:
NGINX-only 監視 (このガイド): NGINX Web サーバーのパフォーマンスとメトリクスだけを監視します
完全なサーバー監視: NGINX とサーバー全体 (CPU 使用率、メモリ、ディスク容量、システム ログ) を監視します。
NGINX だけでなくサーバー全体を監視したい場合は、代わりに NRDOT コレクターのデフォルト設定を使用し、それに NGINX レシーバー設定を追加します。
設定ファイル/etc/nrdot-collector/nginx-config.yamlを作成します。
receivers: nginx: endpoint: <YOUR_STUB_STATUS_ENDPOINT> # Replace with your stub status URL collection_interval: 30s # How often to collect metrics metrics: nginx.requests: enabled: true nginx.connections_accepted: enabled: true nginx.connections_handled: enabled: true nginx.connections_current: enabled: true
processors: # Detect system information resourcedetection: detectors: [system] system: resource_attributes: host.name: enabled: false host.id: enabled: true
# Add NGINX-specific identification resource/nginx: attributes: - key: nginx.server.endpoint value: "<YOUR_STUB_STATUS_ENDPOINT>" # Replace with your endpoint action: upsert - key: nginx.deployment.name value: "<DEPLOYMENT_NAME>" # Replace with your deployment name action: upsert # Batch metrics for efficient sending batch: timeout: 30s send_batch_size: 1024
# Transform metrics for better display in New Relic transform/nginx_metrics: metric_statements: - context: resource statements: # Customize the display name as needed for your New Relic dashboard - set(attributes["nginx.display.name"], Concat(["server", attributes["nginx.deployment.name"]], ":")) transform/metadata_nullify: metric_statements: - context: metric statements: - set(description, "") - set(unit, "")
exporters: otlp_http: endpoint: ${env:YOUR_NEWRELIC_OTLP_ENDPOINT} headers: api-key: ${env:YOUR_NEW_RELIC_LICENSE_KEY}
service: pipelines: metrics/nginx: receivers: [nginx] processors: [resourcedetection, resource/nginx, batch, transform/nginx_metrics, transform/metadata_nullify] exporters: [otlp_http]設定パラメーター
次の表では、キー設定について説明します。
パラメータ | 説明 |
|---|---|
| NGINXスタブのステータスエンドポイント(例:
)に置き換えてください。 |
| このNGINXサーバーの一意のデプロイメント名に置き換えてください(例:
、
、
)。 |
| メトリクスを収集する間隔 (秒単位)。 デフォルト値は
|
| バッチ処理されたメトリクスを送信する前に待機するタイムアウト時間(秒)。デフォルト値は
|
| 送信前にバッチ処理するメトリクスの数。デフォルト値は
|
NGINX 構成ファイルを使用し、OTLP エンドポイントを設定するように NRDOT コレクター設定を更新します。
New Relicリージョンに基づいて OTLP エンドポイントを決定します。 お住まいの地域でエンドポイントとサポートされているポートの完全なリストについては、「エンドポイント、ポート、およびプロトコルの構成」を参照してください。
重要
ライセンスキーは、インストール中にすでに/etc/nrdot-collector/nrdot-collector.confに設定されています。 更新する必要があるのは、構成ファイルのパスと OTLP エンドポイントのみです。
コレクター設定ファイルを更新します。
$export collector_distro="nrdot-collector"$export otlp_endpoint="<YOUR_NEWRELIC_OTLP_ENDPOINT>" # Replace with your region's endpoint$
$# Update the config file path to point to nginx-config.yaml$sudo sed -i 's|OTELCOL_OPTIONS="--config=/etc/nrdot-collector/config.yaml"|OTELCOL_OPTIONS="--config=/etc/nrdot-collector/nginx-config.yaml"|' /etc/${collector_distro}/${collector_distro}.conf$
$# Add the OTLP endpoint$echo "OTEL_EXPORTER_OTLP_ENDPOINT=${otlp_endpoint}" | sudo tee -a /etc/${collector_distro}/${collector_distro}.conf > /dev/nullメトリクスに加えて、NGINX のアクセスとエラー ログをNew Relicに送信して、包括的な監視とトラブルシューティングを行うことができます。 これらのログはコア NGINX メトリクスを補完し、詳細なリクエスト レベルのインサイトを提供します。
ヒント
基本的な NGINX メトリクスのみが必要で、詳細なリクエスト ログが必要ない場合は、この手順をスキップしてください。
NGINXでJSON形式のログを出力するように設定するには、NGINXの設定(
/etc/nginx/nginx.conf)に以下を追加します。http {# JSON log format for better parsinglog_format json_combined escape=json'{''"time":"$time_local",''"remote_addr":"$remote_addr",''"request":"$request",''"status":$status,''"bytes_sent":$body_bytes_sent,''"request_time":$request_time,''"referer":"$http_referer",''"user_agent":"$http_user_agent"''}';# Use the JSON format for access logsaccess_log /var/log/nginx/access.log json_combined;error_log /var/log/nginx/error.log warn;# Your existing configuration...}変更を適用するには、NGINX をリロードします。
bash$sudo nginx -t && sudo nginx -s reloadログ転送用にコレクターを設定するには、
/etc/nrdot-collector/nginx-config.yamlに次のセクションを追加します。receivers:# Your existing nginx receiver...nginx:# existing configuration...# Add log receiversfilelog/nginx_access:include:- /var/log/nginx/access.logfilelog/nginx_error:include:- /var/log/nginx/error.logprocessors:# Your existing processors...# Add log processortransform/nginx_access_logs:log_statements:- context: resourcestatements:- set(attributes["nginx.display.name"], Concat(["server", attributes["nginx.deployment.name"]], ":"))- set(attributes["logtype"], "nginx")transform/nginx_error_logs:log_statements:- context: resourcestatements:- set(attributes["nginx.display.name"], Concat(["server", attributes["nginx.deployment.name"]], ":"))- set(attributes["logtype"], "nginx-error")service:pipelines:# Your existing metrics pipeline...# Add log pipelineslogs/nginx-access:receivers: [filelog/nginx_access]processors: [resource/nginx, batch, transform/nginx_access_logs]exporters: [otlp_http]logs/nginx-error:receivers: [filelog/nginx_error]processors: [resource/nginx, batch, transform/nginx_error_logs]exporters: [otlp_http]権限を設定し、設定を適用します。コレクターが NGINX ログ ファイルを読み取ることを許可します。
bash$# Add collector user to adm group (has read access to logs)$sudo usermod -a -G adm nrdot-collector$$# Ensure log files are readable$sudo chmod 644 /var/log/nginx/access.log$sudo chmod 644 /var/log/nginx/error.log
すべて設定が完了したら、NRDOTコレクターを起動して、データがNew Relicに流れていることを確認してください。
コレクターを起動します。
- 設定の変更を適用します。
bash$sudo systemctl daemon-reload$sudo systemctl restart nrdot-collector.service- サービスが実行されていることを確認します。
bash$sudo systemctl status nrdot-collector.service期待される出力:
Active: active (running)(最近のエラーなし)データ収集を確認する:
- 起動ログを確認します。
bash$sudo journalctl -u nrdot-collector.service -n 20- テスト トラフィックを生成します (メトリクスを作成するため)。
bash$# Make a few requests to your NGINX server$curl http://localhost初期データが New Relic に表示されるまで待ってから、 NGINX ダッシュボードにアクセスしてデータ収集を確認します。
ヒント
検証手順のいずれかが失敗した場合は、続行する前に不足しているコンポーネントをインストールしてください。コレクターのインストールについてサポートが必要ですか? OpenTelemetry Collectorインストレーション ガイドを確認してください。
NGINX スタブ ステータス エンドポイントからメトリクスを取得し、 New Relicに送信するようにOpenTelemetry Collector設定します。
重要
編集前に:既存の設定をバックアップしてください。 sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.backup
コレクター設定ファイル(通常は/etc/otelcol-contrib/config.yaml )を編集し、以下のセクションを追加してください。既にレシーバー、プロセッサー、またはエクスポーターのセクションがある場合は、これらを既存の設定に統合してください。
NGINXレシーバーの設定:
receivers:nginx:endpoint: <YOUR_STUB_STATUS_ENDPOINT> # Replace with your stub status URLcollection_interval: 30s # How often to collect metricsmetrics:nginx.requests:enabled: truenginx.connections_accepted:enabled: truenginx.connections_handled:enabled: truenginx.connections_current:enabled: trueメタデータとバッチ処理用にプロセッサを設定する:
processors:# Detect system informationresourcedetection:detectors: [system]system:resource_attributes:host.name:enabled: falsehost.id:enabled: true# Add NGINX-specific identificationresource/nginx:attributes:- key: nginx.server.endpointvalue: "<YOUR_STUB_STATUS_ENDPOINT>" # Replace with your endpointaction: upsert- key: nginx.deployment.namevalue: "<DEPLOYMENT_NAME>" # Replace with your deployment nameaction: upsert# Batch metrics for efficient sendingbatch:timeout: 30ssend_batch_size: 1024# Transform metrics for better display in New Relictransform/nginx_metrics:metric_statements:- context: resourcestatements:# Customize the display name as needed for your New Relic dashboard- set(attributes["nginx.display.name"], Concat(["server", attributes["nginx.deployment.name"]], ":"))transform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")New Relicエクスポーターの設定:
exporters:# Send metrics to New Relic via OTLPotlp_http:endpoint: ${env:YOUR_NEWRELIC_OTLP_ENDPOINT}headers:api-key: ${env:YOUR_NEW_RELIC_LICENSE_KEY}すべてをパイプラインで接続する:
service:pipelines:metrics/nginx:receivers: [nginx]processors: [resourcedetection, resource/nginx, batch, transform/nginx_metrics, transform/metadata_nullify]exporters: [otlp_http]設定パラメーター
次の表では、キー設定について説明します。
パラメータ
説明
<YOUR_STUB_STATUS_ENDPOINT>NGINXスタブのステータスエンドポイント(例:
http://127.0.0.1/basic_status)に置き換えてください。
<DEPLOYMENT_NAME>このNGINXサーバーの一意のデプロイメント名に置き換えてください(例:
production-web-01、
staging-api、
prod-lb-01)。
collection_intervalメトリクスを収集する間隔 (秒単位)。 デフォルト値は
30stimeoutバッチ処理されたメトリクスを送信する前に待機するタイムアウト時間(秒)。デフォルト値は
30ssend_batch_size送信前にバッチ処理するメトリクスの数。デフォルト値は
1024
OpenTelemetry Collector が New Relic アカウントにデータを送信できるように、安全な認証を構成します。この手順では、資格情報を安全に保つために環境変数を設定します。
New Relicの認証情報を取得してください:
- ライセンスキー: APIキーUIページからライセンスキーを取得します。
- OTLP エンドポイント: New Relic OTLP エンドポイントから地域のエンドポイントを使用します
認証情報を設定します。
- systemd オーバーライド ディレクトリを作成します。
bash$sudo mkdir -p /etc/systemd/system/otelcol-contrib.service.d- 環境設定ファイルを作成します。
bash$cat <<EOF | sudo tee /etc/systemd/system/otelcol-contrib.service.d/environment.conf$[Service]$Environment="NEWRELIC_OTLP_ENDPOINT=<YOUR_NEWRELIC_OTLP_ENDPOINT>" # Replace with your region's endpoint$Environment="NEWRELIC_LICENSE_KEY=YOUR_NEW_RELIC_LICENSE_KEY"$EOF
メトリクスに加えて、NGINXのアクセスログとエラーログをNew Relicに送信することで、包括的な監視とトラブルシューティングを行うことができます。これらのログはコア NGINX メトリクスを補完し、詳細なリクエスト レベルのインサイトを提供します。
ヒント
基本的な NGINX メトリクスのみが必要で、詳細なリクエスト ログが必要ない場合は、この手順をスキップしてください。
NGINXでJSON形式のログを出力するように設定するには、NGINXの設定(
/etc/nginx/nginx.conf)に以下を追加します。http {# JSON log format for better parsinglog_format json_combined escape=json'{''"time":"$time_local",''"remote_addr":"$remote_addr",''"request":"$request",''"status":$status,''"bytes_sent":$body_bytes_sent,''"request_time":$request_time,''"referer":"$http_referer",''"user_agent":"$http_user_agent"''}';# Use the JSON format for access logsaccess_log /var/log/nginx/access.log json_combined;error_log /var/log/nginx/error.log warn;# Your existing configuration...}変更を適用するには、NGINX をリロードします。
bash$sudo nginx -t && sudo nginx -s reloadログ転送用にコレクターを設定するには、
/etc/otelcol-contrib/config.yamlに次のセクションを追加します。receivers:# Your existing nginx receiver...nginx:# existing configuration...# Add log receiversfilelog/nginx_access:include:- /var/log/nginx/access.logfilelog/nginx_error:include:- /var/log/nginx/error.logprocessors:# Your existing processors...# Add log processortransform/nginx_access_logs:log_statements:- context: resourcestatements:- set(attributes["nginx.display.name"], Concat(["server", attributes["nginx.deployment.name"]], ":"))- set(attributes["logtype"], "nginx")transform/nginx_error_logs:log_statements:- context: resourcestatements:- set(attributes["nginx.display.name"], Concat(["server", attributes["nginx.deployment.name"]], ":"))- set(attributes["logtype"], "nginx-error")service:pipelines:# Your existing metrics pipeline...# Add log pipelineslogs/nginx-access:receivers: [filelog/nginx_access]processors: [resource/nginx, batch, transform/nginx_access_logs]exporters: [otlp_http]logs/nginx-error:receivers: [filelog/nginx_error]processors: [resource/nginx, batch, transform/nginx_error_logs]exporters: [otlp_http]権限を設定し、設定を適用します。コレクターが NGINX ログ ファイルを読み取ることを許可します。
bash$# Add collector user to adm group (has read access to logs)$sudo usermod -a -G adm otelcol-contrib$$# Ensure log files are readable$sudo chmod 644 /var/log/nginx/access.log$sudo chmod 644 /var/log/nginx/error.log
すべての設定が完了したら、OpenTelemetry Collector を起動し、データが New Relic に流れていることを確認します。
コレクターを起動します。
- 設定の変更を適用します。
bash$sudo systemctl daemon-reload$sudo systemctl restart otelcol-contrib.service- サービスが実行されていることを確認します。
bash$sudo systemctl status otelcol-contrib.service期待される出力:
Active: active (running)(最近のエラーなし)データ収集を確認する:
- 起動ログを確認します。
bash$sudo journalctl -u otelcol-contrib.service -n 20- テスト トラフィックを生成します (メトリクスを作成するため)。
bash$# Make a few requests to your NGINX server$curl http://localhost初期データが New Relic に表示されるまで待ってから、 NGINX ダッシュボードにアクセスしてデータ収集を確認します。
New Relic でデータを表示する
セットアップが完了し、データが流れるようになると、 New Relicダッシュボードで NGINX メトリクスにアクセスし、カスタム アラートを作成できます。
ダッシュボードへのアクセス、NRQL を使用したデータのクエリ、アラートの作成に関する詳細な手順については、 「NGINX データの検索とクエリ」を参照してください。
トラブルシューティング
セットアップ中に問題が発生した場合は、このトラブルシューティング ガイドを使用して一般的な問題を診断し、解決してください。
404 Not Found が表示される場合:
$curl http://<NGINX_SERVER_IP>:<YOUR_LOCAL_PORT>/nginx_status解決策:
- ロケーションパスがリクエストURLと一致していることを確認してください
- 設定が正しいサーバーブロックに追加されたことを確認します
sudo nginx -T | grep -A5 nginx_statusを実行して設定が読み込まれていることを確認します
403 Forbidden が表示される:
- 正しいサーバーIPアドレスからテストしていることを確認してください。
<NGINX_SERVER_IP> - NGINX 設定の
allow/denyディレクティブを確認してください - 他のアクセス制限によってリクエストがブロックされていないことを確認します
接続拒否:
- NGINX が実行されているかどうかを確認します。
sudo systemctl status nginx - 設定したポートがブロックされていないことを確認してください。
sudo netstat -tlnp | grep :<YOUR_LOCAL_PORT> - 該当する場合はファイアウォールルールを確認してください
サービスステータスを確認します:
$sudo systemctl status ${collector_distro}.service$sudo journalctl -u ${collector_distro}.service -n 50一般的な原因と修正方法:
- YAML構文エラー - インデントと構文の問題を修正
- 環境変数が不足しています - 環境ファイルに認証情報が設定されていることを確認してください。
- ファイル権限の問題 - 実行
sudo chown ${collector_distro}:${collector_distro} /etc/${collector_distro}/config.yaml - 無効なエンドポイント URL - NGINX エンドポイントと New Relic OTLP エンドポイントを確認してください
- コンポーネントの設定が不足しています - サービスパイプラインセクションで参照されているすべてのレシーバー、プロセッサー、およびエクスポーターが、上記のそれぞれの設定セクションで実際に定義されていることを確認してください。
修正後に再起動します:
$sudo systemctl restart ${collector_distro}.serviceステップバイステップの診断:
NGINX スタブ ステータスが機能していることを確認します。
bash$curl http://<NGINX_SERVER_IP>:<YOUR_LOCAL_PORT>/nginx_status接続統計を返す必要があります。
Collectorが実行中であり正常であることを確認します。
bash$sudo systemctl status ${collector_distro}.service$sudo journalctl -u ${collector_distro} -n 20ログには、 OpenTelemetry Collectorの設定または実行時の問題がある場合の詳細なコンテキストが提供されます。
NRQL でデータを確認します。
FROM Metric SELECT * WHERE nginx.deployment.name LIKE '%production%' LIMIT 1
New Relic にログが表示されない:
$# Check Collector logs for file errors$sudo journalctl -u ${collector_distro} -f | grep -i "filelog\|error"よくある問題:
- ファイル権限エラー - コレクターをadmグループに追加してください:
sudo usermod -a -G adm ${collector_distro} - ファイルパスが間違っています - 設定ファイル内のログファイルの場所を確認してください
次のステップ
データについて詳しくはこちらをご覧ください:
- NGINX データを見つけて書きます- ダッシュボードにアクセスし、カスタム書き込みを作成し、アラートを設定します
- NGINX OpenTelemetry のメトリクスと属性のリファレンス- 説明と例を含む完全なメトリクス リファレンス
- NGINX OpenTelemetry概要- 収集されたメトリクス、プロパティ、およびユースケースを理解する
関連する監視を調べます:
- OpenTelemetryを使用した NGINX Plus のモニター- 商用 NGINX Plus デプロイメント用
- Kubernetes上の NGINX を監視する- コンテナ化された環境の場合