Skip to content

Commit 6e7f92f

Browse files
authored
Merge pull request #72176 from bburt-rh/OBSDOCS-850-update-CLI-command-to-access-metrics-outside-the-cluster
OBSDOCS-850: update CLI commands to access metrics outside the cluster for UWM
2 parents 46e063f + 61599bb commit 6e7f92f

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

modules/accessing-metrics-outside-cluster.adoc

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,50 @@
88

99
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.
1010

11+
This access only supports using a Bearer Token for authentication.
12+
1113
.Prerequisites
1214

13-
* You deployed your own service, following the _Enabling monitoring for user-defined projects_ procedure.
15+
* You have deployed your own service, following the "Enabling monitoring for user-defined projects" procedure.
16+
* You are logged in to an account with the `cluster-monitoring-view` cluster role, which provides permission to access the Thanos Querier API.
17+
* You are logged in to an account that has permission to get the Thanos Querier API route.
18+
+
19+
[NOTE]
20+
====
21+
If your account does not have permission to get the Thanos Querier API route, a cluster administrator can provide the URL for the route.
22+
====
1423
1524
.Procedure
1625

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

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

36-
. Query the metrics of your own services in the command line. For example:
40+
. Set the namespace to the namespace in which your service is running by using the following command:
3741
+
3842
[source,terminal]
3943
----
4044
$ NAMESPACE=ns1
4145
----
46+
47+
. Query the metrics of your own services in the command line by running the following command:
4248
+
4349
[source,terminal]
4450
----
45-
$ curl -X GET -kG "https://$THANOS_QUERIER_HOST/api/v1/query?" --data-urlencode "query=up{namespace='$NAMESPACE'}" -H "Authorization: Bearer $TOKEN"
51+
$ curl -H "Authorization: Bearer $TOKEN" -k "https://$HOST/api/v1/query?" --data-urlencode "query=up{namespace='$NAMESPACE'}"
4652
----
4753
+
48-
The output will show you the duration that your application pods have been up.
54+
The output shows the status for each application pod that Prometheus is scraping:
4955
+
5056
.Example output
5157
[source,terminal]

monitoring/enabling-monitoring-for-user-defined-projects.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ include::modules/monitoring-granting-users-permission-to-configure-monitoring-fo
3131
// Accessing metrics from outside the cluster for custom applications
3232
include::modules/accessing-metrics-outside-cluster.adoc[leveloffset=+1]
3333

34+
[role="_additional-resources"]
35+
.Additional resources
36+
37+
* 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]
38+
3439
// Excluding a user-defined project from monitoring
3540
include::modules/monitoring-excluding-a-user-defined-project-from-monitoring.adoc[leveloffset=+1]
3641

0 commit comments

Comments
 (0)