Using Metering

Metering is a deprecated feature. Deprecated functionality is still included in OKD 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 OKD, refer to the Deprecated and removed features section of the OKD release notes.

Prerequisites

  • Install Metering

  • Review the details about the available options that can be configured for a report and how they function.

Writing Reports

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

  1. Change to the openshift-metering project:

    1. $ oc project openshift-metering
  2. Create a Report resource as a YAML file:

    1. Create a YAML file with the following content:

      1. apiVersion: metering.openshift.io/v1
      2. kind: Report
      3. metadata:
      4. name: namespace-cpu-request-2019 (2)
      5. namespace: openshift-metering
      6. spec:
      7. reportingStart: '2019-01-01T00:00:00Z'
      8. reportingEnd: '2019-12-30T23:59:59Z'
      9. query: namespace-cpu-request (1)
      10. runImmediately: true (3)
      1The query specifies the ReportQuery resources used to generate the report. Change this based on what you want to report on. For a list of options, run oc get reportqueries | grep -v raw.
      2Use a descriptive name about what the report does for metadata.name. A good name describes the query, and the schedule or period you used.
      3Set runImmediately to true for it to run with whatever data is available, or set it to false if you want it to wait for reportingEnd to pass.
    2. Run the following command to create the Report resource:

      1. $ oc create -f <file-name>.yaml

      Example output

      1. report.metering.openshift.io/namespace-cpu-request-2019 created
  3. You can list reports and their Running status with the following command:

    1. $ oc get reports

    Example output

    1. NAME QUERY SCHEDULE RUNNING FAILED LAST REPORT TIME AGE
    2. namespace-cpu-request-2019 namespace-cpu-request Finished 2019-12-30T23:59:59Z 26s

Viewing report results

Viewing a report’s results involves querying the reporting API route and authenticating to the API using your OKD 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 the openshift-metering namespace.

Procedure

  1. Change to the openshift-metering project:

    1. $ oc project openshift-metering
  2. Query the reporting API for results:

    1. Create a variable for the metering reporting-api route then get the route:

      1. $ meteringRoute="$(oc get routes metering -o jsonpath='{.spec.host}')"
      1. $ echo "$meteringRoute"
    2. Get the token of your current user to be used in the request:

      1. $ token="$(oc whoami -t)"
    3. Set reportName to the name of the report you created:

      1. $ reportName=namespace-cpu-request-2019
    4. Set reportFormat to one of csv, json, or tabular to specify the output format of the API response:

      1. $ reportFormat=csv
    5. To get the results, use curl to make a request to the reporting API for your report:

      1. $ curl --insecure -H "Authorization: Bearer ${token}" "https://${meteringRoute}/api/v1/reports/get?name=${reportName}&namespace=openshift-metering&format=$reportFormat"

      Example output with reportName=namespace-cpu-request-2019 and reportFormat=csv

      1. period_start,period_end,namespace,pod_request_cpu_core_seconds
      2. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-apiserver,11745.000000
      3. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-apiserver-operator,261.000000
      4. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-authentication,522.000000
      5. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-authentication-operator,261.000000
      6. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-cloud-credential-operator,261.000000
      7. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-cluster-machine-approver,261.000000
      8. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-cluster-node-tuning-operator,3385.800000
      9. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-cluster-samples-operator,261.000000
      10. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-cluster-version,522.000000
      11. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-console,522.000000
      12. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-console-operator,261.000000
      13. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-controller-manager,7830.000000
      14. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-controller-manager-operator,261.000000
      15. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-dns,34372.800000
      16. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-dns-operator,261.000000
      17. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-etcd,23490.000000
      18. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-image-registry,5993.400000
      19. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-ingress,5220.000000
      20. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-ingress-operator,261.000000
      21. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-kube-apiserver,12528.000000
      22. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-kube-apiserver-operator,261.000000
      23. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-kube-controller-manager,8613.000000
      24. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-kube-controller-manager-operator,261.000000
      25. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-machine-api,1305.000000
      26. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-machine-config-operator,9637.800000
      27. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-metering,19575.000000
      28. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-monitoring,6256.800000
      29. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-network-operator,261.000000
      30. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-sdn,94503.000000
      31. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-service-ca,783.000000
      32. 2019-01-01 00:00:00 +0000 UTC,2019-12-30 23:59:59 +0000 UTC,openshift-service-ca-operator,261.000000