Skip to content

Application Monitoring example

Deploy cluster wide workload monitoring (cluster-admin needed)

Enabling monitoring for user-defined projects

Enable user workload monitoring

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
oc create -f - <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
  name: cluster-monitoring-config
  namespace: openshift-monitoring
data:
  config.yaml: |
    enableUserWorkload: true
EOF

Check user workload monitoring stack

1
2
3
4
5
6
7
$ oc get pods -n openshift-user-workload-monitoring
NAME                                   READY   STATUS    RESTARTS   AGE
prometheus-operator-84d9857947-wlmws   2/2     Running   0          49s
prometheus-user-workload-0             5/5     Running   1          37s
prometheus-user-workload-1             5/5     Running   1          37s
thanos-ruler-user-workload-0           3/3     Running   0          38s
thanos-ruler-user-workload-1           3/3     Running   0          37s

Granting permission

Deploy application

Official example

1
oc apply -f https://examples.openshift.pub/deploy/monitoring/workload/deployment.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: opensift-examples
  name: opensift-examples
spec:
  ports:
  - name: http
    port: 8080
    protocol: TCP
    targetPort: 8080
  - name: metrics
    port: 9113
    protocol: TCP
    targetPort: 9113
  selector:
    app: opensift-examples
  type: ClusterIP
status:
  loadBalancer: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations: null
  labels:
    app: opensift-examples
    app.kubernetes.io/component: opensift-examples
    app.kubernetes.io/instance: opensift-examples
    app.kubernetes.io/part-of: opensift-examples
    app.openshift.io/runtime: openshift
  name: opensift-examples
spec:
  progressDeadlineSeconds: 30
  replicas: 1
  selector:
    matchLabels:
      app: opensift-examples
  template:
    metadata:
      labels:
        app: opensift-examples
    spec:
      containers:
      - image: quay.io/openshift-examples/web:master
        name: web
        ports:
        - containerPort: 8080
          name: http
        readinessProbe:
          httpGet:
            path: /
            port: 8081
      - args:
        - -nginx.scrape-uri=http://localhost:8081/
        image: docker.io/nginx/nginx-prometheus-exporter:latest
        name: nginx-prometheus-exporter
        ports:
        - containerPort: 9113
          name: metrics
        readinessProbe:
          httpGet:
            path: /
            port: 9113

Create Service Monitoring

1
oc apply -f https://examples.openshift.pub/deploy/monitoring/workload/servicemonitor.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app: opensift-examples
  name: opensift-examples
spec:
  endpoints:
  - interval: 30s
    port: metrics
    scheme: http
  selector:
    matchLabels:
      app: opensift-examples

Result

Screenshot


Last update: July 15, 2021
Back to top