Skip to content

Commit 2547de9

Browse files
authored
Merge pull request #31500 from ahardin-rh/OSDOCS-2074
OSDOCS-2074, convert KCS article on accessing metrics from outside the cluster for custom apps
2 parents 757a7fa + a776e2d commit 2547de9

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * monitoring/enabling-monitoring-for-user-defined-projects.adoc
4+
5+
[id="accessing-metrics-from-outside-cluster_{context}"]
6+
= Accessing metrics from outside the cluster for custom applications
7+
8+
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.
9+
10+
.Prerequisites
11+
12+
* You deployed your own service, following the _Enabling monitoring for user-defined projects_ procedure.
13+
14+
.Procedure
15+
16+
. Extract a token to connect to Prometheus:
17+
+
18+
[source,terminal]
19+
----
20+
$ SECRET=`oc get secret -n openshift-user-workload-monitoring | grep prometheus-user-workload-token | head -n 1 | awk '{print $1 }'`
21+
----
22+
+
23+
[source,terminal]
24+
----
25+
$ TOKEN=`echo $(oc get secret $SECRET -n openshift-user-workload-monitoring -o json | jq -r '.data.token') | base64 -d`
26+
----
27+
28+
. Extract your route host:
29+
+
30+
[source,terminal]
31+
----
32+
$ THANOS_QUERIER_HOST=`oc get route thanos-querier -n openshift-monitoring -o json | jq -r '.spec.host'`
33+
----
34+
35+
. Query the metrics of your own services in the command line. For example:
36+
+
37+
[source,terminal]
38+
----
39+
$ NAMESPACE=ns1
40+
----
41+
+
42+
[source,terminal]
43+
----
44+
$ curl -X GET -kG "https://$THANOS_QUERIER_HOST/api/v1/query?" --data-urlencode "query=up{namespace='$NAMESPACE'}" -H "Authorization: Bearer $TOKEN"
45+
----
46+
+
47+
The output will show you the duration that your application pods have been up.
48+
+
49+
.Example output
50+
[source,terminal]
51+
----
52+
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","endpoint":"web","instance":"10.129.0.46:8080","job":"prometheus-example-app","namespace":"ns1","pod":"prometheus-example-app-68d47c4fb6-jztp2","service":"prometheus-example-app"},"value":[1591881154.748,"1"]}]}}
53+
----

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ include::modules/monitoring-granting-user-permissions-using-the-cli.adoc[levelof
2929
// Granting users permission to configure monitoring for user-defined projects
3030
include::modules/monitoring-granting-users-permission-to-configure-monitoring-for-user-defined-projects.adoc[leveloffset=+1]
3131

32+
// Accessing metrics from outside the cluster for custom applications
33+
include::modules/accessing-metrics-outside-cluster.adoc[leveloffset=+1]
34+
3235
// Disabling monitoring for user-defined projects
3336
include::modules/monitoring-disabling-monitoring-for-user-defined-projects.adoc[leveloffset=+1]
3437

0 commit comments

Comments
 (0)