This is a cache of https://docs.okd.io/latest/observability/monitoring/accessing-metrics/accessing-metrics-as-a-developer.html. It is a snapshot of the page at 2025-02-18T19:11:41.470+0000.
Accessing metrics as a developer - Monitoring | Observability | OKD 4
×

Viewing a list of available metrics

As a cluster administrator or as a user with view permissions for all projects, you can view a list of metrics available in a cluster and output the list in JSON format.

Prerequisites
  • You are a cluster administrator, or you have access to the cluster as a user with the cluster-monitoring-view cluster role.

  • You have installed the OKD CLI (oc).

  • You have obtained the OKD API route for Thanos Querier.

  • You are able to get a bearer token by using the oc whoami -t command.

    You can only use bearer token authentication to access the Thanos Querier API route.

Procedure
  1. If you have not obtained the OKD API route for Thanos Querier, run the following command:

    $ oc get routes -n openshift-monitoring thanos-querier -o jsonpath='{.status.ingress[0].host}'
  2. Retrieve a list of metrics in JSON format from the Thanos Querier API route by running the following command. This command uses oc to authenticate with a bearer token.

    $ curl -k -H "Authorization: Bearer $(oc whoami -t)" https://<thanos_querier_route>/api/v1/metadata (1)
    1 Replace <thanos_querier_route> with the OKD API route for Thanos Querier.

Querying metrics for user-defined projects with the OKD web console

You can use the OKD metrics query browser to run Prometheus Query Language (PromQL) queries to examine metrics visualized on a plot. This functionality provides information about any user-defined workloads that you are monitoring.

As a developer, you must specify a project name when querying metrics. You must have the required privileges to view metrics for the selected project.

The Metrics UI includes predefined queries, for example, CPU, memory, bandwidth, or network packet. These queries are restricted to the selected project. You can also run custom Prometheus Query Language (PromQL) queries for the project.

Developers can only use the Developer perspective and not the Administrator perspective. As a developer, you can only query metrics for one project at a time.

Prerequisites
  • You have access to the cluster as a developer or as a user with view permissions for the project that you are viewing metrics for.

  • You have enabled monitoring for user-defined projects.

  • You have deployed a service in a user-defined project.

  • You have created a ServiceMonitor custom resource definition (CRD) for the service to define how the service is monitored.

Procedure
  1. In the Developer perspective of the OKD web console, click Observe and go to the Metrics tab.

  2. Select the project that you want to view metrics for from the Project: list.

  3. To add one or more queries, perform any of the following actions:

    Option Description

    Select an existing query.

    From the Select query drop-down list, select an existing query.

    Create a custom query.

    Add your Prometheus Query Language (PromQL) query to the Expression field.

    As you type a PromQL expression, autocomplete suggestions appear in a drop-down list. These suggestions include functions, metrics, labels, and time tokens. Use the keyboard arrows to select one of these suggested items and then press Enter to add the item to your expression. Move your mouse pointer over a suggested item to view a brief description of that item.

    Add multiple queries.

    Click Add query.

    Duplicate an existing query.

    Click the options menu kebab next to the query, then choose Duplicate query.

    Disable a query from being run.

    Click the options menu kebab next to the query and choose Disable query.

  4. To run queries that you created, click Run queries. The metrics from the queries are visualized on the plot. If a query is invalid, the UI shows an error message.

    • When drawing time series graphs, queries that operate on large amounts of data might time out or overload the browser. To avoid this, click Hide graph and calibrate your query by using only the metrics table. Then, after finding a feasible query, enable the plot to draw the graphs.

    • By default, the query table shows an expanded view that lists every metric and its current value. Click the ˅ down arrowhead to minimize the expanded view for a query.

  5. Optional: Save the page URL to use this set of queries again in the future.

  6. Explore the visualized metrics. Initially, all metrics from all enabled queries are shown on the plot. Select which metrics are shown by performing any of the following actions:

    Option Description

    Hide all metrics from a query.

    Click the options menu kebab for the query and click Hide all series.

    Hide a specific metric.

    Go to the query table and click the colored square near the metric name.

    Zoom into the plot and change the time range.

    Perform one of the following actions:

    • Visually select the time range by clicking and dragging on the plot horizontally.

    • Use the menu to select the time range.

    Reset the time range.

    Click Reset zoom.

    Display outputs for all queries at a specific point in time.

    Hover over the plot at the point you are interested in. The query outputs appear in a pop-up box.

    Hide the plot.

    Click Hide graph.

Additional resources

Reviewing monitoring dashboards as a developer

In the Developer perspective, you can view dashboards relating to a selected project.

In the Developer perspective, you can view dashboards for only one project at a time.

Prerequisites
  • You have access to the cluster as a developer or as a user.

  • You have view permissions for the project that you are viewing the dashboard for.

Procedure
  1. In the Developer perspective in the OKD web console, click Observe and go to the Dashboards tab.

  2. Select a project from the Project: drop-down list.

  3. Select a dashboard from the Dashboard drop-down list to see the filtered metrics.

    All dashboards produce additional sub-menus when selected, except Kubernetes / Compute Resources / Namespace (Pods).

  4. Optional: Select a time range for the graphs in the Time Range list.

    • Select a pre-defined time period.

    • Set a custom time range by clicking Custom time range in the Time Range list.

      1. Input or select the From and To dates and times.

      2. Click Save to save the custom time range.

  5. Optional: Select a Refresh Interval.

  6. Hover over each of the graphs within a dashboard to display detailed information about specific items.