Alerts Overviewยถ
๐จ Prometheus Alerting for MongoDB & Custom Resourcesยถ
This page provides examples and references for Prometheus alerting rules, including MongoDB monitoring and custom container CPU usage alerts.
๐ Reference: Awesome Prometheus Alertsยถ
For a comprehensive list of Prometheus alerting rules, visit the Awesome Prometheus Alerts - MongoDB Section.
๐ก๏ธ MongoDB Down Alertยถ
The following Prometheus rule triggers a critical alert when a MongoDB instance is detected as down.
{
"alert": "MongodbDown",
"expr": "mongodb_up == 0",
"for": "0m",
"labels": {
"severity": "critical"
},
"annotations": {
"summary": "MongoDB Down {{ $labels.instance }}",
"description": "MongoDB instance is down {{ $value }}"
}
}
MongoDB Availability
This alert fires immediately when the mongodb_up metric equals zero, indicating the MongoDB instance is unreachable.
โก Custom Container CPU Usage Alertยถ
The following custom PrometheusRule monitors CPU usage for containers named stress and triggers a warning if usage exceeds 75% of the requested CPU for more than 1 minute.
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: container-cpu-alert
labels:
prometheus: kube-prometheus
role: alert-rules
spec:
groups:
- name: container-cpu-usage
rules:
- alert: KubeContainerCPURequestAlert
expr: |
(rate(container_cpu_usage_seconds_total{container="stress"}[5m]) /
on (container) kube_pod_container_resource_requests{resource="cpu", container="stress"}) > 0.75
for: 1m
labels:
severity: warning
annotations:
summary: "Container CPU usage is above 75% of request for 5 minutes"
description: "The container is using more than 75% of its requested CPU for 5 minutes."
CPU Usage Monitoring
Adjust the container name and threshold values as needed for your environment.
This alert helps identify containers that may be under resource pressure.