Skip to content

Commit

Permalink
OBSDOCS-850-update-CLI-command-to-access-metrics-outside-the-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
bburt-rh committed Feb 29, 2024
1 parent c142e68 commit 04c054c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
33 changes: 20 additions & 13 deletions modules/accessing-metrics-outside-cluster.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,51 @@

Learn how to query Prometheus statistics from the command line when monitoring your own services. You can access monitoring data from outside the cluster with the `thanos-querier` route.

This access only supports using a Bearer Token for authentication.

.Prerequisites

* You deployed your own service, following the _Enabling monitoring for user-defined projects_ procedure.
* You have deployed your own service, following the "Enabling monitoring for user-defined projects" procedure.
* You are logged in to an account that has permission to access the Thanos Querier API.
* You are logged in to an account that has permission to get the Thanos Querier API route.
+
[NOTE]
====
If your account does not have permission to get the Thanos Querier route, a cluster administrator can provide the URL for the route.
====
.Procedure

. Extract a token to connect to Prometheus:
+
[source,terminal]
----
$ SECRET=`oc get secret -n openshift-user-workload-monitoring | grep prometheus-user-workload-token | head -n 1 | awk '{print $1 }'`
----
. Extract an authentication token to connect to Prometheus by running the following command:
+
[source,terminal]
----
$ TOKEN=`echo $(oc get secret $SECRET -n openshift-user-workload-monitoring -o json | jq -r '.data.token') | base64 -d`
$ TOKEN=$(oc whoami -t)
----

. Extract your route host:
. Extract the `thanos-querier` API route URL by running the following command:
+
+
[source,terminal]
----
$ THANOS_QUERIER_HOST=`oc get route thanos-querier -n openshift-monitoring -o json | jq -r '.spec.host'`
$ HOST=$(oc -n openshift-monitoring get route thanos-querier -ojsonpath={.spec.host})
----

. Query the metrics of your own services in the command line. For example:
. Set the namespace to the namespace in which your service is running by using the following command:
+
[source,terminal]
----
$ NAMESPACE=ns1
----

. Query the metrics of your own services in the command line by running the following command:
+
[source,terminal]
----
$ curl -X GET -kG "https://$THANOS_QUERIER_HOST/api/v1/query?" --data-urlencode "query=up{namespace='$NAMESPACE'}" -H "Authorization: Bearer $TOKEN"
$ curl -H "Authorization: Bearer $TOKEN" -k "https://$HOST/api/v1/query?" --data-urlencode "query=up{namespace='$NAMESPACE'}"
----
+
The output will show you the duration that your application pods have been up.
The output shows the status for each application pod that Prometheus is scraping:
+
.Example output
[source,terminal]
Expand Down
5 changes: 5 additions & 0 deletions monitoring/enabling-monitoring-for-user-defined-projects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ include::modules/monitoring-granting-users-permission-to-configure-monitoring-fo
// Accessing metrics from outside the cluster for custom applications
include::modules/accessing-metrics-outside-cluster.adoc[leveloffset=+1]

[role="_additional-resources"]
.Additional resources

* xref:../monitoring/enabling-monitoring-for-user-defined-projects.adoc#enabling-monitoring-for-user-defined-projects_enabling-monitoring-for-user-defined-projects[Enabling monitoring for user-defined projects]
// Excluding a user-defined project from monitoring
include::modules/monitoring-excluding-a-user-defined-project-from-monitoring.adoc[leveloffset=+1]

Expand Down

0 comments on commit 04c054c

Please sign in to comment.