Skip to content

Commit 89ed165

Browse files
authored
Merge pull request #95251 from gabriel-rh/OBSDOCS-2004
OBSDOCS-2004 scrape targets in multiple namespaces
2 parents c13644c + 96d416d commit 89ed165

File tree

2 files changed

+209
-1
lines changed

2 files changed

+209
-1
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * observability/cluster-observability-operator/configuring-the-cluster-observability-operator-to-monitor-a-service.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="monitoring-scrape-targets-in-multiple-namespaces_{context}"]
7+
= Scrape targets in multiple namespaces
8+
9+
To scrape targets in multiple namespaces, set the namespace and resource selector in the `MonitoringStack` object.
10+
11+
.Prerequisites
12+
13+
* You have access to the cluster as a user with the `cluster-admin` cluster role or as a user with administrative permissions for the namespace.
14+
* You have installed the {coo-full}.
15+
16+
.Procedure
17+
18+
. Deploy the following namespace object and `MonitoringStack` YAML file:
19+
+
20+
.Example `MonitoringStack`
21+
[source,yaml]
22+
----
23+
apiVersion: v1
24+
kind: Namespace
25+
metadata:
26+
name: ns1-coo
27+
labels:
28+
monitoring.rhobs/stack: multi-ns
29+
---
30+
apiVersion: monitoring.rhobs/v1alpha1
31+
kind: MonitoringStack
32+
metadata:
33+
name: example-coo-monitoring-stack
34+
namespace: ns1-coo
35+
spec:
36+
logLevel: debug
37+
retention: 1d
38+
resourceSelector:
39+
matchLabels:
40+
k8s-app: prometheus-coo-example-monitor
41+
namespaceSelector:
42+
matchLabels:
43+
monitoring.rhobs/stack: multi-ns
44+
----
45+
46+
. Deploy a sample application in the namespace `ns1-coo`, with an alert that is always firing:
47+
+
48+
[source,yaml]
49+
----
50+
apiVersion: apps/v1
51+
kind: Deployment
52+
metadata:
53+
labels:
54+
app: prometheus-coo-example-app
55+
name: prometheus-coo-example-app
56+
namespace: ns1-coo
57+
spec:
58+
replicas: 1
59+
selector:
60+
matchLabels:
61+
app: prometheus-coo-example-app
62+
template:
63+
metadata:
64+
labels:
65+
app: prometheus-coo-example-app
66+
spec:
67+
containers:
68+
- image: ghcr.io/rhobs/prometheus-example-app:0.4.2
69+
imagePullPolicy: IfNotPresent
70+
name: prometheus-coo-example-app
71+
---
72+
apiVersion: v1
73+
kind: Service
74+
metadata:
75+
labels:
76+
app: prometheus-coo-example-app
77+
name: prometheus-coo-example-app
78+
namespace: ns1-coo
79+
spec:
80+
ports:
81+
- port: 8080
82+
protocol: TCP
83+
targetPort: 8080
84+
name: web
85+
selector:
86+
app: prometheus-coo-example-app
87+
type: ClusterIP
88+
---
89+
apiVersion: monitoring.rhobs/v1
90+
kind: ServiceMonitor
91+
metadata:
92+
labels:
93+
k8s-app: prometheus-coo-example-monitor
94+
name: prometheus-coo-example-monitor
95+
namespace: ns1-coo
96+
spec:
97+
endpoints:
98+
- interval: 30s
99+
port: web
100+
scheme: http
101+
selector:
102+
matchLabels:
103+
app: prometheus-coo-example-app
104+
---
105+
apiVersion: monitoring.rhobs/v1
106+
kind: PrometheusRule
107+
metadata:
108+
name: example-alert
109+
namespace: ns1-coo
110+
labels:
111+
k8s-app: prometheus-coo-example-monitor
112+
spec:
113+
groups:
114+
- name: example
115+
rules:
116+
- alert: VersionAlert
117+
for: 1m
118+
expr: version{job="prometheus-coo-example-app"} > 0
119+
labels:
120+
severity: warning
121+
----
122+
123+
. Deploy the same example application in another namespace labeled with `monitoring.rhobs/stack: multi-ns`:
124+
+
125+
[source,yaml]
126+
----
127+
apiVersion: v1
128+
kind: Namespace
129+
metadata:
130+
name: ns2-coo
131+
labels:
132+
monitoring.rhobs/stack: multi-ns
133+
---
134+
apiVersion: apps/v1
135+
kind: Deployment
136+
metadata:
137+
labels:
138+
app: prometheus-coo-example-app
139+
name: prometheus-coo-example-app
140+
namespace: ns2-coo
141+
spec:
142+
replicas: 1
143+
selector:
144+
matchLabels:
145+
app: prometheus-coo-example-app
146+
template:
147+
metadata:
148+
labels:
149+
app: prometheus-coo-example-app
150+
spec:
151+
containers:
152+
- image: ghcr.io/rhobs/prometheus-example-app:0.4.2
153+
imagePullPolicy: IfNotPresent
154+
name: prometheus-coo-example-app
155+
---
156+
apiVersion: v1
157+
kind: Service
158+
metadata:
159+
labels:
160+
app: prometheus-coo-example-app
161+
name: prometheus-coo-example-app
162+
namespace: ns2-coo
163+
spec:
164+
ports:
165+
- port: 8080
166+
protocol: TCP
167+
targetPort: 8080
168+
name: web
169+
selector:
170+
app: prometheus-coo-example-app
171+
type: ClusterIP
172+
---
173+
apiVersion: monitoring.rhobs/v1
174+
kind: ServiceMonitor
175+
metadata:
176+
labels:
177+
k8s-app: prometheus-coo-example-monitor
178+
name: prometheus-coo-example-monitor
179+
namespace: ns2-coo
180+
spec:
181+
endpoints:
182+
- interval: 30s
183+
port: web
184+
scheme: http
185+
selector:
186+
matchLabels:
187+
app: prometheus-coo-example-app
188+
----
189+
190+
.Verification
191+
192+
. Verify that the Prometheus instance adds new targets and that the alert are firing. Use a port-forward command to expose the Prometheus or the Alertmanager user interface that has been deployed by the `Monitoringstack` instance.
193+
+
194+
.Prometheus
195+
[source,terminal]
196+
----
197+
$ oc port-forward -n ns1-coo pod/prometheus-example-coo-monitoring-stack-0 9090
198+
----
199+
+
200+
.Alertmanager
201+
[source,terminal]
202+
----
203+
$ oc port-forward -n ns1-coo pod/alertmanager-example-coo-monitoring-stack-0 9093
204+
----
205+
206+
. Verify that the targets are being scraped and that the alerts are firing by browsing to `http://localhost:9090/targets` or `http://localhost:9093/#/alerts`.

observability/cluster_observability_operator/configuring-the-cluster-observability-operator-to-monitor-a-service.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ include::modules/monitoring-specifying-how-a-service-is-monitored-by-cluster-obs
2323
// Create a MonitoringStack object to discover the service monitor
2424
include::modules/monitoring-creating-a-monitoringstack-object-for-cluster-observability-operator.adoc[leveloffset=+1]
2525

26-
// Validate a MonitoringStack
26+
// Validate a MonitoringStack
2727
include::modules/monitoring-validating-a-monitoringstack-for-cluster-observability-operator.adoc[leveloffset=+1]
2828

29+
// Scrape targets in multiple namespaces
30+
include::modules/monitoring-scrape-targets-in-multiple-namespaces.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)