Skip to main content
Gå til innhold

Prometheus rules

A PrometheusRule is an alert rule you keep as YAML in your repository and deploy with your application. The Prometheus in the PaaS cluster evaluates it, and the alerts go to Argus or Zabbix. See Choose an approach for how to choose between Prometheus rules and Grafana Alerting.

PrometheusRules​

PrometheusRules evaluate metrics and generate alerts based on predefined conditions.

Which metrics a PrometheusRule can see

A PrometheusRule is evaluated by the Prometheus in the PaaS cluster, so it can only alert on metrics that this Prometheus collects. Those are the Kubernetes metrics, metrics from Probes, and metrics your application exposes through a ServiceMonitor or PodMonitor. Metrics your application sends to Mimir with OpenTelemetry don't pass through this Prometheus, so a rule that queries them never fires, and nothing tells you. To alert on those metrics, use Grafana Alerting, or expose them for Prometheus to collect as the hello-prometheus-rules-alerting example does. To see what the cluster Prometheus has, query the Platon App Clusters data source in Grafana.

Example PrometheusRule​

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: my-app-alerts
labels:
prometheus: system
role: alert-rules
spec:
groups:
- name: my-app.rules
rules:
- alert: HighErrorRate
expr: |
sum(rate(http_requests_total{status=~"5..", namespace="my-namespace"}[5m]))
/ sum(rate(http_requests_total{namespace="my-namespace"}[5m])) > 0.05
for: 5m
labels:
severity: warning
sikt_alert: argus
annotations:
summary: "High error rate in my-app"
description: "Error rate is {{ $value | humanizePercentage }}"

Required labels​

For Prometheus to pick up your rules, give the PrometheusRule these labels:

metadata:
labels:
prometheus: system
role: alert-rules

To route an alert, set the sikt_alert label on the rule:

sikt_alert valueDestination
argusArgus (see Argus below)
zabbixZabbix (see Zabbix below)

An alert can target only one destination. Rules without a sikt_alert label still fire in Prometheus but aren't forwarded to either system.

Best practices​

  1. Create PrometheusRules only for production environments to avoid noise
  2. Use group names that match the *.rules pattern
  3. Verify your expr is valid before deploying
  4. Test in staging before production

Probes (black-box monitoring)​

Probes actively check endpoint health from outside your application.

When to use Probes​

  • Monitor external endpoints
  • Check SSL certificate expiration
  • Verify DNS resolution
  • Test HTTP response codes and latency

Example Probe​

apiVersion: monitoring.coreos.com/v1
kind: Probe
metadata:
name: my-app-probe
labels:
platon-monitor: "true"
spec:
interval: 30s
module: http_2xx
targets:
staticConfig:
static:
- https://my-app.example.com

Add the label platon-monitor: "true" to the Probe so that it is detected automatically.

Default Probe rules​

Platon provides default PrometheusRules for all Probes. These rules check:

  • Endpoint is responding (probe failure)
  • Probe and ping latency
  • HTTP status code is in the 200–401 range
  • HTTP request latency
  • SSL certificate validity and upcoming expiry

For custom probe alerts, create your own PrometheusRule that references the probe metrics.

Opting out of default alerts​

If you want a Probe to be scraped but not generate alerts from the default rules set the label sikt_alert_disabled: "true" on the probe target:

apiVersion: monitoring.coreos.com/v1
kind: Probe
metadata:
name: my-app-probe
labels:
platon-monitor: "true"
spec:
interval: 30s
module: http_2xx
targets:
staticConfig:
static:
- https://my-app.example.com
labels:
sikt_alert_disabled: "true"

This suppresses all default probe alerts (failure, slow probe, HTTP status, SSL expiry, etc.) for that target. The probe still runs and metrics are still scraped, so you can build your own dashboards or custom PrometheusRules against them.

Argus​

Alerts with sikt_alert: argus go to Argus. The severity label on your rule sets the alert's level in Argus, as listed in Alerting — Severity levels. Setting up notifications there is described in Alerting — Argus.

Alert flow​

Alert flow from applications to Argus

Zabbix​

Zabbix is the other system available as a destination for PrometheusRules.

Argus or Zabbix?​

  • Argus — if you just want to fire the alert and don't need any post-processing.
  • Zabbix — if you already use it for other monitoring, or you need its broader feature set.
  • Sikt Service Center can monitor either, but only if this has been agreed in advance and the procedures they are to follow are in place. Contact SSC to arrange this.

Prerequisites​

Before alerts can be received, a Zabbix host must exist for your service. Coordinate with Platon to have a host registered — the host name you choose is what you'll reference in your rule annotations.

Routing an alert to Zabbix​

Add the sikt_alert: zabbix label and a zabbix_host annotation, example:

- alert: MyServiceDown
expr: up{job="my-service"} == 0
for: 5m
labels:
severity: critical
sikt_alert: zabbix
annotations:
summary: "my-service is down"
zabbix_host: my-host # must match a registered Zabbix host
  • sikt_alert: zabbix (label) routes the alert through AlertManager to the Zabbix webhook.
  • zabbix_host (annotation) tells the webhook which Zabbix host to record the alert against. Required.

Severity mapping​

Zabbix uses its own severity levels — see Zabbix severity best practices. The severity label on your rule does not influence Zabbix severity directly; configure that on the Zabbix host item.

Learn more​