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.Questo contenuto non è disponibile nella lingua selezionata.
Chapter 5. Using Metering
5.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
- Install Metering
- Review the details about the available options that can be configured for a Report and how they function.
5.2. Writing Reports Copia collegamentoCollegamento copiato negli appunti!
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 by using oc
.
Prerequisites
- Metering is installed.
Procedure
Change to the
openshift-metering
project:oc project openshift-metering
$ oc project openshift-metering
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a Report resource as a YAML file:
Create a YAML file with the following content:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 2
- The
query
specifies ReportQuery 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 is the query, and the schedule or period you used. - 3
- Set
runImmediately
totrue
for it to run with whatever data is available, or set it tofalse
if you want it to wait forreportingEnd
to pass.
Run the following command to create the Report:
oc create -f <file-name>.yaml
$ oc create -f <file-name>.yaml report.metering.openshift.io/namespace-cpu-request-2019 created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
You can list Reports and their
Running
status with the following command:oc get reports
$ oc get reports NAME QUERY SCHEDULE RUNNING FAILED LAST REPORT TIME AGE namespace-cpu-request-2019 namespace-cpu-request Finished 2019-12-30T23:59:59Z 26s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.3. Viewing Report results Copia collegamentoCollegamento copiato negli appunti!
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-exporter
role in theopenshift-metering
namespace.
Procedure
Change to the
openshift-metering
project:oc project openshift-metering
$ oc project openshift-metering
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Query the reporting API for results:
Get the route to the
reporting-api
:meteringRoute="$(oc get routes metering -o jsonpath='{.spec.host}')" echo "$meteringRoute"
$ meteringRoute="$(oc get routes metering -o jsonpath='{.spec.host}')" $ 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 To get the results, use
curl
to make a request to the reporting API for your report:reportName=namespace-cpu-request-2019 reportFormat=csv curl --insecure -H "Authorization: Bearer ${token}" "https://${meteringRoute}/api/v1/reports/get?name=${reportName}&namespace=openshift-metering&format=$reportFormat"
$ reportName=namespace-cpu-request-2019
1 $ reportFormat=csv
2 $ 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 The response should look similar to the following (example output is with
reportName=namespace-cpu-request-2019
andreportFormat=csv
):Copy to Clipboard Copied! Toggle word wrap Toggle overflow