|
8 | 8 |
|
9 | 9 | 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.
|
10 | 10 |
|
| 11 | +This access only supports using a Bearer Token for authentication. |
| 12 | + |
11 | 13 | .Prerequisites
|
12 | 14 |
|
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 | +==== |
14 | 23 |
|
15 | 24 | .Procedure
|
16 | 25 |
|
17 |
| -. Extract a token to connect to Prometheus: |
| 26 | +. Extract an authentication token to connect to Prometheus by running the following command: |
18 | 27 | +
|
19 | 28 | [source,terminal]
|
20 | 29 | ----
|
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) |
27 | 31 | ----
|
28 | 32 |
|
29 |
| -. Extract your route host: |
| 33 | +. Extract the `thanos-querier` API route URL by running the following command: |
30 | 34 | +
|
31 | 35 | [source,terminal]
|
32 | 36 | ----
|
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}) |
34 | 38 | ----
|
35 | 39 |
|
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: |
37 | 41 | +
|
38 | 42 | [source,terminal]
|
39 | 43 | ----
|
40 | 44 | $ NAMESPACE=ns1
|
41 | 45 | ----
|
| 46 | + |
| 47 | +. Query the metrics of your own services in the command line by running the following command: |
42 | 48 | +
|
43 | 49 | [source,terminal]
|
44 | 50 | ----
|
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'}" |
46 | 52 | ----
|
47 | 53 | +
|
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: |
49 | 55 | +
|
50 | 56 | .Example output
|
51 | 57 | [source,terminal]
|
|
0 commit comments