Skip to main content

Metric alerts

paqtra-api evaluates threshold and anomaly-rate rules against the per-second metrics store (see metrics.md) and sends every transition through the existing notifier (Slack, webhook, PagerDuty and the other channels configured for Paqtra alerts) as rule metric:<rule>.

A metric alert only notifies. It can raise, clear, repeat or be silenced. It never applies, changes or suggests a Cilium policy. The only state the API can change is notification state (ack and silence).

Rule format​

Rules are YAML documents with a top-level alerts: list. The syntax follows Netdata's health configuration closely, so most Netdata alarms port with a field rename.

alerts:
- alarm: cpu_usage_high # unique name
on: system.cpu # metric context
dimensions: "*" # globs, separated by space, comma or |
lookup: average -10m # <function> -<window>
aggregate: sum # how matched dimensions combine
units: "%"
every: 1m
warn: '$this > (($status >= $WARNING) ? 75 : 85)'
crit: '$this > (($status == $CRITICAL) ? 85 : 95)'
delay_down: 15m
repeat: 6h
class: Utilization
info: average CPU utilization over the last 10 minutes
FieldRequiredMeaning
alarmyesRule name. A later rule with the same name replaces an earlier one.
onyesContext, for example net.net or hubble.http.
chartsnoChart ID globs. Empty or * matches all.
dimensionsnoDimension globs. Empty or * matches all.
labelsnoChart labels that must match (values are globs), for example namespace: shop.
lookupyes<function> -<window>. Functions: average/avg/mean, min, max, sum, last, median/p50, p90, p95, p99, anomaly-rate.
aggregatenosum, avg, min or max across matched dimensions. Default avg for percent units, sum otherwise.
pernoInstance granularity: chart (default), dimension or node.
varsnoConstants available as $name.
calcnoExpression turning the lookup result into $this.
warn, critone of themExpressions; true raises the status. crit wins.
everynoEvaluation interval, default 10s.
delay_up, delay_downnoHow long a worse / better status must hold before it changes.
repeatnoRe-notify while raised, unacknowledged and unsilenced.
units, class, infonoShown in the API, console and notifications.
enablednofalse removes the rule, including a built-in one of the same name.

Durations accept 90s, 15m, 6h, 7d or a bare number of seconds.

Expression language​

  • numbers, nan, inf
  • + - * / % (division or modulo by zero gives NaN)
  • > >= < <= == !=, && || !, ?:, parentheses
  • abs(x), min(...), max(...)

Any comparison involving NaN is false, so a rule over missing data never raises.

VariableValue
$thisThe aggregated lookup result, or the calc result.
$<dimension>That dimension's lookup result, for example $responses or $errors_5xx.
$status$UNDEFINED (-1), $CLEAR (1), $WARNING (3), $CRITICAL (4).
$anomaly_ratePercent of samples flagged anomalous in the window.
$ncpuCPUs on the node.
$nowUnix seconds.

Use $status for hysteresis: warn: '$this > (($status >= $WARNING) ? 75 : 85)' raises above 85 and clears below 75.

Built-in rules​

The embedded pack (web-api/paqtra-metrics/src/metricalert/defaults.yaml, 45 rules):

AreaRules
CPU and loadcpu_usage_high, cpu_iowait_high, cpu_steal_high, load_average_high, cpu_pressure_some
Memoryram_in_use, oom_kill, memory_pressure_full, swap_used_high, swap_io_heavy
Diskdisk_space_usage, disk_inode_usage, disk_util_high, disk_await_high, io_pressure_full
Interfacesinterface_inbound_drops, interface_outbound_drops, interface_errors, interface_fifo_errors, interface_down, interface_carrier_changes, softnet_dropped, softnet_squeezed
TCP and UDPtcp_listen_overflows, tcp_syn_queue_drops, tcp_syncookies_sent, tcp_backlog_drops, tcp_retransmit_timeouts, tcp_memory_pressure, udp_receive_buffer_errors, udp_send_buffer_errors
Conntrack and systemconntrack_table_full, conntrack_insert_failed, file_descriptors_high, processes_blocked
Pods (cgroups)workload_cpu_throttling, workload_memory_near_limit, workload_oom_kill
Applicationsapp_down
Hubblehubble_drop_ratio, hubble_policy_denied, hubble_http_5xx_ratio, hubble_dns_errors
Anomalynode_anomaly_rate, network_anomaly_rate

Read the YAML for exact thresholds. To change one, add a rule with the same alarm name in PAQTRA_METRICALERT_DIR; to drop one, set enabled: false.

Silences and acknowledgement​

  • Ack stops repeat notifications for one raised instance until its next status change.
  • Silence suppresses notifications for instances matching rule, node and chart globs until it expires. Status is still tracked and shown as silenced. Silences persist in metricalert-silences.json in the metrics directory. The notifier also honours existing silences for rule metric:<rule>.

Ack and silence need the editor role and are written to the audit log.

API and CLI​

Method and pathPurpose
GET /api/v1/metrics/alerts?all=&history=Raised instances (all with all=true), transitions, rules, silences, stats.
POST /api/v1/metrics/alerts/{id}/ackAcknowledge a raised instance.
POST /api/v1/metrics/silencesBody: rule, node, chart globs, duration (seconds) or until (Unix seconds), comment.
DELETE /api/v1/metrics/silences/{id}Remove a silence.
paqtra metrics alerts [--all]

Configuration​

VariableDefaultMeaning
PAQTRA_METRICALERTtruefalse turns the engine off.
PAQTRA_METRICALERT_DEFAULTStruefalse skips the built-in pack.
PAQTRA_METRICALERT_DIRempty*.yaml / *.yml files loaded in name order on top of the defaults.

An invalid rule disables the engine and reports the error in GET /api/v1/metrics/status (alertsError) instead of running a partial pack. Helm: api.metrics.alerts.