Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBSDOCS-850: update CLI commands to access metrics outside the cluster for UWM #72176

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions modules/accessing-metrics-outside-cluster.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,50 @@

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 with the `cluster-monitoring-view` cluster role, which provides 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 API route, a cluster administrator can provide the URL for the route.
====

.Procedure

. Extract a token to connect to Prometheus:
. Extract an authentication token to connect to Prometheus by running the following command:
+
[source,terminal]
----
$ SECRET=`oc get secret -n openshift-user-workload-monitoring | grep prometheus-user-workload-token | head -n 1 | awk '{print $1 }'`
----
+
[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