6.6. OpenShift Serverless でのメータリングの使用
メータリングは非推奨の機能です。非推奨の機能は依然として OpenShift Container Platform に含まれており、引き続きサポートされますが、本製品の今後のリリースで削除されるため、新規デプロイメントでの使用は推奨されません。
OpenShift Container Platform で非推奨となったか、または削除された主な機能の最新の一覧については、OpenShift Container Platform リリースノートの 非推奨および削除された機能セクションを参照してください。
クラスター管理者として、メータリングを使用して OpenShift Serverless クラスターで実行されている内容を分析できます。
OpenShift Container Platform のメータリングについての詳細は、メータリングの概要 を参照してください。
現時点で、メータリングは IBM Z および IBM Power Systems ではサポートされていません。
6.6.1. メータリングのインストール リンクのコピーリンクがクリップボードにコピーされました!
OpenShift Container Platform でのメータリングのインストールについての詳細は、メータリングのインストール を参照してください。
6.6.2. Knative Serving メータリングのデータソース リンクのコピーリンクがクリップボードにコピーされました!
以下の ReportDataSources は、Knative Serving を OpenShift Container Platform メータリングで使用する方法についての例です。
6.6.2.1. Knative Serving での CPU 使用状況のデータソース リンクのコピーリンクがクリップボードにコピーされました!
このデータソースは、レポート期間における Knative サービスごとに使用される累積された CPU の秒数を示します。
YAML ファイル
apiVersion: metering.openshift.io/v1
kind: ReportDataSource
metadata:
name: knative-service-cpu-usage
spec:
prometheusMetricsImporter:
query: >
sum
by(namespace,
label_serving_knative_dev_service,
label_serving_knative_dev_revision)
(
label_replace(rate(container_cpu_usage_seconds_total{container!="POD",container!="",pod!=""}[1m]), "pod", "$1", "pod", "(.*)")
*
on(pod, namespace)
group_left(label_serving_knative_dev_service, label_serving_knative_dev_revision)
kube_pod_labels{label_serving_knative_dev_service!=""}
)
6.6.2.2. Knative Serving でのメモリー使用状況のデータソース リンクのコピーリンクがクリップボードにコピーされました!
このデータソースは、レポート期間における Knative サービスごとの平均メモリー消費量を示します。
YAML ファイル
apiVersion: metering.openshift.io/v1
kind: ReportDataSource
metadata:
name: knative-service-memory-usage
spec:
prometheusMetricsImporter:
query: >
sum
by(namespace,
label_serving_knative_dev_service,
label_serving_knative_dev_revision)
(
label_replace(container_memory_usage_bytes{container!="POD", container!="",pod!=""}, "pod", "$1", "pod", "(.*)")
*
on(pod, namespace)
group_left(label_serving_knative_dev_service, label_serving_knative_dev_revision)
kube_pod_labels{label_serving_knative_dev_service!=""}
)
6.6.2.3. Knative Serving メータリングのデータソースの適用 リンクのコピーリンクがクリップボードにコピーされました!
以下のコマンドを使用して、ReportDataSources を適用することができます。
$ oc apply -f <datasource_name>.yaml
例
$ oc apply -f knative-service-memory-usage.yaml
6.6.3. Knative Serving メータリングのクエリー リンクのコピーリンクがクリップボードにコピーされました!
以下の ReportQuery リソースは、提供されるサンプルの DataSources を参照します。
6.6.3.1. Knative Serving での CPU 使用状況のクエリー リンクのコピーリンクがクリップボードにコピーされました!
YAML ファイル
apiVersion: metering.openshift.io/v1
kind: ReportQuery
metadata:
name: knative-service-cpu-usage
spec:
inputs:
- name: ReportingStart
type: time
- name: ReportingEnd
type: time
- default: knative-service-cpu-usage
name: KnativeServiceCpuUsageDataSource
type: ReportDataSource
columns:
- name: period_start
type: timestamp
unit: date
- name: period_end
type: timestamp
unit: date
- name: namespace
type: varchar
unit: kubernetes_namespace
- name: service
type: varchar
- name: data_start
type: timestamp
unit: date
- name: data_end
type: timestamp
unit: date
- name: service_cpu_seconds
type: double
unit: cpu_core_seconds
query: |
SELECT
timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart| prestoTimestamp |}' AS period_start,
timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}' AS period_end,
labels['namespace'] as project,
labels['label_serving_knative_dev_service'] as service,
min("timestamp") as data_start,
max("timestamp") as data_end,
sum(amount * "timeprecision") AS service_cpu_seconds
FROM {| dataSourceTableName .Report.Inputs.KnativeServiceCpuUsageDataSource |}
WHERE "timestamp" >= timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prestoTimestamp |}'
AND "timestamp" < timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}'
GROUP BY labels['namespace'],labels['label_serving_knative_dev_service']
6.6.3.2. Knative Serving でのメモリー使用状況のクエリー リンクのコピーリンクがクリップボードにコピーされました!
YAML ファイル
apiVersion: metering.openshift.io/v1
kind: ReportQuery
metadata:
name: knative-service-memory-usage
spec:
inputs:
- name: ReportingStart
type: time
- name: ReportingEnd
type: time
- default: knative-service-memory-usage
name: KnativeServiceMemoryUsageDataSource
type: ReportDataSource
columns:
- name: period_start
type: timestamp
unit: date
- name: period_end
type: timestamp
unit: date
- name: namespace
type: varchar
unit: kubernetes_namespace
- name: service
type: varchar
- name: data_start
type: timestamp
unit: date
- name: data_end
type: timestamp
unit: date
- name: service_usage_memory_byte_seconds
type: double
unit: byte_seconds
query: |
SELECT
timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart| prestoTimestamp |}' AS period_start,
timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}' AS period_end,
labels['namespace'] as project,
labels['label_serving_knative_dev_service'] as service,
min("timestamp") as data_start,
max("timestamp") as data_end,
sum(amount * "timeprecision") AS service_usage_memory_byte_seconds
FROM {| dataSourceTableName .Report.Inputs.KnativeServiceMemoryUsageDataSource |}
WHERE "timestamp" >= timestamp '{| default .Report.ReportingStart .Report.Inputs.ReportingStart | prestoTimestamp |}'
AND "timestamp" < timestamp '{| default .Report.ReportingEnd .Report.Inputs.ReportingEnd | prestoTimestamp |}'
GROUP BY labels['namespace'],labels['label_serving_knative_dev_service']
6.6.3.3. Knative Serving メータリングのクエリーの適用 リンクのコピーリンクがクリップボードにコピーされました!
以下のコマンドを使用して、
ReportQueryを適用できます。$ oc apply -f <query-name>.yamlコマンドの例
$ oc apply -f knative-service-memory-usage.yaml
6.6.4. Knative Serving のメータリングレポート リンクのコピーリンクがクリップボードにコピーされました!
Report リソースを作成し、Knative Serving に対してメータリングレポートを実行できます。レポートを実行する前に、レポート期間の開始日と終了日を指定するために、Report リソース内で入力パラメーターを変更する必要があります。
YAML ファイル
apiVersion: metering.openshift.io/v1
kind: Report
metadata:
name: knative-service-cpu-usage
spec:
reportingStart: '2019-06-01T00:00:00Z'
reportingEnd: '2019-06-30T23:59:59Z'
query: knative-service-cpu-usage
runImmediately: true
6.6.4.1. メータリングレポートの実行 リンクのコピーリンクがクリップボードにコピーされました!
以下のコマンドを入力してレポートを実行します。
$ oc apply -f <report-name>.yml以下のコマンドを入力してレポートを確認できます。
$ oc get report出力例
NAME QUERY SCHEDULE RUNNING FAILED LAST REPORT TIME AGE knative-service-cpu-usage knative-service-cpu-usage Finished 2019-06-30T23:59:59Z 10h