このKubernetesインテグレーションは、クラスタ内のHAProxyポッドを自動的に検出し、各インスタンスの手動設定なしでメトリクスを収集します。OpenTelemetryのhaproxyreceiverとreceivercreatorを使用して、コンテナ化された環境全体でHAProxyのセッション、requests、エラー、およびバックエンドサーバーの健全性を動的にモニターします。
ヒント
LinuxホストでHAProxyを実行していますか?仮想マシンまたはベアメタルデプロイメントについては、セルフホストインストレーションガイドを参照してください。
あなたが始める前に
以下のものを用意してください:
- 有効なNew Relicライセンスキー
- statsエンドポイントが有効になっているHAProxyポッド(通常はポート8404)
- 検出用の各HAProxyポッドのラベル(例:
app: haproxy) - Helmインストール方法を使用している場合は、ベースとなるKubernetes OpenTelemetry Helmインストレーションを完了してください。
HAProxy監視の設定
values.yamlのdeployment.extraConfigの下に次のセクションを追加します:重要
deployment.extraConfigでは、pipelines:はルートレベルで定義する必要があります —service:の下にネストしないでください。Helmチャートテンプレートは、extraConfig.pipelinesをservice.pipelinesに、extraConfig.service.extensionsをservice.extensionsにマッピングします。拡張機能:
extensions:k8s_observer:auth_type: serviceAccountobserve_pods: trueobserve_nodes: false環境変数(
deployment.envsの下に追加):deployment:envs:- name: OTEL_RESOURCE_ATTRIBUTESvalue: "host.id=$(KUBE_NODE_NAME)"重要
エンティティの合成には、
host.idリソース属性が必要です。コンテナイメージには/etc/machine-idがないため、OTEL_RESOURCE_ATTRIBUTESを介して注入する必要があります。Helmチャートは、Kubernetes Downward APIからすでにKUBE_NODE_NAMEを設定しています。レシーバー:
receivers:receiver_creator/haproxy:watch_observers: [k8s_observer]receivers:haproxy:rule: type == "pod" && labels["app"] == "haproxy"config:endpoint: 'http://`endpoint`:8404/stats'collection_interval: 30sプロセッサ:
processors:resource/cluster:attributes:- key: k8s.cluster.namevalue: "<YOUR_CLUSTER_NAME>"action: inserttransform/haproxy:metric_statements:- context: resourcestatements:- set(attributes["haproxy.display.name"], Concat(["server","k8s",attributes["k8s.cluster.name"],attributes["k8s.namespace.name"],"pod",attributes["k8s.pod.name"],"haproxy","8404"], ":"))transform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")サービス拡張機能:
service:extensions: [k8s_observer]パイプライン:
pipelines:metrics/haproxy:receivers: [receiver_creator/haproxy]processors: [batch, resource/cluster, transform/haproxy, transform/metadata_nullify, memory_limiter]exporters: [otlphttp/newrelic]設定パラメーター
次の表では、キー設定について説明します。
パラメータ
説明
labels["app"] == "haproxy"HAProxyポッドの検出に使用されるポッドラベルセレクタ。ポッドのラベルに一致するようにルールを更新します。
<YOUR_PORT_NUMBER>HAProxyがstatsエンドポイントを公開するポート。
<YOUR_CLUSTER_NAME>New Relicでの識別用に、Kubernetesクラスタ名に置き換えます。
collection_intervalメトリクスを収集する頻度。デフォルトは
30sです。
更新された値を実行中のHelmリリースに適用します:
bash$helm upgrade nr-k8s-otel-collector newrelic/nr-k8s-otel-collector \>--namespace newrelic \>--reuse-values \>-f values.yaml
基本的なKubernetes OpenTelemetryマニフェストのインストレーションを完了した後、HAProxyの監視を設定します:
NRDOT コレクターを使用するようにコレクター イメージを更新します。
ローカルの
renderedディレクトリにあるdeployment.yamlファイルで、イメージを次のように更新します:image: newrelic/nrdot-collector:latestデプロイメント仕様に以下を追加して、ホストの
/etc/machine-idをコレクターコンテナにマウントします:volumeMounts:- name: machine-idmountPath: /etc/machine-idreadOnly: truevolumes:- name: machine-idhostPath:path: /etc/machine-idtype: File重要
エンティティの合成には、
host.idリソース属性が必要です。resourcedetectionプロセッサは/etc/machine-idを読み取って入力します。このボリュームマウントがないと、host.idは設定されず、エンティティは作成されません。deployment-configmap.yamlのdeployment-config.yaml: |の下にあるコンテンツを次のように置き換えます:extensions:health_check:endpoint: 0.0.0.0:13133k8s_observer:auth_type: serviceAccountobserve_pods: trueobserve_nodes: falsereceivers:receiver_creator/haproxy:watch_observers: [k8s_observer]receivers:haproxy:rule: type == "pod" && labels["app"] == "haproxy"config:endpoint: 'http://`endpoint`:8404/stats'collection_interval: 30sprocessors:resourcedetection:detectors: [env, system]system:resource_attributes:host.name:enabled: truehost.id:enabled: trueos.type:enabled: truebatch:send_batch_max_size: 1000timeout: 30ssend_batch_size: 800memory_limiter:check_interval: 1slimit_percentage: 80spike_limit_percentage: 25resource/cluster:attributes:- key: k8s.cluster.namevalue: "<YOUR_CLUSTER_NAME>"action: inserttransform/haproxy:metric_statements:- context: resourcestatements:- set(attributes["haproxy.display.name"], Concat(["server","k8s",attributes["k8s.cluster.name"],attributes["k8s.namespace.name"],"pod",attributes["k8s.pod.name"],"haproxy","8404"], ":"))transform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")exporters:otlp_http/newrelic:endpoint: "<YOUR_NEWRELIC_OTLP_ENDPOINT>"headers:api-key: ${env:NR_LICENSE_KEY}service:extensions: [health_check, k8s_observer]pipelines:metrics/haproxy:receivers: [receiver_creator/haproxy]processors: [resourcedetection, batch, resource/cluster, transform/haproxy, transform/metadata_nullify, memory_limiter]exporters: [otlp_http/newrelic]DaemonSetとkube-state-metricsデプロイメントを削除します(HAProxyのみの監視には不要です):
bash$kubectl delete daemonset nr-k8s-otel-collector-daemonset -n newrelic$kubectl delete deployment nr-k8s-otel-collector-kube-state-metrics -n newrelic変更を適用するには、コレクターのデプロイメントを再起動します:
bash$kubectl rollout restart deployment nr-k8s-otel-collector-deployment -n newrelic設定パラメーター
パラメータ
説明
labels["app"] == "haproxy"HAProxyポッドの検出に使用されるポッドラベルセレクタ。ポッドのラベルに一致するようにルールを更新します。
<YOUR_PORT_NUMBER>HAProxyがstatsエンドポイントを公開するポート。
<YOUR_CLUSTER_NAME>New Relicでの識別用に、Kubernetesクラスタ名に置き換えます。
<YOUR_NEWRELIC_OTLP_ENDPOINT>New Relic OTLPエンドポイント。米国には
https://otlp.nr-data.netを、EUには
https://otlp.eu01.nr-data.netを使用します。
OpenTelemetry Collector ContribをKubernetesクラスタにデプロイします。コレクターは、HAProxyポッドからメトリクスを自動的に検出してスクレイピングします。Helm(アップストリームのOTel Helmチャートを使用)または生のKubernetesマニフェストのいずれかを選択します。
次のHAProxy監視設定を使用して
values.yamlファイルを作成します:mode: deploymentimage:repository: otel/opentelemetry-collector-contribclusterRole:create: truerules:- apiGroups: [""]resources: ["pods", "nodes"]verbs: ["get", "list", "watch"]- apiGroups: ["apps"]resources: ["replicasets"]verbs: ["get", "list", "watch"]extraVolumes:- name: machine-idhostPath:path: /etc/machine-idtype: FileextraVolumeMounts:- name: machine-idmountPath: /etc/machine-idreadOnly: trueconfig:extensions:health_check:endpoint: ${env:MY_POD_IP}:13133k8s_observer:auth_type: serviceAccountobserve_pods: trueobserve_nodes: falsereceivers:receiver_creator/haproxy:watch_observers: [k8s_observer]receivers:haproxy:rule: type == "pod" && labels["app"] == "haproxy"config:endpoint: 'http://`endpoint`:8404/stats'collection_interval: 30sprocessors:resourcedetection:detectors: [env, system]system:resource_attributes:host.name:enabled: truehost.id:enabled: trueos.type:enabled: truebatch:send_batch_size: 1024timeout: 30smemory_limiter:check_interval: 1slimit_percentage: 80spike_limit_percentage: 25resource/cluster:attributes:- key: k8s.cluster.namevalue: "<YOUR_CLUSTER_NAME>"action: inserttransform/haproxy:metric_statements:- context: resourcestatements:- set(attributes["haproxy.display.name"], Concat(["server", "k8s", attributes["k8s.cluster.name"], attributes["k8s.namespace.name"], "pod", attributes["k8s.pod.name"], "haproxy", "8404"], ":"))transform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")exporters:otlp_http/newrelic:endpoint: "<YOUR_NEWRELIC_OTLP_ENDPOINT>"headers:api-key: "<YOUR_NEW_RELIC_LICENSE_KEY>"service:extensions: [health_check, k8s_observer]pipelines:metrics/haproxy:receivers: [receiver_creator/haproxy]processors: [resourcedetection, batch, resource/cluster, transform/haproxy, transform/metadata_nullify, memory_limiter]exporters: [otlp_http/newrelic]設定パラメーター
パラメータ
説明
labels["app"] == "haproxy"HAProxyポッドの検出に使用されるポッドラベルセレクタ。ポッドのラベルに一致するようにルールを更新します。
<YOUR_PORT_NUMBER>HAProxyがstatsエンドポイントを公開するポート。
<YOUR_CLUSTER_NAME>New Relicでの識別用に、Kubernetesクラスタ名に置き換えます。
<YOUR_NEWRELIC_OTLP_ENDPOINT>New Relic OTLPエンドポイント。米国には
https://otlp.nr-data.netを、EUには
https://otlp.eu01.nr-data.netを使用します。
<YOUR_NEW_RELIC_LICENSE_KEY>New Relicのingestライセンスキー。
アップストリームのOpenTelemetry Helmチャートを使用してインストールします:
bash$helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts$helm repo update$helm upgrade --install haproxy-otel-collector open-telemetry/opentelemetry-collector \>-f values.yaml \>-n newrelic --create-namespace
Helmを使用できない場合、またはkubectlを使用してKubernetesリソースを直接管理したい場合は、このオプションを使用します。
New Relicライセンスキーを使用してシークレットを作成します:
bash$kubectl create namespace newrelic$kubectl create secret generic otel-collector-haproxy-secret \>--namespace newrelic \>--from-literal=licenseKey='<YOUR_NEW_RELIC_LICENSE_KEY>'次のマニフェストをファイル(例:
otel-collector-haproxy.yaml)に保存します:---apiVersion: v1kind: ServiceAccountmetadata:name: otel-collector-haproxynamespace: newreliclabels:app: otel-collector-haproxy---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: otel-collector-haproxylabels:app: otel-collector-haproxyrules:- apiGroups: [""]resources: ["pods", "nodes"]verbs: ["get", "list", "watch"]- apiGroups: ["apps"]resources: ["replicasets"]verbs: ["get", "list", "watch"]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: otel-collector-haproxylabels:app: otel-collector-haproxyroleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: otel-collector-haproxysubjects:- kind: ServiceAccountname: otel-collector-haproxynamespace: newrelic---apiVersion: v1kind: ConfigMapmetadata:name: otel-collector-haproxy-confignamespace: newreliclabels:app: otel-collector-haproxydata:collector-config.yaml: |extensions:health_check:endpoint: 0.0.0.0:13133k8s_observer:auth_type: serviceAccountobserve_pods: trueobserve_nodes: falsereceivers:receiver_creator/haproxy:watch_observers: [k8s_observer]receivers:haproxy:rule: type == "pod" && labels["app"] == "haproxy"config:endpoint: 'http://`endpoint`:8404/stats'collection_interval: 30sprocessors:resourcedetection:detectors: [env, system]system:resource_attributes:host.name:enabled: truehost.id:enabled: trueos.type:enabled: truebatch:send_batch_size: 1024timeout: 30smemory_limiter:check_interval: 1slimit_percentage: 80spike_limit_percentage: 25resource/cluster:attributes:- key: k8s.cluster.namevalue: "<YOUR_CLUSTER_NAME>"action: inserttransform/haproxy:metric_statements:- context: resourcestatements:- set(attributes["haproxy.display.name"], Concat(["server", "k8s", attributes["k8s.cluster.name"], attributes["k8s.namespace.name"], "pod", attributes["k8s.pod.name"], "haproxy", "8404"], ":"))transform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")exporters:otlp_http/newrelic:endpoint: "<YOUR_NEWRELIC_OTLP_ENDPOINT>"headers:api-key: ${env:NR_LICENSE_KEY}service:extensions: [health_check, k8s_observer]pipelines:metrics/haproxy:receivers: [receiver_creator/haproxy]processors: [resourcedetection, batch, resource/cluster, transform/haproxy, transform/metadata_nullify, memory_limiter]exporters: [otlp_http/newrelic]---apiVersion: apps/v1kind: Deploymentmetadata:name: otel-collector-haproxynamespace: newreliclabels:app: otel-collector-haproxyspec:replicas: 1selector:matchLabels:app: otel-collector-haproxytemplate:metadata:labels:app: otel-collector-haproxyspec:serviceAccountName: otel-collector-haproxycontainers:- name: otel-collectorimage: otel/opentelemetry-collector-contrib:latestcommand:- "/otelcol-contrib"- "--config=/conf/collector-config.yaml"env:- name: NR_LICENSE_KEYvalueFrom:secretKeyRef:name: otel-collector-haproxy-secretkey: licenseKey- name: GOGCvalue: "80"ports:- name: healthcontainerPort: 13133protocol: TCPresources:limits:cpu: 500mmemory: 512Mirequests:cpu: 100mmemory: 256MivolumeMounts:- name: configmountPath: /conf- name: machine-idmountPath: /etc/machine-idreadOnly: truevolumes:- name: configconfigMap:name: otel-collector-haproxy-configitems:- key: collector-config.yamlpath: collector-config.yaml- name: machine-idhostPath:path: /etc/machine-idtype: File重要
エンティティの合成には、
/etc/machine-idボリュームマウントが必要です。resourcedetectionプロセッサは、このファイルを読み取ってhost.idリソース属性に値を入力します。これがないと、New Relicでエンティティが作成されません。マニフェストを適用します:
bash$kubectl apply -f otel-collector-haproxy.yamlコレクターが実行されており、HAProxyポッドを検出していることを確認します:
bash$kubectl get pods -n newrelic -l app=otel-collector-haproxy$kubectl logs -n newrelic -l app=otel-collector-haproxyHAProxyポッドのIPとともに
starting receiverを示すログ行が表示されるはずです。設定パラメーター
パラメータ
説明
labels["app"] == "haproxy"HAProxyポッドの検出に使用されるポッドラベルセレクタ。ポッドのラベルに一致するようにルールを更新します。
<YOUR_PORT_NUMBER>HAProxyがstatsエンドポイントを公開するポート。
<YOUR_CLUSTER_NAME>New Relicでの識別用に、Kubernetesクラスタ名に置き換えます。
<YOUR_NEWRELIC_OTLP_ENDPOINT>New Relic OTLPエンドポイント。米国には
https://otlp.nr-data.netを、EUには
https://otlp.eu01.nr-data.netを使用します。
<YOUR_NEW_RELIC_LICENSE_KEY>New Relicのingestライセンスキー。
HAProxyポッドがすでにPrometheusの/metricsエンドポイント(HAProxy 2.0以降)を公開しており、CSV statsエンドポイントに接続するよりもPrometheusメトリクスをスクレイピングしたい場合は、このアプローチを使用します。
ヒント
Prometheusエンドポイントをまだ有効にしていない場合は、代わりにNRDOTコレクターまたはOpenTelemetry Collector Contribタブを使用してください。これらは、Prometheusのサポートを必要とせずに、HAProxyのstatsエンドポイントに直接接続します。
重要
このアプローチでは、組み込みのPrometheusエンドポイントが有効になっているHAProxy 2.0+が必要です。HAProxyの設定には以下を含める必要があります:
frontend stats bind *:8404 http-request use-service prometheus-exporter if { path /metrics }また、HAProxyポッドはメトリクスエンドポイントの名前付きポートを公開する必要があります:
ports: - name: metrics containerPort: 8404先に進む前に、nr-k8s-otel-collectorの基本的なKubernetes OpenTelemetry Helmインストレーションを完了してください。
values.yamlのdeployment.configMap.extraConfigの下に次のセクションを追加します:重要
deployment.configMap.extraConfigでは、pipelines:はルートレベルで定義する必要があります —service:の下にネストしないでください。Helmチャートテンプレートは、extraConfig.pipelinesをservice.pipelinesに、extraConfig.service.extensionsをservice.extensionsにマッピングします。拡張機能:
extensions:k8s_observer:auth_type: serviceAccountobserve_pods: trueobserve_nodes: false環境変数(
deployment.envsの下に追加):deployment:envs:- name: OTEL_RESOURCE_ATTRIBUTESvalue: "host.id=$(KUBE_NODE_NAME)"重要
エンティティの合成には、
host.idリソース属性が必要です。resourcedetectionプロセッサはOTEL_RESOURCE_ATTRIBUTESを読み取って入力します。Helmチャートは、Kubernetes Downward APIからすでにKUBE_NODE_NAMEを設定しています。レシーバー:
receivers:receiver_creator/haproxy_prom:watch_observers: [k8s_observer]receivers:prometheus:rule: type == "port" && pod.labels["app"] == "haproxy" && port == 8404config:config:scrape_configs:- job_name: haproxy_prommetrics_path: /metricsscrape_interval: 30sstatic_configs:- targets:- '`endpoint`'resource_attributes:haproxy.addr: 'http://`endpoint`/metrics'プロセッサ:
processors:resourcedetection:detectors: [env]filter/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_http_requests_total"- "haproxy_frontend_current_sessions"- "haproxy_frontend_max_session_rate"- "haproxy_frontend_http_requests_rate_max"- "haproxy_frontend_connections_rate_max"- "haproxy_backend_bytes_in_total"- "haproxy_backend_bytes_out_total"- "haproxy_backend_connection_errors_total"- "haproxy_backend_http_requests_total"- "haproxy_backend_current_sessions"- "haproxy_backend_max_session_rate"- "haproxy_backend_current_queue"- "haproxy_server_bytes_in_total"- "haproxy_server_bytes_out_total"- "haproxy_server_connection_errors_total"- "haproxy_server_current_sessions"- "haproxy_server_max_session_rate"- "haproxy_server_current_queue"transform/add_labels:metric_statements:- context: datapointstatements:- set(attributes["haproxy.service_name"], "FRONTEND") where IsMatch(metric.name, "^haproxy_frontend_.*")- set(attributes["haproxy.service_name"], "BACKEND") where IsMatch(metric.name, "^haproxy_backend_.*")- set(attributes["haproxy.service_name"], attributes["server"]) where IsMatch(metric.name, "^haproxy_server_.*")- set(attributes["haproxy.proxy_name"], attributes["proxy"]) where attributes["proxy"] != nil- delete_key(attributes, "proxy") where attributes["proxy"] != nil- delete_key(attributes, "server") where attributes["server"] != nilmetricstransform/rename:transforms:- 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- 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- include: haproxy_backend_connection_errors_totalaction: updatenew_name: haproxy.connections.errors- include: haproxy_server_connection_errors_totalaction: updatenew_name: haproxy.connections.errors- include: haproxy_frontend_requests_denied_totalaction: updatenew_name: haproxy.requests.denied- include: haproxy_frontend_request_errors_totalaction: updatenew_name: haproxy.requests.errors- include: haproxy_frontend_http_requests_totalaction: updatenew_name: haproxy.requests.total- include: haproxy_backend_http_requests_totalaction: updatenew_name: haproxy.requests.total- include: haproxy_backend_current_queueaction: updatenew_name: haproxy.requests.queued- include: haproxy_server_current_queueaction: updatenew_name: haproxy.requests.queued- 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- include: haproxy_frontend_http_requests_rate_maxaction: updatenew_name: haproxy.requests.rate- include: haproxy_frontend_connections_rate_maxaction: updatenew_name: haproxy.connections.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.rateresource/cluster:attributes:- key: k8s.cluster.namevalue: "<YOUR_CLUSTER_NAME>"action: inserttransform/haproxy:metric_statements:- context: resourcestatements:- set(attributes["haproxy.display.name"], Concat(["server", "k8s", attributes["k8s.cluster.name"], attributes["k8s.namespace.name"], "pod", attributes["k8s.pod.name"], "haproxy", "8404"], ":"))transform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")サービス拡張機能:
service:extensions: [k8s_observer]パイプライン:
pipelines:metrics/haproxy_prom:receivers: [receiver_creator/haproxy_prom]processors: [resourcedetection, filter/haproxy, transform/add_labels, metricstransform/rename, resource/cluster, batch, transform/haproxy, transform/metadata_nullify, memory_limiter]exporters: [otlp_http/newrelic]設定パラメーター
パラメータ
説明
labels["app"] == "haproxy"HAProxyポッドの検出に使用されるポッドラベルセレクタ。ポッドのラベルに一致するようにルールを更新します。
<YOUR_PORT_NUMBER>HAProxyがPrometheusエンドポイントを公開するポート。
<YOUR_CLUSTER_NAME>New Relicでの識別用に、Kubernetesクラスタ名に置き換えます。
scrape_intervalPrometheusメトリクスをスクレイプする頻度。デフォルト:
30s。
更新された値を実行中のHelmリリースに適用します:
bash$helm upgrade nr-k8s-otel-collector newrelic/nr-k8s-otel-collector \>--namespace newrelic \>--reuse-values \>-f values.yaml
Prometheusレシーバーの設定を含む
values.yamlファイルを作成します:mode: deploymentimage:repository: otel/opentelemetry-collector-contribclusterRole:create: truerules:- apiGroups: [""]resources: ["pods", "nodes"]verbs: ["get", "list", "watch"]- apiGroups: ["apps"]resources: ["replicasets"]verbs: ["get", "list", "watch"]extraVolumes:- name: machine-idhostPath:path: /etc/machine-idtype: FileextraVolumeMounts:- name: machine-idmountPath: /etc/machine-idreadOnly: trueconfig:extensions:health_check:endpoint: ${env:MY_POD_IP}:13133k8s_observer:auth_type: serviceAccountobserve_pods: trueobserve_nodes: falsereceivers:receiver_creator/haproxy_prom:watch_observers: [k8s_observer]receivers:prometheus:rule: type == "port" && pod.labels["app"] == "haproxy" && port == 8404config:config:scrape_configs:- job_name: haproxy_prommetrics_path: /metricsscrape_interval: 30sstatic_configs:- targets:- '`endpoint`'resource_attributes:haproxy.addr: 'http://`endpoint`/metrics'processors:resourcedetection:detectors: [env, system]system:resource_attributes:host.name:enabled: truehost.id:enabled: trueos.type:enabled: truefilter/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_http_requests_total"- "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_http_requests_total"- "haproxy_backend_current_sessions"- "haproxy_backend_max_session_rate"- "haproxy_backend_current_queue"- "haproxy_server_bytes_in_total"- "haproxy_server_bytes_out_total"- "haproxy_server_connection_errors_total"- "haproxy_server_current_sessions"- "haproxy_server_max_session_rate"- "haproxy_server_current_queue"transform/add_labels:metric_statements:- context: datapointstatements:- set(attributes["haproxy.service_name"], "FRONTEND") where IsMatch(metric.name, "^haproxy_frontend_.*")- set(attributes["haproxy.service_name"], "BACKEND") where IsMatch(metric.name, "^haproxy_backend_.*")- set(attributes["haproxy.service_name"], attributes["server"]) where IsMatch(metric.name, "^haproxy_server_.*")- set(attributes["haproxy.proxy_name"], attributes["proxy"]) where attributes["proxy"] != nil- delete_key(attributes, "proxy") where attributes["proxy"] != nil- delete_key(attributes, "server") where attributes["server"] != nilmetricstransform/rename:transforms:- 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- 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- include: haproxy_backend_connection_errors_totalaction: updatenew_name: haproxy.connections.errors- include: haproxy_server_connection_errors_totalaction: updatenew_name: haproxy.connections.errors- include: haproxy_frontend_requests_denied_totalaction: updatenew_name: haproxy.requests.denied- include: haproxy_frontend_request_errors_totalaction: updatenew_name: haproxy.requests.errors- include: haproxy_frontend_http_requests_totalaction: updatenew_name: haproxy.requests.total- include: haproxy_backend_http_requests_totalaction: updatenew_name: haproxy.requests.total- include: haproxy_backend_current_queueaction: updatenew_name: haproxy.requests.queued- include: haproxy_server_current_queueaction: updatenew_name: haproxy.requests.queued- 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- 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.rateresource/cluster:attributes:- key: k8s.cluster.namevalue: "<YOUR_CLUSTER_NAME>"action: insertbatch:send_batch_size: 1024timeout: 30smemory_limiter:check_interval: 1slimit_percentage: 80spike_limit_percentage: 25transform/haproxy:metric_statements:- context: resourcestatements:- set(attributes["haproxy.display.name"], Concat(["server", "k8s", attributes["k8s.cluster.name"], attributes["k8s.namespace.name"], "pod", attributes["k8s.pod.name"], "haproxy", "8404"], ":"))transform/metadata_nullify:metric_statements:- context: metricstatements:- set(description, "")- set(unit, "")exporters:otlp_http/newrelic:endpoint: "<YOUR_NEWRELIC_OTLP_ENDPOINT>"headers:api-key: "<YOUR_NEW_RELIC_LICENSE_KEY>"service:extensions: [health_check, k8s_observer]pipelines:metrics/haproxy_prom:receivers: [receiver_creator/haproxy_prom]processors: [resourcedetection, filter/haproxy, transform/add_labels, metricstransform/rename, resource/cluster, batch, transform/haproxy, transform/metadata_nullify, memory_limiter]exporters: [otlp_http/newrelic]重要
エンティティの合成には、
/etc/machine-idボリュームマウントが必要です。resourcedetectionプロセッサは、このファイルを読み取ってhost.idリソース属性に値を入力します。これがないと、New Relicでエンティティが作成されません。設定パラメーター
パラメータ
説明
labels["app"] == "haproxy"HAProxyポッドの検出に使用されるポッドラベルセレクタ。ポッドのラベルに一致するようにルールを更新します。
<YOUR_PORT_NUMBER>HAProxyがPrometheusエンドポイントを公開するポート。
<YOUR_CLUSTER_NAME>New Relicでの識別用に、Kubernetesクラスタ名に置き換えます。
<YOUR_NEWRELIC_OTLP_ENDPOINT>New Relic OTLPエンドポイント。米国には
https://otlp.nr-data.netを、EUには
https://otlp.eu01.nr-data.netを使用します。
<YOUR_NEW_RELIC_LICENSE_KEY>New Relicのingestライセンスキー。
scrape_intervalPrometheusメトリクスをスクレイプする頻度。デフォルト:
30s。
アップストリームのOpenTelemetry Helmチャートを使用してインストールします:
bash$helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts$helm repo update$helm upgrade --install haproxy-prom-collector open-telemetry/opentelemetry-collector \>-f values.yaml \>-n newrelic --create-namespace
New Relic でデータを表示する
数分後、HAProxyメトリクスがNew Relicに表示されます。データを検索するには:
- one.newrelic.com > All capabilities > All entitiesに移動します。
- HAProxyエンティティを名前で検索するか、エンティティタイプ
HAPROXYINSTANCEでフィルタリングします。 - エンティティを選択して、ゴールデンメトリクス(1秒あたりのセッション数、1秒あたりのrequests、接続エラー)を含むサマリーページを表示します。
トラブルシューティング
- HAProxyポッドに正しいラベル(たとえば、
app: haproxy)があることを確認します:kubectl get pods -l app=haproxy - statsエンドポイントが応答することを確認します:
kubectl exec -it <haproxy-pod> -- curl -s http://localhost:8404/stats - 検出エラーについてコレクターのログを確認します:
kubectl logs -n newrelic -l app.kubernetes.io/name=nr-k8s-otel-collector -f(NRDOT)またはkubectl logs -n newrelic -l app=otel-collector-haproxy -f(OTel Contribマニフェスト) - コレクターのServiceAccountがポッドに対する
get、list、およびwatchの権限を持っていることを確認します。
各HAProxyポッドは、New Relicに個別のエンティティを作成する必要があります。エンティティが1つしか表示されない場合:
- コレクターに
host.idが設定されていることを確認します。コンテナ化された環境では、これをコレクターのデプロイメントに追加します:env:- name: K8S_NODE_NAMEvalueFrom:fieldRef:fieldPath: spec.nodeName- name: OTEL_RESOURCE_ATTRIBUTESvalue: "host.id=$(K8S_NODE_NAME)" - 次のクエリを実行して、ポッドごとに異なる
haproxy.addr値を確認します:FROM Metric SELECT uniques(haproxy.addr) WHERE metricName LIKE 'haproxy.%' SINCE 10 minutes ago
receiver_creatorは、HAProxyに到達するために(localhostではなく)ポッドIPを使用します。statsフロントエンドが127.0.0.1:8404ではなく、*:8404(すべてのインターフェース)にバインドされていることを確認します。- コレクターポッドとHAProxyポッド間のトラフィックをブロックする可能性のあるネットワークポリシーを確認します。
次のステップ
- 収集されたメトリクスの完全なリストについては、メトリクスリファレンスを確認してください。
- HAProxyデータを検索してクエリを実行する方法をご覧ください。
- HAProxyのゴールデンメトリクスに基づいてアラートを設定します。