Skip to content

Application Monitoring example

Deploy cluster wide workload monitoring (cluster-admin needed)

Enabling monitoring for user-defined projects

Enable user workload monitoring

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

oc apply -f https://examples.openshift.pub/deploy/monitoring/workload/deployment.yaml
---
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

oc apply -f https://examples.openshift.pub/deploy/monitoring/workload/servicemonitor.yaml
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


2021-07-15 2020-07-30 Contributors: Robert Bohne