7.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
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"
---
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:
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>"}'
metrics_path: '/federate'
static_configs:
- targets:
- "prometheus-k8s.openshift-monitoring.svc.cluster.local:9091"
exporters:
debug:
verbosity: detailed
service:
pipelines:
metrics:
receivers: [prometheus]
processors: []
exporters: [debug]
- 1
cluster-monitoring-viewクラスターロールを OpenTelemetry Collector のサービスアカウントに割り当て、サービスアカウントからメトリクスデータにアクセスできるようにします。- 2
- Prometheus Receiver で TLS を設定するための OpenShift サービス CA を注入します。
- 3
- クラスター内モニタリングスタックからフェデレートエンドポイントを取得するように Prometheus Receiver を設定します。
- 4
- Prometheus クエリー言語を使用して、スクレイプするメトリクスを選択します。フェデレートエンドポイントの詳細と制限は、クラスター内モニタリングのドキュメントを参照してください。
- 5
- メトリクスを標準出力に出力するように Debug Exporter を設定します。