Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Step-by-step guide to configuring alerts in Cluster Observability Operator

December 16, 2024
Christina Zhang
Related topics:
ObservabilityOperators
Related products:
Red Hat OpenShiftRed Hat OpenShift Container Platform

    The first installment in this series provided a brief introduction to the Cluster Observability Operator (COO). This article serves as a detailed guide for configuring alerts within the COO namespace. In the following sections, I will present specific examples for two structural configurations within the COO monitoring stack.

    Case 1: One monitoring stack for multiple namespace. 

    Create a namespace to host the COO instance and utilize this monitoring stack to monitor the namespaces coo-ns2, coo-ns3, and coo-ns4 as shown in Figures 1 and 2.

    COO Monitoring Stack structure.
    Figure 1: COO Monitoring Stack structure.
    One Monitoring Stack for multiple namespace structure.
    Figure 2: One Monitoring Stack for multiple namespace structure.

    Create a project to host the COO monitoring stack. Give a label for the namespace monitoring.rhobs: coo-stack:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: coo-namespace
      labels:
        monitoring.rhobs:coo-stack

    Create a COO monitoring stack, ensuring that the namespaceSelector matches the project label monitoring.rhobs:coo-stack. The resourceSelector should be set to k8s-app: prometheus-coo-example-monitor. This label should match the ServiceMonitor label. See below:

    apiVersion: monitoring.rhobs/v1alpha1
    kind: MonitoringStack
    metadata:
      name: my-coo-monitoring-stack
      namespace: coo-namespace
    spec:
      alertmanagerConfig:
        disabled: false
      logLevel: debug
      namespaceSelector:
        matchLabels:
          monitoring.rhobs: coo-stack
      prometheusConfig:
        replicas: 2
      resourceSelector:
        matchLabels:
          k8s-app: prometheus-coo-example-monitor
      resources:
        limits:
          cpu: 500m
          memory: 512Mi
        requests:
          cpu: 100m
          memory: 256Mi
      retention: 16d

    Set the label app: prometheus-coo-example for the deployment/pod you wish to monitor:

    apiVersion: monitoring.rhobs/v1
    kind: ServiceMonitor
    metadata:
     labels:
       k8s-app: prometheus-coo-example-monitor
     name: coo-servicemonitor-forcoonamespace
     namespace: coo-namespace
    spec:
     endpoints:
     - interval: 30s
       port: web
       scheme: http
     selector:
       matchLabels:
         app: prometheus-coo-example

    Check the info below namespace coo-namespace, shown in Figure 3.

    Info below coo-namespace.
    Figure 3: Info below coo-namespace.

    Create the namespace coo-ns2, also with label monitoring.rhobs: coo-stack:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: coo-ns2
      labels:
        monitoring.rhobs: coo-stack

    Run a Deployment:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: prometheus-coo-example
      name: coo-example-app2
      namespace: coo-ns2
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: prometheus-coo-example
      template:
        metadata:
          labels:
            app: prometheus-coo-example
        spec:
          containers:
          - image: ghcr.io/rhobs/prometheus-example-app:0.4.2
            imagePullPolicy: IfNotPresent
            name: coo-example-app2

    Create a Service:

    apiVersion: v1
    kind: Service
    metadata:
      labels:
       app: prometheus-coo-example
      name: coo-example-service-app2 # alter 条件是这个
      namespace: coo-ns2
    spec:
      ports:
      - port: 8080
        protocol: TCP
        targetPort: 8080
        name: web
      selector:
        app: prometheus-coo-example
      type: ClusterIP

    Also create a Service Monitor:

    apiVersion: monitoring.rhobs/v1
    kind: ServiceMonitor
    metadata:
      labels:
        k8s-app: prometheus-coo-example-monitor
      name: prometheus-coo-example-servicemonitor2
      namespace: coo-ns2
    spec:
      endpoints:
      - interval: 30s
        port: web
        scheme: http
      selector:
        matchLabels:
          app: prometheus-coo-example

    Create a PrometheusRule and place the label k8s-app: prometheus-coo-example-monitor:

    apiVersion: monitoring.rhobs/v1
    kind: PrometheusRule
    metadata:
      name: coo-alert2
      namespace: coo-ns2
      labels:
        k8s-app: prometheus-coo-example-monitor
    spec:
      groups:
      - name: example
        rules:
        - alert: VersionAlert
          for: 1m
          expr: version{job="coo-example-service-app2"} > 0 
          labels:
            severity: warning

    Use the same method to create coo-ns3 and coo-ns4.

    To verify it the alert has been configured correctly, try oc get all. Find the svc. In my case, mine is my-coo-monitoring-stack-prometheus. See Figure 4.

    Locate my-coo-monitoring-stack-prometheus.
    Figure 4: Locate my-coo-monitoring-stack-prometheus.
    oc port-forward svc/my-coo-monitoring-stack-prometheus 9090:9090 --address 0.0.0.0 -n coo-namespace

    Try:

    localhost:9090

    You will see a Prometheus UI Page. Click Alert and you should find the alert there. See Figure 5.

    Prometheus Alerts page.
    Figure 5: Prometheus Alerts page.

    Next, let's move on and examine case 2. The structure in this example is shown in Figures 6 and 7.

    Monitoring Stack for single project structure.
    Figure 6: Monitoring Stack for single project structure.
    A COO Monitoring Stack project structure.
    Figure 7: A COO Monitoring Stack project structure.

    Case 2: Deploy the monitoring stack at the namespace you wish to monitor

    In this instance, deploy the monitoring stack below namespace coo-ns1.

    If you already had the namespace, assign a label for the namespace. If not, create a namespace, then make deployment and configure alerts for the namespace. Give a label for the namespace monitoring.rhobs: coo-stack:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: coo-ns1
      labels:
        monitoring.rhobs: coo-stack

    Next, create a monitoringStack. Make sure the namespaceSelector is monitoring.rhobs: coo-stack, the same as the namespace label. Give a label k8s-app: prometheus-coo-example-monitor to resourceSelector:

    apiVersion: monitoring.rhobs/v1alpha1
    kind: MonitoringStack
    metadata:
      name: my-coo-monitoring-stack
      namespace: coo-ns1
    spec:
      alertmanagerConfig:
        disabled: false
      logLevel: debug
      namespaceSelector:
        matchLabels:
          monitoring.rhobs: coo-stack
      prometheusConfig:
        replicas: 2
      resourceSelector:
        matchLabels:
          k8s-app: prometheus-coo-example-monitor
      resources:
        limits:
          cpu: 500m
          memory: 512Mi
        requests:
          cpu: 100m
          memory: 256Mi
      retention: 16d

    Create a ServiceMonitor. Give the label k8s-app: prometheus-coo-example-monitor. Also give a label app: prometheus-coo-example used for the deployment, service, and pod:

    apiVersion: monitoring.rhobs/v1
    kind: ServiceMonitor
    metadata:
     labels:
       k8s-app: prometheus-coo-example-monitor
     name: coo-servicemonitor-forcoonamespace
     namespace: coo-ns1
    spec:
     endpoints:
     - interval: 30s
       port: web
       scheme: http
     selector:
       matchLabels:
         app: prometheus-coo-example

    Create a Service. Use the same label app: prometheus-coo-example:

    apiVersion: v1
    kind: Service
    metadata:
      labels:
       app: prometheus-coo-example
      name: coo-example-service-app1 
      namespace: coo-ns1
    spec:
      ports:
      - port: 8080
        protocol: TCP
        targetPort: 8080
        name: web
      selector:
        app: prometheus-coo-example
      type: ClusterIP

    Create a Deployment. Use the same label  app: prometheus-coo-example:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: prometheus-coo-example
      name: coo-example-app1
      namespace: coo-ns1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: prometheus-coo-example
      template:
        metadata:
          labels:
            app: prometheus-coo-example
        spec:
          containers:
          - image: ghcr.io/rhobs/prometheus-example-app:0.4.2
            imagePullPolicy: IfNotPresent
            name: coo-example-app1

    Create a PrometheusRule. It is to configure the alert you wish to fire once you trigger the condition. Use the label k8s-app: prometheus-coo-example-monitor  from the previous configuration:

    apiVersion: monitoring.rhobs/v1
    kind: PrometheusRule
    metadata:
      name: coo-alert1
      namespace: coo-ns1
      labels:
        k8s-app: prometheus-coo-example-monitor
    spec:
      groups:
      - name: example
        rules:
        - alert: VersionAlert
          for: 1m
          expr: version{job="coo-example-service-app1"} > 0 
          labels:
            severity: warning

    To verify it the alert has been configured correctly, try oc get all. Find the svc. In my case, mine is my-coo-monitoring-stack-prometheus:

    kubectl port-forward svc/my-coo-monitoring-stack-prometheus 9090:9090 --address 0.0.0.0 -n coo-ns1 

    Try:

    localhost:9090

    You will see a Prometheus UI Page. Click Alert and you should find the alert there. 

    This guide provides you with a step-by-step understanding of the procedure. You can modify the the configuration to satisfy your business requirements.

    Related Posts

    • Get started with the OpenShift Cluster Observability Operator

    • Set up an OpenShift cluster to deploy an application in odo CLI

    • How to manage a fleet of heterogeneous OpenShift clusters

    • Enable etcd backups for OpenShift clusters in hybrid cloud environments

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    What’s up next?

    Learn how to install the oc command-line interface (CLI) in order to work with your Red Hat OpenShift cluster from a command line.

    Start the activity
    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI