1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-06 06:46:26 +01:00
Files
openshift-docs/modules/serverless-metering-datasources.adoc
2020-09-30 18:43:42 +00:00

77 lines
2.3 KiB
Plaintext

// Module included in the following assemblies:
// serverless-metering.adoc
[id="datasources-metering-serverless_{context}"]
= Datasources for Knative Serving metering
The following `ReportDataSources` are examples of how Knative Serving can be used with {product-title} metering.
[id="knative-service-cpu-usage-ds_{context}"]
== Datasource for CPU usage in Knative Serving
This datasource provides the accumulated CPU seconds used per Knative service over the report time period.
.YAML file
[source,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!=""}
)
----
[id="knative-service-memory-usage-ds_{context}"]
== Datasource for memory usage in Knative Serving
This datasource provides the average memory consumption per Knative service over the report time period.
.YAML file
[source,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!=""}
)
----
[id="applying-datasources-knative_{context}"]
== Applying Datasources for Knative Serving metering
You can apply the `ReportDataSources` by using the following command:
[source,terminal]
----
$ oc apply -f <datasource_name>.yaml
----
.Example
[source,terminal]
----
$ oc apply -f knative-service-memory-usage.yaml
----