Cyber Deals - Get up to 65% off on CKA, CKAD, CKS, KCNA, KCSA exams and courses!

OpenShift 4: Query Prometheus API for Firing Alert

Introduction

Prometheus is a robust, efficient and cloud native monitoring tools, graduated from CNCF incubator. It was part of the OpenShift since OpenShift 3.11. In OpenShift 4.x it become part of the platform core component.

In this quick blog, we will show you how to query OpenShift Prometheus API that already being exposed by route. This is very useful for external monitoring integration solution like Nagios active check that can query Prometheus for firing alert.

How to get this done?

First you need an authorization bearer token. In this blog we will use short-lived user token, however for proper integration, we can use ServiceAccount long-lived token with assigned RBAC.

# export TOKEN=$( oc whoami -t)
# export URL=https://prometheus-k8s-openshift-monitoring.apps.ocp4.local.bytewise.my

#curl -s -g -k -X GET -H "Authorization: Bearer $TOKEN" -H 'Accept: application/json' -H 'Content-Type: application/json' "$URL/api/v1/alerts" | jq  -c '.data.alerts[] | select( .state == "firing" and .labels.severity == "critical")'

OUTPUT:
{"labels":{"alertname":"KubeAPIErrorsHigh","resource":"events","severity":"critical","verb":"LIST"},"annotations":{"message":"API server is returning errors for 45.45% of requests for LIST events ."},"state":"firing","activeAt":"2020-11-04T04:12:20.907806203Z","value":"4.545454545454545e-01"}

For full and official Prometheus API documentation, we may refer to https://prometheus.io/docs/prometheus/latest/querying/api/.

Muhammad Aizuddin Zali

Muhammad Aizuddin Zali

RHCA | AppDev & Platform Consultant | DevSecOps


Disclaimer: Views expressed in articles are those of the respective authors and do not necessarily reflect the views of their employers or this site. While we aim for accuracy, please verify information before relying on it, and let us know if you spot an error.
Share:

Related Posts

OpenShift 4: Red Hat OpenShift Container Storage 4.5 Lab Installation

OpenShift 4: Red Hat OpenShift Container Storage 4.5 Lab Installation

Official documentation of Red Hat OpenShift Container Storage can be found here. This blog merely written only to show on the technical feasibility …

OpenShift 3: Enforcing modern and strong OCP TLS & Cipher Suites

OpenShift 3: Enforcing modern and strong OCP TLS & Cipher Suites

Introduction Enforcing strong and modern cipher is critical to ensure our deployment are well protected from old and weak cipher. Enforcing only …

Cloud

OpenShift 4: Libvirt Platform Agnostic installation

Hello everyone, just a couple of months ago, Red Hat has released a shiny OpenShift 4 [1] based on CoreOS technology. In this guide, we...

OpenShift Cluster – How to Drain or Evacuate a Node for Maintenance

OpenShift Cluster – How to Drain or Evacuate a Node for Maintenance

As we know OpenShift clusters are bundled with multiple compute nodes, master nodes, infra nodes etc, it’s not a big deal to manage node …

How to delete a pod with Terminating state in OpenShift or Kubernetes Cluster

How to delete a pod with Terminating state in OpenShift or Kubernetes Cluster

There might be situations where you have already deleted pods (or already removed dc aka deployment configuration) but pods are stuck in Terminating …

OpenShift 4: Installation Bonding Setup

OpenShift 4: Installation Bonding Setup

Objective Setting up 2 x LACP bonding using boot params options. For guidance on the boot params available look here. (Cover image : 2 x...