Get up to 50% 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/.

Share :

Related Posts

OpenShift 4.5 : NooBaa S3 Bucket for internal image registry

OpenShift 4.5 : NooBaa S3 Bucket for internal image registry

Image registry storage is best and recommended to run on S3 storage endpoint(then filesystem storage, then block). In this blog context, we are going …

OpenShift 4.5 KNI Labs (Step-by-step)

OpenShift 4.5 KNI Labs (Step-by-step)

KNI, Kubernetes Native Infrastructure is one of the method deploying OpenShift baremetal with IPI (Installer Provided Infrastructure), yes you read it …

OpenShift 4: Custom API URL Endpoint

OpenShift 4: Custom API URL Endpoint

https://unsplash.com/@pankajpatel Objective On top of the standard api.<cluster_name>. as external API endpoint, we are going to serve this …

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 LACP Bonding …

OpenShift 4: DHCPD High Availability

OpenShift 4: DHCPD High Availability

Objective One of the support component to install OpenShift 4 is the DHCP . We need to ensure this DHCP is r esilient and highly available hence this …

OpenShift 4: AlertManager + Slack Configuration

OpenShift 4: AlertManager + Slack Configuration

Objective Sending alert to Slack and defined proper channel for each alert type. Pre-Requisites: