This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 6. Using Metering
Metering is a deprecated feature. Deprecated functionality is still included in OpenShift Container Platform and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.
For the most recent list of major functionality that has been deprecated or removed within OpenShift Container Platform, refer to the Deprecated and removed features section of the OpenShift Container Platform release notes.
6.1. Prerequisites Link kopierenLink in die Zwischenablage kopiert!
- Install Metering
- Review the details about the available options that can be configured for a report and how they function.
6.2. Writing Reports Link kopierenLink in die Zwischenablage kopiert!
Writing a report is the way to process and analyze data using metering.
To write a report, you must define a Report resource in a YAML file, specify the required parameters, and create it in the openshift-metering namespace.
Prerequisites
- Metering is installed.
Procedure
Change to the
openshift-meteringproject:oc project openshift-metering
$ oc project openshift-meteringCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
Reportresource as a YAML file:Create a YAML file with the following content:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 2
- The
queryspecifies theReportQueryresources used to generate the report. Change this based on what you want to report on. For a list of options, runoc get reportqueries | grep -v raw. - 1
- Use a descriptive name about what the report does for
metadata.name. A good name describes the query, and the schedule or period you used. - 3
- Set
runImmediatelytotruefor it to run with whatever data is available, or set it tofalseif you want it to wait forreportingEndto pass.
Run the following command to create the
Reportresource:oc create -f <file-name>.yaml
$ oc create -f <file-name>.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
report.metering.openshift.io/namespace-cpu-request-2020 created
report.metering.openshift.io/namespace-cpu-request-2020 createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
You can list reports and their
Runningstatus with the following command:oc get reports
$ oc get reportsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME QUERY SCHEDULE RUNNING FAILED LAST REPORT TIME AGE namespace-cpu-request-2020 namespace-cpu-request Finished 2020-12-30T23:59:59Z 26s
NAME QUERY SCHEDULE RUNNING FAILED LAST REPORT TIME AGE namespace-cpu-request-2020 namespace-cpu-request Finished 2020-12-30T23:59:59Z 26sCopy to Clipboard Copied! Toggle word wrap Toggle overflow
6.3. Viewing report results Link kopierenLink in die Zwischenablage kopiert!
Viewing a report’s results involves querying the reporting API route and authenticating to the API using your OpenShift Container Platform credentials. Reports can be retrieved as JSON, CSV, or Tabular formats.
Prerequisites
- Metering is installed.
-
To access report results, you must either be a cluster administrator, or you need to be granted access using the
report-exporterrole in theopenshift-meteringnamespace.
Procedure
Change to the
openshift-meteringproject:oc project openshift-metering
$ oc project openshift-meteringCopy to Clipboard Copied! Toggle word wrap Toggle overflow Query the reporting API for results:
Create a variable for the metering
reporting-apiroute then get the route:meteringRoute="$(oc get routes metering -o jsonpath='{.spec.host}')"$ meteringRoute="$(oc get routes metering -o jsonpath='{.spec.host}')"Copy to Clipboard Copied! Toggle word wrap Toggle overflow echo "$meteringRoute"
$ echo "$meteringRoute"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the token of your current user to be used in the request:
token="$(oc whoami -t)"
$ token="$(oc whoami -t)"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set
reportNameto the name of the report you created:reportName=namespace-cpu-request-2020
$ reportName=namespace-cpu-request-2020Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set
reportFormatto one ofcsv,json, ortabularto specify the output format of the API response:reportFormat=csv
$ reportFormat=csvCopy to Clipboard Copied! Toggle word wrap Toggle overflow To get the results, use
curlto make a request to the reporting API for your report:curl --insecure -H "Authorization: Bearer ${token}" "https://${meteringRoute}/api/v1/reports/get?name=${reportName}&namespace=openshift-metering&format=$reportFormat"$ curl --insecure -H "Authorization: Bearer ${token}" "https://${meteringRoute}/api/v1/reports/get?name=${reportName}&namespace=openshift-metering&format=$reportFormat"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output with
reportName=namespace-cpu-request-2020andreportFormat=csvCopy to Clipboard Copied! Toggle word wrap Toggle overflow