////
This PROCEDURE module included in the following assemblies:
- ossm-tutorial-prometheus.adoc
////

:_mod-docs-content-type: PROCEDURE
[id="ossm-tutorial-prometheus-querying-metrics_{context}"]
= Querying Prometheus metrics

This tutorial uses {SMProductShortName} and the `bookinfo` tutorial to demonstrate how you can query for metrics using Prometheus.

.Prerequisites

* {product-title} 3.11 or higher installed.
* {SMProductName} {SMProductVersion} installed.
* `Bookinfo` demonstration application installed.

After you have verified the Bookinfo application has deployed, you will need to generate calls to the application before you query for metrics.

.Procedure

. Verify that the `prometheus` Service is running in your cluster. In this example, `istio-system` is the name of the control plane project. Execute the following command:
+
[source,terminal]
----
$ oc get svc prometheus -n istio-system
----
+
.Example output
[source,terminal]
----
NAME         CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
prometheus   10.59.241.54   <none>        9090/TCP   2m
----
+
. Generate network traffic by accessing the Bookinfo application:
+
[source,terminal]
----
$ curl -o /dev/null http://$GATEWAY_URL/productpage
----
+
. A route to access the Prometheus user interface already exists. Query for details of the route:
+
[source,terminal]
----
$ export PROMETHEUS_URL=$(oc get route -n istio-system prometheus -o jsonpath='{.spec.host}')
----
+
. Launch a browser and navigate to  `http://<PROMETHEUS_URL>`. You will see the Prometheus home screen, similar to the following figure:
+
image::ossm-prometheus-home-screen.png[]
+
. In the *Expression* field, enter `istio_request_duration_seconds_count`, and click `Execute`. You will see a screen similar to the following figure:
+
image::ossm-prometheus-metrics.png[]
+
. You can narrow down queries by using selectors. For example `istio_request_duration_seconds_count{destination_workload="reviews-v2"}`  shows only counters with the matching *destination_workload* label. For more information about using queries, see the link:https://prometheus.io/docs/prometheus/latest/querying/basics/#instant-vector-selectors[Prometheus documentation].
+
. To list all available Prometheus metrics, run the following command:
+
[source,terminal]
----
$ oc get prometheus -n istio-system -o jsonpath='{.items[*].spec.metrics[*].name}' requests_total request_duration_seconds request_bytes response_bytes tcp_sent_bytes_total tcp_received_bytes_total
----
+
Note that returned metric names must be prepended with `istio_` when used in queries, for example,  `requests_total` is `istio_requests_total`.
