OpenTelemetryを使用してセルフホスト型HAProxyロードバランサーをモニターし、パフォーマンスメトリクスとテレメトリーデータをNew Relicに送信します。
3つのコレクターオプションから選択できます:
- NRDOT: New Relic Distribution of OpenTelemetry(推奨 — ガイド付きインストールによる自動化)
- OTel Collector Contrib:haproxyreceiverを備えた標準のOpenTelemetry Collector
- Prometheus Receiver: すでにHAProxyの組み込みPrometheusエンドポイントを使用している環境向け(HAProxy 2.0+)
ヒント
現在nri-haproxyを使用しており、OpenTelemetryに切り替えたい場合は、レガシーインテグレーションを無効にして、以下のセットアップ手順に従ってください。OTelベースのアプローチは、より豊富なメタデータ(フロントエンド/バックエンド/サーバーごとにhaproxy.proxy_name、haproxy.service_name)を備えたディメンショナルメトリクスを提供します。
あなたが始める前に
以下のものを用意してください:
有効なNew Relicライセンスキー
statsエンドポイントが有効になっているHAProxyバージョン2.0以降(statsをサポートする任意のバージョン;Prometheusパスには2.0+が必要です)
Linux ホストにインストールされている次のいずれかのコレクター:
Linux ホストから次のネットワーク アクセス:
- HAProxy statsエンドポイント(通常は
http://localhost:8404/stats) - New RelicのOTLP エンドポイント
- HAProxy statsエンドポイント(通常は
HAProxy監視の設定
お好みのコレクターを選択し、以下の手順に従ってください。
NRDOTコレクターは、haproxyreceiverとNew Relic固有のコンポーネントを含む事前設定されたディストリビューションです。
NRDOTコレクターをインストールして設定するには、次の手順に従います:
ヒント
検証手順のいずれかが失敗した場合は、続行する前に不足しているコンポーネントをインストールしてください。NRDOT コレクターのインストールについてサポートが必要ですか? nrdot -collectors-releases リポジトリのインストレーション セクションを確認してください。
インストレーション使用時 export collector_distro="nrdot-collector"
HAProxy統計エンドポイントをまだ有効にしていない場合は、haproxy.cfgに次を追加します:
frontend stats bind *:8404 stats enable stats uri /stats stats refresh 10sHAProxyをリロードして設定を適用します:
$sudo systemctl reload haproxystatsエンドポイントにアクセスできることを確認します:
$curl -s http://localhost:8404/statsHAProxyの統計情報を含むHTML出力が表示されるはずです。
HAProxy statsエンドポイントからメトリクスを収集し、New Relicに送信するようにNRDOTコレクターを設定します。
重要
監視方法を選択してください:
HAProxyのみの監視(このガイド):HAProxyロードバランサーのパフォーマンスとメトリクスのみをモニターします
完全なサーバー監視:HAProxyに加えて、サーバー全体(CPU使用率、メモリ、ディスク容量、システムログ)をモニターします。
HAProxyだけでなくサーバー全体をモニターする場合は、代わりにNRDOTコレクターのデフォルト設定を使用し、それにHAProxyレシーバーの設定を追加してください。
設定ファイル/etc/nrdot-collector/haproxy-config.yamlを作成します。
receivers: haproxy: endpoint: http://localhost:8404/stats collection_interval: 15s
processors: resourcedetection: detectors: [system] system: resource_attributes: host.name: enabled: true host.id: enabled: true
batch:
exporters: otlphttp: endpoint: ${env:OTEL_EXPORTER_OTLP_ENDPOINT} headers: api-key: ${env:NEW_RELIC_LICENSE_KEY}
service: pipelines: metrics: receivers: [haproxy] processors: [resourcedetection, batch] exporters: [otlphttp]この設定は、15秒間隔で17のデフォルトメトリクスをすべて収集します。haproxyreceiverは、各メトリクスにhaproxy.proxy_name、haproxy.service_name、およびhaproxy.addr属性を自動的に追加します。
より深い可視性のために追加のメトリクス(合計27:デフォルト17 + オプション10)を有効にするには、オプションのメトリクスを追加します:
receivers: haproxy: endpoint: http://localhost:8404/stats collection_interval: 15s metrics: haproxy.connections.average_time: enabled: true haproxy.requests.average_time: enabled: true haproxy.responses.average_time: enabled: true haproxy.active: enabled: true haproxy.backup: enabled: true haproxy.downtime: enabled: true haproxy.failed_checks: enabled: true haproxy.weight: enabled: true haproxy.sessions.total: enabled: true haproxy.connections.total: enabled: trueヒント
以下の最適化された設定により、包括的モードと比較してデータの取り込みが約85%削減されます。すべてのダッシュボードとゴールデンメトリクスは引き続き完全に機能します。
データの取り込み量を減らすには、60秒の間隔を使用し、最適化プロセッサを追加します:
receivers: haproxy: endpoint: http://localhost:8404/stats collection_interval: 60s
processors: resourcedetection: detectors: [system] system: resource_attributes: host.name: enabled: true host.id: enabled: true
transform/metadata_nullify: metric_statements: - context: metric statements: - set(description, "") where description != "" - set(unit, "") where unit != ""
resource/remove_attributes: attributes: - key: os.description action: delete - key: telemetry.sdk.version action: delete - key: telemetry.sdk.language action: delete - key: telemetry.sdk.name action: delete - key: host.arch action: delete
batch: send_batch_size: 2048 timeout: 30s
exporters: otlphttp: endpoint: ${env:OTEL_EXPORTER_OTLP_ENDPOINT} headers: api-key: ${env:NEW_RELIC_LICENSE_KEY}
service: pipelines: metrics: receivers: [haproxy] processors: [resourcedetection, transform/metadata_nullify, resource/remove_attributes, batch] exporters: [otlphttp]設定パラメーター
パラメータ | 説明 |
|---|---|
| HAProxy statsエンドポイントのURLに置き換えます(例:
) |
| メトリクス収集の間隔。詳細については
、取り込み量を減らすには
|
HAProxy設定ファイルを使用し、OTLPエンドポイントを設定するようにNRDOTコレクター設定を更新します。
OTLPエンドポイントについては、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 haproxy-config.yaml$sudo sed -i 's|OTELCOL_OPTIONS="--config=/etc/nrdot-collector/config.yaml"|OTELCOL_OPTIONS="--config=/etc/nrdot-collector/haproxy-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/nullNRDOTコレクターサービスを開始(または再起動)します:
$sudo systemctl daemon-reload$sudo systemctl restart nrdot-collectorサービスステータスを確認します。
$sudo systemctl status nrdot-collector設定エラーがないかログを確認します:
$sudo journalctl -u nrdot-collector -n 50 --no-pagerデータが流れるまで2~3分待ってから、New Relicで確認します:
FROM Metric SELECT uniques(metricName)WHERE metricName LIKE 'haproxy.%'SINCE 10 minutes ago17個(デフォルト)または27個(すべてのメトリクスが有効)の一意のHAProxyメトリクス名が表示されるはずです。次元属性を確認します:
FROM Metric SELECT latest(haproxy.sessions.count)FACET haproxy.proxy_name, haproxy.service_nameSINCE 5 minutes agoOpenTelemetry Collector Contribディストリビューションとhaproxyreceiverを使用して、HAProxyサーバーをモニターできます。haproxyreceiverはHAProxyのCSV statsエンドポイントをスクレイピングし、フロントエンドごと、バックエンドごと、およびサーバーごとの粒度でディメンション・メトリクスを生成します。
HAProxy統計エンドポイントをまだ有効にしていない場合は、haproxy.cfgに次を追加します:
frontend stats bind *:8404 stats enable stats uri /stats stats refresh 10sHAProxyをリロードして設定を適用します:
$sudo systemctl reload haproxystatsエンドポイントにアクセスできることを確認します:
$curl -s http://localhost:8404/statsOpenTelemetry Collector Contribをまだインストールしていない場合は、「OpenTelemetry Collectorリリース」から最新リリースをダウンロードしてインストールします:
Debian/Ubuntuの場合:
$wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/latest/download/otelcol-contrib_<VERSION>_linux_amd64.deb$sudo dpkg -i otelcol-contrib_<VERSION>_linux_amd64.debRHEL/Amazon Linuxの場合:
$wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/latest/download/otelcol-contrib_<VERSION>_linux_amd64.rpm$sudo rpm -U otelcol-contrib_<VERSION>_linux_amd64.rpm重要
編集前に:既存の設定をバックアップしてください。 sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.backup
コレクター設定ファイル(/etc/otelcol-contrib/config.yaml)の内容を次のように置き換えます:
receivers: haproxy: endpoint: http://localhost:8404/stats collection_interval: 15s
processors: resourcedetection: detectors: [system] system: resource_attributes: host.name: enabled: true host.id: enabled: true
batch:
exporters: otlphttp: endpoint: ${env:OTEL_EXPORTER_OTLP_ENDPOINT} headers: api-key: ${env:NEW_RELIC_LICENSE_KEY}
service: pipelines: metrics: receivers: [haproxy] processors: [resourcedetection, batch] exporters: [otlphttp]この最小限の設定により、17個のデフォルトメトリクスがすべて収集されます。haproxyreceiverは、各メトリクスにhaproxy.proxy_name、haproxy.service_name、およびhaproxy.addr属性を自動的に追加します。
より詳細な可視化のために追加のメトリクスを有効にするには(合計27個:デフォルト17個+オプション10個)、metricsセクションを追加します:
receivers: haproxy: endpoint: http://localhost:8404/stats collection_interval: 15s metrics: haproxy.connections.average_time: enabled: true haproxy.requests.average_time: enabled: true haproxy.responses.average_time: enabled: true haproxy.active: enabled: true haproxy.backup: enabled: true haproxy.downtime: enabled: true haproxy.failed_checks: enabled: true haproxy.weight: enabled: true haproxy.sessions.total: enabled: true haproxy.connections.total: enabled: true設定パラメーター
パラメータ | 説明 |
|---|---|
| HAProxyのstatsエンドポイントURL(例:
) |
| メトリクス収集の間隔。推奨:詳細をすべて取得する場合は
、取り込み量を減らす場合は
|
必要な環境変数を設定します。
$# Set your New Relic license key$export NEW_RELIC_LICENSE_KEY="<YOUR_LICENSE_KEY>"$
$# Set the OTLP endpoint. For more information, refer to New Relic OTLP endpoint: https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp$export OTEL_EXPORTER_OTLP_ENDPOINT="<YOUR_NEWRELIC_OTLP_ENDPOINT>"systemdサービスの場合は、これらをサービス環境ファイルに追加します:
$echo "NEW_RELIC_LICENSE_KEY=<YOUR_LICENSE_KEY>" | sudo tee -a /etc/otelcol-contrib/otelcol-contrib.conf$echo "OTEL_EXPORTER_OTLP_ENDPOINT=<YOUR_NEWRELIC_OTLP_ENDPOINT>" | sudo tee -a /etc/otelcol-contrib/otelcol-contrib.conf<YOUR_LICENSE_KEY> に置き換えます。
コレクターサービスを開始(または再起動)します:
$sudo systemctl daemon-reload$sudo systemctl restart otelcol-contribサービスステータスを確認します。
$sudo systemctl status otelcol-contrib設定エラーがないかログを確認します:
$sudo journalctl -u otelcol-contrib -n 50 --no-pagerデータが流れるまで2~3分待ってから、New Relicで確認します:
FROM Metric SELECT uniques(metricName)WHERE metricName LIKE 'haproxy.%'SINCE 10 minutes agoHAProxyメトリクスが表示されるはずです。次元属性を確認します:
FROM Metric SELECT latest(haproxy.sessions.count)WHERE metricName = 'haproxy.sessions.count'FACET haproxy.proxy_name, haproxy.service_nameSINCE 5 minutes ago環境内でHAProxyの組み込みPrometheusエンドポイントがすでに有効になっている場合、またはPrometheusベースの監視スタックから移行する場合は、このアプローチを使用します。
ヒント
推奨:HAProxyのPrometheusエンドポイントがまだ有効になっていない場合は、代わりにNRDOTコレクターまたはOpenTelemetry Collector Contribタブを使用してください。Prometheusエクスポーターモジュールを必要とせずに、HAProxyのstatsエンドポイントに直接接続します。
Prometheusエクスポーターをhaproxy.cfgのstatsフロントエンドに追加します:
frontend stats bind *:8404 http-request use-service prometheus-exporter if { path /metrics } stats enable stats uri /stats stats refresh 10s重要な行はhttp-request use-service prometheus-exporter if { path /metrics }です — これは/metricsへのrequestsをインターセプトし、HAProxyに組み込まれたpromexモジュールを介してPrometheus形式のメトリクスを提供します。
ヒント
HAProxy 2.0~2.3を実行している場合は、フロントエンドにoption http-use-htxを追加する必要もあります。このオプションはHAProxy 2.4以降でデフォルトになったため、不要になりました。
HAProxyをリロードします:
$sudo systemctl reload haproxyPrometheusエンドポイントを確認します:
$curl -s http://localhost:8404/metrics | head -20haproxy_frontend_current_sessionsやhaproxy_backend_http_responses_totalなどのPrometheus形式のメトリクスが表示されます。HAProxyは、このエンドポイントを通じて約204個のメトリクスを公開します。
重要
Prometheusエンドポイントには、HAProxy 2.0以降が必要です。古いバージョンを実行している場合は、代わりにhaproxyreceiverでOTel Collector Contribタブを使用してください。これはCSV統計エンドポイントを使用し、すべてのHAProxyバージョンで機能します。
OpenTelemetry Collector Contribをまだインストールしていない場合は、「OpenTelemetry Collectorリリース」から最新リリースをダウンロードしてインストールします:
Debian/Ubuntuの場合:
$wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/latest/download/otelcol-contrib_<VERSION>_linux_amd64.deb$sudo dpkg -i otelcol-contrib_<VERSION>_linux_amd64.debRHEL/Amazon Linuxの場合:
$wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/latest/download/otelcol-contrib_<VERSION>_linux_amd64.rpm$sudo rpm -U otelcol-contrib_<VERSION>_linux_amd64.rpmこの設定は、HAProxyのPrometheusエンドポイントをスクレイピングし、関連するメトリクスにフィルタリングし、haproxyreceiverの属性スキーム(haproxy.proxy_name、haproxy.service_name)に一致するようにラベルを変換し、メトリクスの名前をOTelのhaproxy.*命名規則に変更します。
この設定は、NRDOTとOTel Collector Contribの両方で機能します。適切な設定場所に配置します:
NRDOT:
/etc/nrdot-collector/config.yamlOTel Collector Contrib:
/etc/otelcol-contrib/config.yaml重要
編集前に:既存の設定をバックアップしてください。
bash$# NRDOT$sudo cp /etc/nrdot-collector/config.yaml /etc/nrdot-collector/config.yaml.backup$# OTel Collector Contrib$sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.backupコレクター設定ファイルの内容を次のように置き換えます:
receivers:prometheus/haproxy_transform:config:scrape_configs:- job_name: haproxy_transformscrape_interval: 30sstatic_configs:- targets: ["localhost:8404"]metrics_path: /metricsprocessors:# Filter to keep only the metrics we need to transformfilter/haproxy:metrics:include:match_type: regexpmetric_names:- "haproxy_frontend_bytes_in_total"- "haproxy_frontend_bytes_out_total"- "haproxy_frontend_requests_denied_total"- "haproxy_frontend_request_errors_total"- "haproxy_frontend_responses_denied_total"- "haproxy_frontend_http_requests_total"- "haproxy_frontend_connections_rate_max"- "haproxy_frontend_http_requests_rate_max"- "haproxy_frontend_current_sessions"- "haproxy_frontend_max_session_rate"- "haproxy_backend_bytes_in_total"- "haproxy_backend_bytes_out_total"- "haproxy_backend_connection_errors_total"- "haproxy_backend_retry_warnings_total"- "haproxy_backend_requests_denied_total"- "haproxy_backend_responses_denied_total"- "haproxy_backend_redispatch_warnings_total"- "haproxy_backend_http_requests_total"- "haproxy_backend_response_errors_total"- "haproxy_backend_loadbalanced_total"- "haproxy_backend_current_queue"- "haproxy_backend_total_time_average_seconds"- "haproxy_backend_current_sessions"- "haproxy_backend_max_session_rate"- "haproxy_server_bytes_in_total"- "haproxy_server_bytes_out_total"- "haproxy_server_connection_errors_total"- "haproxy_server_retry_warnings_total"- "haproxy_server_responses_denied_total"- "haproxy_server_redispatch_warnings_total"- "haproxy_server_response_errors_total"- "haproxy_server_loadbalanced_total"- "haproxy_server_current_queue"- "haproxy_server_total_time_average_seconds"- "haproxy_server_current_sessions"- "haproxy_server_max_session_rate"# Add haproxy.service_name and haproxy.proxy_name attributes using OTTLtransform/add_labels:metric_statements:- context: datapointstatements:# Frontend metrics: haproxy.service_name = "FRONTEND"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_bytes_in_total"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_bytes_out_total"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_requests_denied_total"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_request_errors_total"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_responses_denied_total"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_http_requests_total"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_connections_rate_max"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_http_requests_rate_max"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_current_sessions"- set(attributes["haproxy.service_name"], "FRONTEND") where metric.name == "haproxy_frontend_max_session_rate"# Backend metrics: haproxy.service_name = "BACKEND"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_bytes_in_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_bytes_out_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_connection_errors_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_retry_warnings_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_requests_denied_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_responses_denied_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_redispatch_warnings_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_http_requests_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_response_errors_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_loadbalanced_total"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_current_queue"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_total_time_average_seconds"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_current_sessions"- set(attributes["haproxy.service_name"], "BACKEND") where metric.name == "haproxy_backend_max_session_rate"# Server metrics: haproxy.service_name = server label value- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_bytes_in_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_bytes_out_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_connection_errors_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_retry_warnings_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_responses_denied_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_redispatch_warnings_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_response_errors_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_loadbalanced_total"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_current_queue"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_total_time_average_seconds"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_current_sessions"- set(attributes["haproxy.service_name"], attributes["server"]) where metric.name == "haproxy_server_max_session_rate"# Rename proxy label to haproxy.proxy_name for ALL metrics- set(attributes["haproxy.proxy_name"], attributes["proxy"]) where attributes["proxy"] != nil# Remove old Prometheus labels- delete_key(attributes, "proxy") where attributes["proxy"] != nil- delete_key(attributes, "server") where attributes["server"] != nil# Rename metrics to match haproxyreceiver naming conventionmetricstransform/rename:transforms:# haproxy.bytes.input- include: haproxy_frontend_bytes_in_totalaction: updatenew_name: haproxy.bytes.input- include: haproxy_backend_bytes_in_totalaction: updatenew_name: haproxy.bytes.input- include: haproxy_server_bytes_in_totalaction: updatenew_name: haproxy.bytes.input# haproxy.bytes.output- include: haproxy_frontend_bytes_out_totalaction: updatenew_name: haproxy.bytes.output- include: haproxy_backend_bytes_out_totalaction: updatenew_name: haproxy.bytes.output- include: haproxy_server_bytes_out_totalaction: updatenew_name: haproxy.bytes.output# haproxy.connections.errors- include: haproxy_backend_connection_errors_totalaction: updatenew_name: haproxy.connections.errors- include: haproxy_server_connection_errors_totalaction: updatenew_name: haproxy.connections.errors# haproxy.connections.retries- include: haproxy_backend_retry_warnings_totalaction: updatenew_name: haproxy.connections.retries- include: haproxy_server_retry_warnings_totalaction: updatenew_name: haproxy.connections.retries# haproxy.requests.denied- include: haproxy_frontend_requests_denied_totalaction: updatenew_name: haproxy.requests.denied- include: haproxy_backend_requests_denied_totalaction: updatenew_name: haproxy.requests.denied# haproxy.requests.errors- include: haproxy_frontend_request_errors_totalaction: updatenew_name: haproxy.requests.errors# haproxy.requests.redispatched- include: haproxy_backend_redispatch_warnings_totalaction: updatenew_name: haproxy.requests.redispatched- include: haproxy_server_redispatch_warnings_totalaction: updatenew_name: haproxy.requests.redispatched# haproxy.requests.total- include: haproxy_frontend_http_requests_totalaction: updatenew_name: haproxy.requests.total- include: haproxy_backend_http_requests_totalaction: updatenew_name: haproxy.requests.total# haproxy.responses.denied- include: haproxy_frontend_responses_denied_totalaction: updatenew_name: haproxy.responses.denied- include: haproxy_backend_responses_denied_totalaction: updatenew_name: haproxy.responses.denied- include: haproxy_server_responses_denied_totalaction: updatenew_name: haproxy.responses.denied# haproxy.responses.errors- include: haproxy_backend_response_errors_totalaction: updatenew_name: haproxy.responses.errors- include: haproxy_server_response_errors_totalaction: updatenew_name: haproxy.responses.errors# haproxy.server_selected.total- include: haproxy_backend_loadbalanced_totalaction: updatenew_name: haproxy.server_selected.total- include: haproxy_server_loadbalanced_totalaction: updatenew_name: haproxy.server_selected.total# haproxy.connections.rate- include: haproxy_frontend_connections_rate_maxaction: updatenew_name: haproxy.connections.rate# haproxy.requests.queued- include: haproxy_backend_current_queueaction: updatenew_name: haproxy.requests.queued- include: haproxy_server_current_queueaction: updatenew_name: haproxy.requests.queued# haproxy.requests.rate- include: haproxy_frontend_http_requests_rate_maxaction: updatenew_name: haproxy.requests.rate# haproxy.sessions.average- include: haproxy_backend_total_time_average_secondsaction: updatenew_name: haproxy.sessions.average- include: haproxy_server_total_time_average_secondsaction: updatenew_name: haproxy.sessions.average# haproxy.sessions.count- include: haproxy_frontend_current_sessionsaction: updatenew_name: haproxy.sessions.count- include: haproxy_backend_current_sessionsaction: updatenew_name: haproxy.sessions.count- include: haproxy_server_current_sessionsaction: updatenew_name: haproxy.sessions.count# haproxy.sessions.rate- include: haproxy_frontend_max_session_rateaction: updatenew_name: haproxy.sessions.rate- include: haproxy_backend_max_session_rateaction: updatenew_name: haproxy.sessions.rate- include: haproxy_server_max_session_rateaction: updatenew_name: haproxy.sessions.rate# Add resource attributes and strip Prometheus auto-labelsresource/haproxy_transform:attributes:- key: haproxy.addrvalue: "http://localhost:8404/stats"action: upsert- key: service.nameaction: delete- key: service.instance.idaction: delete- key: net.host.nameaction: delete- key: net.host.portaction: delete- key: server.portaction: delete- key: url.schemeaction: deleteresourcedetection:detectors: [system]system:resource_attributes:host.name:enabled: truehost.id:enabled: trueos.type:enabled: truetransform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")batch:exporters:otlphttp:endpoint: ${env:OTEL_EXPORTER_OTLP_ENDPOINT}headers:api-key: ${env:NEW_RELIC_LICENSE_KEY}service:pipelines:metrics/haproxy_transform:receivers:- prometheus/haproxy_transformprocessors:- filter/haproxy- transform/add_labels- metricstransform/rename- resourcedetection- resource/haproxy_transform- transform/metadata_nullify- batchexporters:- otlphttp重要
この設定は、3つの重要な変換を実行します:
- 17個のOTelデフォルトメトリクス(フロントエンド/バックエンド/サーバーティア全体)に対応する36個のPrometheusメトリクスのみへのフィルター
- haproxyreceiverの属性スキームに一致するディメンション属性を追加します(
haproxy.proxy_name、haproxy.service_name) - 一貫したダッシュボードとアラートのために、Prometheusの命名(
haproxy_frontend_*)からOTelの命名(haproxy.*)にメトリクスの名前を変更します
設定パラメーター
パラメータ
説明
targetsHAProxy Prometheusエンドポイントアドレス(デフォルトは
localhost:8404)
haproxy.addrvalue
HAProxyの統計エンドポイントURLに置き換えます
scrape_intervalPrometheusエンドポイントをスクレイピングする頻度。デフォルト:
30s
New Relicの認証情報を使用してsystemdオーバーライドファイルを作成します:
$sudo mkdir -p /etc/systemd/system/<collector-service>.service.d$cat <<EOF | sudo tee /etc/systemd/system/<collector-service>.service.d/environment.conf$[Service]$Environment="NEW_RELIC_LICENSE_KEY=<YOUR_LICENSE_KEY>"$Environment="OTEL_EXPORTER_OTLP_ENDPOINT=<YOUR_NEWRELIC_OTLP_ENDPOINT>"$EOF<YOUR_LICENSE_KEY>をに、<collector-service>をコレクターサービス名(例:otelcol-contribまたはnrdot-collector)に置き換えます。
$sudo systemctl daemon-reload$sudo systemctl restart <collector-service>サービスのステータスとログを確認してください:
$sudo systemctl status <collector-service>$sudo journalctl -u <collector-service> -n 20エラーなしでActive: active (running)が表示されます。
数分後、クエリビルダーで次のNRQLクエリを実行します:
FROM Metric SELECT *WHERE metricName LIKE 'haproxy.%'SINCE 10 minutes agoNew Relic でデータを表示する
データが流れ始めたら、New RelicでHAProxyのメトリクスを見つけます:
- one.newrelic.com > All capabilities > All entitiesに移動します。
- HAProxyエンティティを名前で検索するか、エンティティタイプ
HAPROXYINSTANCEでフィルタリングします。 - エンティティを選択して、ゴールデンメトリクス(1秒あたりのセッション数、1秒あたりのrequests、接続エラー)を含むサマリーページを表示します。
データを探索するその他の方法については、HAProxyデータの検索とクエリを参照してください。
トラブルシューティング
セットアップ中に問題が発生した場合は、このトラブルシューティング ガイドを使用して一般的な問題を診断し、解決してください。
statsフロントエンドがhaproxy.cfgで設定されていることを確認します:
$sudo haproxy -c -f /etc/haproxy/haproxy.cfg$grep -A 4 "frontend stats" /etc/haproxy/haproxy.cfg解決策:
bindポート(デフォルト8404)が別のプロセスによって使用されていないことを確認します:sudo ss -tlnp | grep 8404- HAProxyが実行中であることを確認します:
sudo systemctl status haproxy - 変更後に設定をリロードします:
sudo systemctl reload haproxy
設定エラーがないかコレクターのログを確認します:
$sudo journalctl -u otelcol-contrib -n 100 --no-pager$# or for NRDOT:$sudo journalctl -u nrdot-collector -n 100 --no-pager一般的な原因:
- 設定ファイルの無効なYAML構文
- 環境変数がありません(
NEW_RELIC_LICENSE_KEY、OTEL_EXPORTER_OTLP_ENDPOINT) - コレクターのテレメトリーポートでのポートの競合
- 初回のデータ取り込みには2~3分お待ちください。
- コレクターが実行中であることを確認します。
sudo systemctl status otelcol-contrib - コレクターホストからstatsエンドポイントに到達可能であることを確認します:
curl -s http://localhost:8404/stats - ライセンスキーが正しく、OTLPエンドポイントが正しく設定されていることを確認してください。詳細については、「New Relic OTLPエンドポイント」を参照してください。
- 任意のHAProxyメトリクスをクエリします:FROM Metric SELECT count(*) WHERE metricName LIKE 'haproxy.%' SINCE 30 minutes ago
コレクターのログに401 Unauthorizedまたは403 Forbiddenが表示される場合:
- ライセンスキーを確認します:ユーザーキーではなく、ingest(INGEST - ライセンスキー)であることを確認してください
- エンドポイントが正しく設定されていることを確認します。詳細については、「New Relic OTLPエンドポイント」を参照してください。
- 環境変数が正しく設定されていることを確認してください:
echo $NEW_RELIC_LICENSE_KEY
HAProxyの組み込みPrometheusエクスポーター(promex)には、バージョン2.0以降が必要です。
HAProxyのバージョンを確認します:
$haproxy -v2.0より古いバージョンを実行している場合は、代わりにhaproxyreceiverとともにOTel Collector Contribタブを使用してください。これはCSV statsエンドポイントを使用し、statsをサポートするすべてのHAProxyバージョンで機能します。
HAProxy 2.0~2.3を実行している場合は、statsフロントエンドの設定にoption http-use-htxが存在することを確認してください。このオプションはHAProxy 2.4以降でデフォルトになったため、新しいバージョンでは必要ありません。
次のステップ
- Kubernetes上のHAProxyをモニターする — コンテナ化された環境の自動ポッド検出
- HAProxyデータの検索とクエリ — ダッシュボード、NRQLクエリ、およびデータナビゲーション
- HAProxy OTelメトリクスリファレンス — 収集されたメトリクスの完全なリスト
- OpenTelemetryのベストプラクティス — New RelicでのOTelの一般的なガイダンス