モニタリングスタックのメトリクスの設定


Red Hat build of OpenTelemetry 3.8

OpenTelemetry Collector と Prometheus モニタリングの統合

Red Hat OpenShift Documentation Team

概要

このドキュメントでは、OpenTelemetry Collector と OpenShift モニタリングスタックの間でメトリクス統合を設定する方法について説明します。ServiceMonitor および PodMonitor カスタムリソースを使用して Collector メトリクスを Prometheus に送信する方法と、Prometheus レシーバーを使用してクラスター内モニタリングスタックからメトリクスを受信する方法を説明します。内部 Collector メトリクスの収集、Prometheus エクスポーターエンドポイント、RBAC セットアップ、TLS 設定、フェデレーションエンドポイントへのアクセスの設定が含まれます。

第1章 モニタリングスタックのメトリクスの設定

クラスター管理者は、OpenTelemetry Collector カスタムリソース (CR) を設定して、次のタスクを実行できます。

  • Collector のパイプラインメトリクスと有効な Prometheus エクスポーターをスクレイプするための Prometheus ServiceMonitor CR を作成します。
  • クラスター内モニタリングスタックからメトリクスを取得するように Prometheus Receiver を設定します。

1.1. モニタリングスタックにメトリクスを送信するための設定

OpenTelemetryCollector カスタムリソース (CR) を設定して、サイドカーデプロイメント用の Prometheus ServiceMonitor CR または PodMonitor CR を作成できます。ServiceMonitor は、Collector の内部メトリクスエンドポイントと Prometheus エクスポーターメトリクスエンドポイントをスクレイピングできます。

Prometheus エクスポーターを使用した OpenTelemetry Collector CR の例

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
spec:
  mode: deployment
  observability:
    metrics:
      enableMetrics: true 
1

  config:
    exporters:
      prometheus:
        endpoint: 0.0.0.0:8889
        resource_to_telemetry_conversion:
          enabled: true # by default resource attributes are dropped
    service:
      telemetry:
        metrics:
          readers:
          - pull:
              exporter:
                prometheus:
                  host: 0.0.0.0
                  port: 8888
      pipelines:
        metrics:
          exporters: [prometheus]
Copy to Clipboard Toggle word wrap

1
Red Hat build of OpenTelemetry Operator を設定して Prometheus ServiceMonitor CR または PodMonitor CR を作成し、Collector の内部メトリクスエンドポイントと Prometheus エクスポーターメトリクスエンドポイントをスクレイピングします。
注記

enableMetricstrue に設定すると、次の 2 つの ServiceMonitor インスタンスが作成されます。

  • <instance_name>-collector-monitoring サービス用の 1 つの ServiceMonitor インスタンス。この ServiceMonitor インスタンスは、Collector の内部メトリクスをスクレイピングします。
  • <instance_name>-collector サービス用の 1 つの ServiceMonitor インスタンス。この ServiceMonitor インスタンスは、Prometheus エクスポーターインスタンスによって公開されるメトリクスをスクレイピングします。

あるいは、手動で作成した Prometheus PodMonitor CR を使用すると、Prometheus のスクレイピング中に追加された重複ラベルの削除など、細かい制御を行うことができます。

Collector メトリクスをスクレイプするようにモニタリングスタックを設定する PodMonitor CR の例

apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: otel-collector
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: <cr_name>-collector 
1

  podMetricsEndpoints:
  - port: metrics 
2

  - port: promexporter 
3

    relabelings:
    - action: labeldrop
      regex: pod
    - action: labeldrop
      regex: container
    - action: labeldrop
      regex: endpoint
    metricRelabelings:
    - action: labeldrop
      regex: instance
    - action: labeldrop
      regex: job
Copy to Clipboard Toggle word wrap

1
OpenTelemetry Collector CR の名前。
2
OpenTelemetry Collector の内部メトリクスポートの名前。このポート名は、必ず metrics になります。
3
OpenTelemetry Collector の Prometheus エクスポーターポートの名前。

1.2. モニタリングスタックからメトリクスを受信するための設定

設定された OpenTelemetry Collector カスタムリソース (CR) は、Prometheus Receiver をセットアップして、クラスター内モニタリングスタックからメトリクスをスクレイプできます。

クラスター内のモニタリングスタックからメトリクスをスクレイプするための OpenTelemetry Collector CR の例

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otel-collector
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-monitoring-view 
1

subjects:
  - kind: ServiceAccount
    name: otel-collector
    namespace: observability
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: cabundle
  namespace: observability
  annotations:
    service.beta.openshift.io/inject-cabundle: "true" 
2

---
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel
  namespace: observability
spec:
  volumeMounts:
    - name: cabundle-volume
      mountPath: /etc/pki/ca-trust/source/service-ca
      readOnly: true
  volumes:
    - name: cabundle-volume
      configMap:
        name: cabundle
  mode: deployment
  config:
    receivers:
      prometheus: 
3

        config:
          scrape_configs:
            - job_name: 'federate'
              scrape_interval: 15s
              scheme: https
              tls_config:
                ca_file: /etc/pki/ca-trust/source/service-ca/service-ca.crt
              bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
              honor_labels: false
              params:
                'match[]':
                  - '{__name__="<metric_name>"}' 
4

              metrics_path: '/federate'
              static_configs:
                - targets:
                  - "prometheus-k8s.openshift-monitoring.svc.cluster.local:9091"
    exporters:
      debug: 
5

        verbosity: detailed
    service:
      pipelines:
        metrics:
          receivers: [prometheus]
          processors: []
          exporters: [debug]
Copy to Clipboard Toggle word wrap

1
cluster-monitoring-view クラスターロールを OpenTelemetry Collector のサービスアカウントに割り当て、サービスアカウントからメトリクスデータにアクセスできるようにします。
2
Prometheus Receiver で TLS を設定するための OpenShift サービス CA を注入します。
3
クラスター内モニタリングスタックからフェデレートエンドポイントを取得するように Prometheus Receiver を設定します。
4
Prometheus クエリー言語を使用して、スクレイプするメトリクスを選択します。フェデレートエンドポイントの詳細と制限は、クラスター内モニタリングのドキュメントを参照してください。
5
メトリクスを標準出力に出力するように Debug Exporter を設定します。

法律上の通知

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る