Author Netdata Health Alerts
Use this skill when changing or reviewing a health-alert definition. Alerts are production policy: a syntactically valid
expression can still page incorrectly, manufacture a recovery, duplicate an incident owner, or make a disappearing entity
look healthy.
The normal goal when translating an alert from another system is Netdata-adapted operational equivalence, not
execution-engine emulation. Preserve the operator-visible incident as closely as Netdata can express it through NIDL
instances, alert beats, database lookups, native gap behavior, and chart obsoletion. Treat differences from the source
engine as explicit design facts to document and test, not as defects by default.
Read The Right Sources
Read the target alert, its collector/profile signal contract, and the existing incident owner. Search for duplicate
names, contexts and equivalent generic alerts. Select the affected references:
| Question |
Sources |
| Identity, scope, variables and expression syntax |
docs/NIDL-Framework.md, src/health/REFERENCE.md; current variable/evaluator code when affected |
| Template/alarm ownership or overrides |
src/health/alert-configuration-ordering.md and existing named/generic rules |
| Lifecycle, gaps or timing |
src/health/README.md, relevant lookup/delay sections of src/health/REFERENCE.md, and runtime owners below |
| Runtime semantics changed or uncertain |
health_event_loop.c, health_variable.c under src/health/; src/web/api/queries/query-execute.c, selected grouping implementation and src/libnetdata/eval/eval-evaluate.c as applicable |
| Collector/profile signal or identity changes |
Matching collector/profile skill and its affected references; this skill does not replace them |
For review, use the contract and completion sections as questions against the complete assigned change and existing
design/test evidence. Read an active SOW when available; do not create one or demand a new authoring note merely to
review. Missing evidence matters when it leaves an affected contract unproven. Implementation follows the root SOW gate.
Never query or reconfigure a live Agent merely to validate an alert unless the user has explicitly authorized that access.
Establish The Alert Contract Before Editing
Write down the following in the active SOW before changing a non-trivial alert:
- Incident and owner: What real incident does this alert represent? Which one source owns it? Do not create a
product-named duplicate of an existing collection-failure, component-failure, or generic host alert just to change
routing or severity.
- Signal contract: Identify every source value and its meanings, including zero, non-zero, tri-state values, absent
dimensions, temporary collection failure, and known entity disappearance.
- Source intent and adaptation: Separate the source alert's operator intent from its engine syntax. Record which
condition, scope, severity, persistence intent, identity, and recovery semantics Netdata preserves; record every
deliberate difference. Use
NETDATA-ADAPTED as the normal classification. Reserve EXACT for a proven coincidental
match across timing, gaps, identity, recovery, and removal—not merely a similar expression.
- NIDL instance map: Record the monitored component, context, one instance type, RRDSET/chart ID identity, dimensions,
stable identity labels, current metadata labels, and the collector's obsoletion condition. An alert attaches to one
RRDSET/chart instance; a template applies that same rule independently to matching instances in one context.
- Identity: Choose an
alarm only for a specific chart instance; choose a template for a context-wide rule. An
identity label MUST identify the same monitored entity across its intended lifetime. A label whose source value can
change for that entity is current metadata, not RRDSET identity: preserve the chart ID and update/promote the label.
Confirm labels preserve the incident identity and do not create unbounded instances.
Prove whether each promoted source label is live metadata, creation-time metadata, or source-frozen history. Do not
describe a label as "current" merely because Netdata can update labels.
- Variables and aggregation: An unqualified variable resolves in the alert's local monitored component/instance before
broader candidates. Use a fully qualified chart/dimension reference only after proving the other chart is the matching
instance and labels select it unambiguously. Never synthesize an infrastructure-level alert by combining multiple
RRDSET instances in alert configuration; require a source-owned aggregate RRDSET at the higher component level instead.
The alert
component: classification field does not replace this NIDL mapping.
- Lifecycle: Specify expected
UNINITIALIZED, CLEAR, WARNING/CRITICAL, UNDEFINED, and REMOVED behavior.
State whether an ordinary recovery emits a zero or whether the chart/dimension disappears instead.
- Timing: State the source update cadence, explicit alert cadence, lookup window, source persistence intent, selected
Netdata adaptation, startup behavior, partial-gap behavior, stale-chart behavior, and notification policy. Do not call
a lookup window an implementation of another engine's
for: state machine.
- Validation: List the boundary, transition, missing-data, recovery, and duplicate-ownership tests that prove the
contract.
Pause for a user decision when the change creates a public alert contract, changes default notification policy, changes
the owner of an incident, needs shared health/query framework work, or cannot preserve the approved operator-visible
incident closely enough with Netdata-native behavior. A difference from Prometheus execution alone is not such a blocker.
Combine Values Across Dimensions, Charts, And Alerts
Choose the smallest pattern that can express the condition truthfully. Do not introduce cross-chart or intermediate-alert
plumbing when the required values already share the alert's chart.
Pattern 1 — dimensions on the alert's chart
Use unqualified dimension variables in calc, warn, or crit when every required value is a dimension on the chart
named by on::
template: example_ratio
on: app.state
calc: $total - $used
Runtime facts:
- Matching is by dimension ID or name in the alert's own chart.
- The default dimension value is
collector.last_stored_value: the latest database-stored value after interpolation, not
a database-window aggregate and not necessarily the raw last collector sample.
- A missing dimension makes the expression fail with an unknown variable and the alert value become
NaN.
- Prefer explicit non-finite guards when
UNDEFINED is the required missing-input state; do not rely on arithmetic or
comparisons to preserve NaN.
Use $dimension_raw only when the contract specifically needs the last collected value before interpolation/storage
presentation, and $dimension_last_collected_t only when it needs that dimension's collection timestamp.
Pattern 2 — dimensions from another chart or context
Use a dotted chart/context reference when values live on different charts:
template: example_cross_chart
on: app.usage
calc: $this * 100 / ${app.capacity.total}
The dotted prefix is interpreted from right to left as chart/context plus the final dimension name. Runtime resolution:
- An exact chart ID is checked first.
- A chart name may match.
- If the prefix is a context, every chart instance in that context contributes candidates for the final dimension.
- Every candidate is scored against the alert's chart labels by counting equal key/value labels.
- The candidate with the highest score wins. Equal scores are resolved by candidate traversal order, so avoid designs
where a tie is possible.
Consequences:
- This is the natural way to compare related chart instances, but the matching labels must make the intended instance
unique. A generic shared label such as only
component=ceph is usually insufficient across many cluster instances.
- Like Pattern 1, the selected dimension value is the latest stored value, not a query over a time window.
- Fully qualified names containing punctuation must use
${...} braces.
- A reference that resolves to no candidate fails as an unknown variable and produces
NaN.
Pattern 3 — an intermediate alert as a computed variable
Create a non-notifying helper alert when the required value itself needs a database lookup or multi-stage computation,
then reference that alert by name from the consuming alert:
template: example_window
on: app.work
lookup: average -1h of requests
calc: $this
to: silent
template: example_consumes
on: app.current
lookup: average -1m of requests
calc: $this / $example_window
warn: $this > 1
to: sysadmin
Runtime facts:
- Every running alert with the referenced name is a candidate.
- Candidates are selected by the same equal-label score used for cross-chart variables.
- The selected candidate contributes its current alert value (
rc->value), after that helper's own lookup and calc.
- This is the only one of the three patterns that can combine database-window results such as “max of the last hour of X
with the average of the last minute of Y”.
- Health evaluates all lookup/calculation phases before warning/critical phases, but helper snapshots are published as
each alert completes. A consumer with a different cadence can therefore read the helper's previous published value on
its first beat or after cadence drift. Align
every: or disclose this timing difference.
- Prefer
to: silent on helpers and document why they exist; a helper is instrumentation, not a second incident owner.
Choosing a pattern
- Same chart, latest values: Pattern 1.
- Different charts/contexts, latest values: Pattern 2.
- Any input needs a database window or a staged calculation: Pattern 3.
- Never use Pattern 3 merely to avoid a qualified dotted reference; its added timing and lifecycle coupling must earn its
place.
- Never combine multiple RRDSET instances into one infrastructure-level alert on the alert side. If no source-owned chart
provides the required aggregate, that is a collector/profile/framework gap, not an alert-expression workaround.
Model The Lifecycle Truthfully
| Source situation |
Alert-lifecycle consequence |
| Valid numeric input and both conditions are false |
CLEAR |
| Valid numeric input and warning/critical condition is true |
WARNING or CRITICAL |
| Some values exist in a lookup window and some are NULL |
The lookup continues using numeric values; NULL is not automatically a failed condition |
| Collector misses a collection while the chart remains live |
A runnable alert may evaluate a lookup based on stored data; no fresh sample is fabricated |
| Lookup runs and its selected window has no usable values |
$this is NaN; the final state is UNDEFINED only when the condition preserves it |
| A lookup's newest stored sample is too old for its runnable-history gate |
The health loop skips that evaluation; it does not manufacture CLEAR or guarantee an UNDEFINED transition |
| Collector knows the entity is gone and obsoletes the chart |
The alert enters REMOVED, not an ordinary zero/CLEAR recovery |
Important rules:
- A collection failure is not disappearance. Collectors MUST preserve a gap when they cannot measure and MUST obsolete
only an entity they know is gone. Do not add a false zero to make an alert recover.
- A chart can remain alert-eligible during a gap. The health loop skips an obsolete chart, but does not require a
newly collected value for every scheduled evaluation.
$last_collected_t and $update_every expose freshness when an
alert is the deliberate stale-collection owner.
- A live chart does not guarantee every lookup remains runnable forever. For a relative database lookup, the health
loop eventually skips evaluation when the newest stored point is too old for the requested window plus its bounded
update-interval tolerance. Skipping evaluation preserves the prior alert state; it is different from evaluating an
all-null result to
UNDEFINED.
- Obsoletion ends the instance alert. Once the collector knows an entity is gone and obsoletes its RRDSET, the health
rule no longer evaluates that instance. Do not attempt to emulate an infrastructure-level continuation in another
alert; collect a source-owned aggregate instance if that is the required product signal.
- A null result does not fabricate healthy state. The health loop assigns
NaN to an empty lookup result. A condition
that itself evaluates to NaN is UNDEFINED.
- Comparisons can consume
NaN. In the expression evaluator, NaN is false in boolean contexts and a comparison
such as $this == 0 produces a finite false result. That can yield CLEAR, not UNDEFINED. If the contract requires
UNDEFINED, make and test an expression path that preserves NaN; never assume a comparison does so.
- Some NULLs are not all NULLs. Query aggregation accepts numeric points and omits non-numeric ones. Do not assume a
partial collection gap invalidates a window unless the current runtime and the approved product contract say it does.
A general strict-coverage rule is shared-framework work, not an alert-file shortcut.
- Do not duplicate freshness ownership. Use
$now - $last_collected_t for an explicit collection/staleness alert only
when no existing generic collection-failure alert already owns the incident. A data-state alert normally owns the
measured condition, not the collector outage.
For a data-state alert that MUST become UNDEFINED when its lookup is non-finite, use and test this condition shape:
warn: ($this == nan or $this == inf) ? (nan) : (<numeric predicate>)
Use crit: in the same way. This preserves the non-finite result only; it does not turn a partial-null window into a
collection-failure alert or replace a known-obsolete chart's REMOVED lifecycle.
Adapt Timing To Netdata
Current State
Use calc when the source's current value is the full condition. Test start-up, missing input, normal recovery, and chart
obsoletion separately. delay: controls notification hysteresis, not the evaluated alert state; it is not a substitute
for a Prometheus for: duration.
Control Flapping With Three Combinable Layers
Stability involves signal smoothing, threshold hysteresis and notification delay. Address them in that order.
State-dependent thresholds are hysteresis; delay: postpones notification execution while the evaluated alert state
changes immediately. See src/health/REFERENCE.md#alert-line-delay and its conditional-operator hysteresis section.
Layer 1 — stabilize the queried value
Use lookup: to make $this a stable aggregate over an explicit observation window:
lookup: average -5m unaligned of latency
average smooths noisy utilization, rate, latency, and utilization-like signals.
min requires every observed numeric sample to remain active, appropriate for persisted binary fault states.
max preserves worst-case excursions when the incident is defined by peaks.
countif expresses percent-of-observed-time semantics.
This reduces noise but cannot prevent a stable aggregate from hovering near one threshold. A 5-minute average near 100 ms
can still cross a 100 ms threshold repeatedly.
Layer 2 — separate raise and clear thresholds
For policy thresholds whose signal may hover near the boundary, use a state-dependent predicate:
warn: $this > (($status >= $WARNING) ? (90) : (100))
crit: $this > (($status == $CRITICAL) ? (105) : (110))
This changes one threshold into two thresholds:
- clear-to-warning raises above 100;
- the warning predicate becomes false at or below 90 (CLEAR when the critical predicate is also false);
- critical can independently use another raise/clear pair.
Important semantics:
- This is threshold hysteresis, without a time delay.
- The alert continues evaluating at its normal
every: cadence.
- It only changes the boundary used by the current status, so a genuine crossing of the recovery threshold acts
immediately.
- Preserve a non-finite guard around the complete expression when
UNDEFINED must remain possible.
Prefer this when independent raise/clear boundaries are meaningful and the signal is expected to linger near one boundary.
Do not use it to redefine a categorical exact condition into a policy band.
Layer 3 — delay transition notifications
Use delay: when notification execution should wait after a state change:
delay: down 5m multiplier 1.5 max 1h
up is selected when the new numeric status is greater than the old; down otherwise.
This includes UNDEFINED (-1) → CLEAR (1) using up, not just warning/critical escalation.
Owners: src/health/health_event_loop.c (delay selection), src/health/rrdcalc.h (status values).
multiplier grows the delay when the state changes during the delay.
max caps the accumulated delay.
This is the only layer that postpones an alert transition notification. It can suppress rapid clear/reactivate
notification cycles, but it can also postpone notice of a real incident. Use it sparingly and record the expected
notification delay in the alert contract. The status still changes on the evaluation beat: health_event_loop.c
updates it immediately, while health_notifications.c checks the notification due time.
Selection procedure
- Establish whether the incident is categorical, threshold policy, or derived arithmetic.
- Select the smallest truthful
lookup: window and aggregation first.
- For a noisy policy threshold, choose explicit raise/clear thresholds before adding transition delay.
- Add
delay: only when rapid transition notifications are independently harmful and later notification is acceptable.
- Test each layer: input noise, boundary crossing, recovery, reactivation, non-finite input, partial gap, and the exact
expected notification time.
Persistence Intent
Treat another system's for: D as an operator intent to suppress transient conditions. It is not a requirement to emulate
that system's pending-state machine. Choose the closest safe Netdata-native behavior from the source's actual numeric
state space, set an explicit every:, and disclose the differences:
- For a binary source where 1 means the active fault,
min -5m unaligned with an active predicate is true only when
every observed numeric value in the selected window is active. This is a Netdata observation-window adaptation, not
Prometheus for: 5m.
- For a binary source where 0 means the active fault, use the complementary aggregation/predicate that requires all
observed values to be zero; consult the lookup reference and prove it with state-sequence tests.
- For a tri-state or enumerated source, do not apply a binary
min/max rule by analogy. Use an exact predicate over the
full state space. For example, countif(!=target) returns the percentage of observed values outside target; zero means
every observed value matched.
min, max, and countif operate on the numeric samples they receive. Test active-to-other-state transitions in both
directions and record the intended partial-gap behavior.
- A new chart may become runnable with up to one chart update interval less history than the requested lookup window.
Therefore an already-active condition can raise up to roughly one source beat before
D after chart creation. Do not
conceal this with a hand-authored "window complete" flag.
- A missing sample does not reset an observation window. Values before and after a partial gap may contribute to the same
lookup. Collection-failure ownership remains separate unless the alert contract explicitly owns freshness.
- One health rule has one historical database lookup. A predicate combining multiple dimensions cannot gain exact
historical persistence by looking up one dimension and combining it with the others' current values. Prefer, in order:
a source-owned derived dimension when the persisted compound condition is essential; otherwise a truthful current-state
adaptation; never a mixed-time formula that changes the incident meaning.
- Do not lengthen the window mechanically by one assumed collector interval. Collector cadence is configurable, and that
does not repair partial gaps or create a source-engine pending state.
For every persistence adaptation, prove: chart startup, observed active history, each recovery state, each higher/lower
enumerated state, a partial source gap, a stale non-runnable lookup, collection resumption, chart obsoletion, and the
configured evaluation cadence. Never invent a pending state that Netdata does not expose, and never declare fidelity
from the look of an expression alone.
Keep Ownership And Identity Non-Duplicating
- Search existing stock alerts before adding one. Reuse an existing alert only when it really owns the same logical
incident; disclose routing/severity/lifecycle differences rather than silently relabeling it.
- Keep source collection failure, component/API collection failure, source data-state failure, and client-observed failure
as separate owners when they identify different operator actions.
- Filter templates with chart labels only when they select the intended RRDSET instance without changing its identity.
A current metadata label may be used as a filter only when the alert contract explicitly wants that current metadata;
do not turn it into
instances.by_labels merely to make filtering convenient. Exclude known named rules from generic
fallbacks, including special sources whose recovery is chart removal rather than zero.
- Preserve ordinary zero recovery. Do not convert an active-to-zero source into disappearance, and do not treat a
disappearing source as a normal CLEAR.
- Use the ordering guide for template/alarm precedence and user-versus-stock override behavior. Same-name definitions are
an override mechanism; different names coexist and can therefore duplicate incidents.
Validate The Actual Contract
Run the smallest relevant tests first, then the full affected suite. A complete alert change normally needs all applicable
items below:
- Run
/usr/sbin/netdata -W healthconfigtest for the built-in health parser and lookup suite.
- Add or update a focused test that reads the shipped alert template and asserts its context, labels, lookup, units,
cadence, expressions, routing, source ownership, and declared fidelity—not merely a copied expected string.
- Test the signal's lifecycle through the real query/health runtime where practical. If a lower-level deterministic model
is necessary, derive it directly from runtime timestamps and numeric-point selection; do not pass an arbitrary
windowComplete flag or label skipped NULLs as continuous evaluation. Cover startup, active transition, normal zero
recovery, a true all-null query, partial-null behavior, stale non-runnable behavior, collection resumption, known
disappearance/REMOVED, and label identity.
- For an expression that relies on
NaN, test the evaluator result directly. Check both direct NaN propagation and any
comparison/conditional branch; do not infer the result from ordinary floating-point intuition.
- Run collector/profile validation when the alert depends on a collector or profile change. Include source absence and
collision-bearing labels where relevant.
- Search for same-incident alerts, duplicate contexts, old names, fallback overlap, and generated artifacts. Record the
result in the SOW.
- For an externally sourced alert pack, commit a source-pinned mapping that records the original condition, scope,
severity, persistence intent, supported releases, Netdata owner, adaptation, and known differences. Tests MUST consume
that mapping rather than restating the intended result independently.
- Validate every published configuration example through the same job-construction prerequisites users need. In
particular, a job referencing
vnode: is incomplete unless the example defines or clearly links the required vnode.
- Run
git diff --check and the project-required validation/review gate before claiming completion.
healthconfigtest runs built-in health parser and lookup cases. It does not load every stock health template, prove that a
template attaches to the intended chart, or prove the runtime lifecycle. Cover those separately with source-aware contract
and transition tests.
Completion Check
Before requesting review, confirm all of the following:
- The alert has exactly one logical owner and a stable scope.
- Its NIDL instance map shows one monitored component and one instance-level alert target; any required aggregate is a
source-owned higher-level RRDSET, not an alert-side merge.
- Its source state values, gaps, absence, and recovery have been tested rather than assumed.
- Its
NaN, UNDEFINED, CLEAR, and REMOVED transitions match the recorded contract.
- Its timing is the closest safe Netdata adaptation, with startup/gap/stale differences disclosed;
delay: is not
standing in for another engine's persistence state machine.
- Notification defaults follow the approved product policy.
- No shared health/query behavior was added or assumed without the required separate scope approval.
Authoritative References
- Syntax, variables, lookups, and stock patterns:
src/health/REFERENCE.md
- State model and missing-data summary:
src/health/README.md
- NIDL component/instance/dimension/label model:
docs/NIDL-Framework.md
- Template/alarm and user/stock precedence:
src/health/alert-configuration-ordering.md
- Alert eligibility, lookup execution, and
REMOVED: src/health/health_event_loop.c
$now, $last_collected_t, $update_every, dimension freshness, same-chart variables, cross-chart/context
variables, alert variables, and label-score selection: src/health/health_variable.c
- Equal-label score implementation:
src/database/rrdlabels.c:rrdlabels_common_count()
- Query gaps and grouping:
src/web/api/queries/query-execute.c and the relevant grouping implementation
NaN expression semantics: src/libnetdata/eval/eval-evaluate.c
1---2name: health-alert-authoring-23description: Author, adapt, modify, or review Netdata health alerts and alert templates. Use when translating alerts from another system; changing `src/health/health.d/*.conf`, lookup/calc/warn/crit expressions, lifecycle, timing, routing, ownership, or missing-data behavior; writing health-config tests; or selecting an alert's chart/context/label identity.4---56# Author Netdata Health Alerts78Use this skill when changing or reviewing a health-alert definition. Alerts are production policy: a syntactically valid9expression can still page incorrectly, manufacture a recovery, duplicate an incident owner, or make a disappearing entity10look healthy.1112The normal goal when translating an alert from another system is **Netdata-adapted operational equivalence**, not13execution-engine emulation. Preserve the operator-visible incident as closely as Netdata can express it through NIDL14instances, alert beats, database lookups, native gap behavior, and chart obsoletion. Treat differences from the source15engine as explicit design facts to document and test, not as defects by default.1617## Read The Right Sources1819Read the target alert, its collector/profile signal contract, and the existing incident owner. Search for duplicate20names, contexts and equivalent generic alerts. Select the affected references:2122| Question | Sources |23|---|---|24| Identity, scope, variables and expression syntax | `docs/NIDL-Framework.md`, `src/health/REFERENCE.md`; current variable/evaluator code when affected |25| Template/alarm ownership or overrides | `src/health/alert-configuration-ordering.md` and existing named/generic rules |26| Lifecycle, gaps or timing | `src/health/README.md`, relevant lookup/delay sections of `src/health/REFERENCE.md`, and runtime owners below |27| Runtime semantics changed or uncertain | `health_event_loop.c`, `health_variable.c` under `src/health/`; `src/web/api/queries/query-execute.c`, selected grouping implementation and `src/libnetdata/eval/eval-evaluate.c` as applicable |28| Collector/profile signal or identity changes | Matching collector/profile skill and its affected references; this skill does not replace them |2930For review, use the contract and completion sections as questions against the complete assigned change and existing31design/test evidence. Read an active SOW when available; do not create one or demand a new authoring note merely to32review. Missing evidence matters when it leaves an affected contract unproven. Implementation follows the root SOW gate.3334Never query or reconfigure a live Agent merely to validate an alert unless the user has explicitly authorized that access.3536## Establish The Alert Contract Before Editing3738Write down the following in the active SOW before changing a non-trivial alert:3940- **Incident and owner:** What real incident does this alert represent? Which one source owns it? Do not create a41 product-named duplicate of an existing collection-failure, component-failure, or generic host alert just to change42 routing or severity.43- **Signal contract:** Identify every source value and its meanings, including zero, non-zero, tri-state values, absent44 dimensions, temporary collection failure, and known entity disappearance.45- **Source intent and adaptation:** Separate the source alert's operator intent from its engine syntax. Record which46 condition, scope, severity, persistence intent, identity, and recovery semantics Netdata preserves; record every47 deliberate difference. Use `NETDATA-ADAPTED` as the normal classification. Reserve `EXACT` for a proven coincidental48 match across timing, gaps, identity, recovery, and removal—not merely a similar expression.49- **NIDL instance map:** Record the monitored component, context, one instance type, RRDSET/chart ID identity, dimensions,50 stable identity labels, current metadata labels, and the collector's obsoletion condition. An alert attaches to one51 RRDSET/chart instance; a template applies that same rule independently to matching instances in one context.52- **Identity:** Choose an `alarm` only for a specific chart instance; choose a `template` for a context-wide rule. An53 identity label MUST identify the same monitored entity across its intended lifetime. A label whose source value can54 change for that entity is current metadata, not RRDSET identity: preserve the chart ID and update/promote the label.55 Confirm labels preserve the incident identity and do not create unbounded instances.56 Prove whether each promoted source label is live metadata, creation-time metadata, or source-frozen history. Do not57 describe a label as "current" merely because Netdata can update labels.58- **Variables and aggregation:** An unqualified variable resolves in the alert's local monitored component/instance before59 broader candidates. Use a fully qualified chart/dimension reference only after proving the other chart is the matching60 instance and labels select it unambiguously. Never synthesize an infrastructure-level alert by combining multiple61 RRDSET instances in alert configuration; require a source-owned aggregate RRDSET at the higher component level instead.62 The alert `component:` classification field does not replace this NIDL mapping.63- **Lifecycle:** Specify expected `UNINITIALIZED`, `CLEAR`, `WARNING`/`CRITICAL`, `UNDEFINED`, and `REMOVED` behavior.64 State whether an ordinary recovery emits a zero or whether the chart/dimension disappears instead.65- **Timing:** State the source update cadence, explicit alert cadence, lookup window, source persistence intent, selected66 Netdata adaptation, startup behavior, partial-gap behavior, stale-chart behavior, and notification policy. Do not call67 a lookup window an implementation of another engine's `for:` state machine.68- **Validation:** List the boundary, transition, missing-data, recovery, and duplicate-ownership tests that prove the69 contract.7071Pause for a user decision when the change creates a public alert contract, changes default notification policy, changes72the owner of an incident, needs shared health/query framework work, or cannot preserve the approved operator-visible73incident closely enough with Netdata-native behavior. A difference from Prometheus execution alone is not such a blocker.7475## Combine Values Across Dimensions, Charts, And Alerts7677Choose the smallest pattern that can express the condition truthfully. Do not introduce cross-chart or intermediate-alert78plumbing when the required values already share the alert's chart.7980### Pattern 1 — dimensions on the alert's chart8182Use unqualified dimension variables in `calc`, `warn`, or `crit` when every required value is a dimension on the chart83named by `on:`:8485```text86template: example_ratio87 on: app.state88 calc: $total - $used89```9091Runtime facts:9293- Matching is by dimension ID or name in the alert's own chart.94- The default dimension value is `collector.last_stored_value`: the latest database-stored value after interpolation, not95 a database-window aggregate and not necessarily the raw last collector sample.96- A missing dimension makes the expression fail with an unknown variable and the alert value become `NaN`.97- Prefer explicit non-finite guards when `UNDEFINED` is the required missing-input state; do not rely on arithmetic or98 comparisons to preserve `NaN`.99100Use `$dimension_raw` only when the contract specifically needs the last collected value before interpolation/storage101presentation, and `$dimension_last_collected_t` only when it needs that dimension's collection timestamp.102103### Pattern 2 — dimensions from another chart or context104105Use a dotted chart/context reference when values live on different charts:106107```text108template: example_cross_chart109 on: app.usage110 calc: $this * 100 / ${app.capacity.total}111```112113The dotted prefix is interpreted from right to left as chart/context plus the final dimension name. Runtime resolution:1141151. An exact chart ID is checked first.1162. A chart name may match.1173. If the prefix is a context, every chart instance in that context contributes candidates for the final dimension.1184. Every candidate is scored against the alert's chart labels by counting equal key/value labels.1195. The candidate with the highest score wins. Equal scores are resolved by candidate traversal order, so avoid designs120 where a tie is possible.121122Consequences:123124- This is the natural way to compare related chart instances, but the matching labels must make the intended instance125 unique. A generic shared label such as only `component=ceph` is usually insufficient across many cluster instances.126- Like Pattern 1, the selected dimension value is the latest stored value, not a query over a time window.127- Fully qualified names containing punctuation must use `${...}` braces.128- A reference that resolves to no candidate fails as an unknown variable and produces `NaN`.129130### Pattern 3 — an intermediate alert as a computed variable131132Create a non-notifying helper alert when the required value itself needs a database lookup or multi-stage computation,133then reference that alert by name from the consuming alert:134135```text136template: example_window137 on: app.work138 lookup: average -1h of requests139 calc: $this140 to: silent141142template: example_consumes143 on: app.current144 lookup: average -1m of requests145 calc: $this / $example_window146 warn: $this > 1147 to: sysadmin148```149150Runtime facts:151152- Every running alert with the referenced name is a candidate.153- Candidates are selected by the same equal-label score used for cross-chart variables.154- The selected candidate contributes its current alert value (`rc->value`), after that helper's own lookup and `calc`.155- This is the only one of the three patterns that can combine database-window results such as “max of the last hour of X156 with the average of the last minute of Y”.157- Health evaluates all lookup/calculation phases before warning/critical phases, but helper snapshots are published as158 each alert completes. A consumer with a different cadence can therefore read the helper's previous published value on159 its first beat or after cadence drift. Align `every:` or disclose this timing difference.160- Prefer `to: silent` on helpers and document why they exist; a helper is instrumentation, not a second incident owner.161162### Choosing a pattern163164- Same chart, latest values: Pattern 1.165- Different charts/contexts, latest values: Pattern 2.166- Any input needs a database window or a staged calculation: Pattern 3.167- Never use Pattern 3 merely to avoid a qualified dotted reference; its added timing and lifecycle coupling must earn its168 place.169- Never combine multiple RRDSET instances into one infrastructure-level alert on the alert side. If no source-owned chart170 provides the required aggregate, that is a collector/profile/framework gap, not an alert-expression workaround.171172## Model The Lifecycle Truthfully173174| Source situation | Alert-lifecycle consequence |175|---|---|176| Valid numeric input and both conditions are false | `CLEAR` |177| Valid numeric input and warning/critical condition is true | `WARNING` or `CRITICAL` |178| Some values exist in a lookup window and some are NULL | The lookup continues using numeric values; NULL is not automatically a failed condition |179| Collector misses a collection while the chart remains live | A runnable alert may evaluate a lookup based on stored data; no fresh sample is fabricated |180| Lookup runs and its selected window has no usable values | `$this` is `NaN`; the final state is `UNDEFINED` only when the condition preserves it |181| A lookup's newest stored sample is too old for its runnable-history gate | The health loop skips that evaluation; it does not manufacture `CLEAR` or guarantee an `UNDEFINED` transition |182| Collector knows the entity is gone and obsoletes the chart | The alert enters `REMOVED`, not an ordinary zero/CLEAR recovery |183184Important rules:185186- **A collection failure is not disappearance.** Collectors MUST preserve a gap when they cannot measure and MUST obsolete187 only an entity they know is gone. Do not add a false zero to make an alert recover.188- **A chart can remain alert-eligible during a gap.** The health loop skips an obsolete chart, but does not require a189 newly collected value for every scheduled evaluation. `$last_collected_t` and `$update_every` expose freshness when an190 alert is the deliberate stale-collection owner.191- **A live chart does not guarantee every lookup remains runnable forever.** For a relative database lookup, the health192 loop eventually skips evaluation when the newest stored point is too old for the requested window plus its bounded193 update-interval tolerance. Skipping evaluation preserves the prior alert state; it is different from evaluating an194 all-null result to `UNDEFINED`.195- **Obsoletion ends the instance alert.** Once the collector knows an entity is gone and obsoletes its RRDSET, the health196 rule no longer evaluates that instance. Do not attempt to emulate an infrastructure-level continuation in another197 alert; collect a source-owned aggregate instance if that is the required product signal.198- **A null result does not fabricate healthy state.** The health loop assigns `NaN` to an empty lookup result. A condition199 that itself evaluates to `NaN` is `UNDEFINED`.200- **Comparisons can consume `NaN`.** In the expression evaluator, `NaN` is false in boolean contexts and a comparison201 such as `$this == 0` produces a finite false result. That can yield `CLEAR`, not `UNDEFINED`. If the contract requires202 `UNDEFINED`, make and test an expression path that preserves `NaN`; never assume a comparison does so.203- **Some NULLs are not all NULLs.** Query aggregation accepts numeric points and omits non-numeric ones. Do not assume a204 partial collection gap invalidates a window unless the current runtime and the approved product contract say it does.205 A general strict-coverage rule is shared-framework work, not an alert-file shortcut.206- **Do not duplicate freshness ownership.** Use `$now - $last_collected_t` for an explicit collection/staleness alert only207 when no existing generic collection-failure alert already owns the incident. A data-state alert normally owns the208 measured condition, not the collector outage.209210For a data-state alert that MUST become `UNDEFINED` when its lookup is non-finite, use and test this condition shape:211212```text213warn: ($this == nan or $this == inf) ? (nan) : (<numeric predicate>)214```215216Use `crit:` in the same way. This preserves the non-finite result only; it does not turn a partial-null window into a217collection-failure alert or replace a known-obsolete chart's `REMOVED` lifecycle.218219## Adapt Timing To Netdata220221### Current State222223Use `calc` when the source's current value is the full condition. Test start-up, missing input, normal recovery, and chart224obsoletion separately. `delay:` controls notification hysteresis, not the evaluated alert state; it is not a substitute225for a Prometheus `for:` duration.226227## Control Flapping With Three Combinable Layers228229Stability involves signal smoothing, threshold hysteresis and notification delay. Address them in that order.230State-dependent thresholds are hysteresis; `delay:` postpones notification execution while the evaluated alert state231changes immediately. See `src/health/REFERENCE.md#alert-line-delay` and its conditional-operator hysteresis section.232233### Layer 1 — stabilize the queried value234235Use `lookup:` to make `$this` a stable aggregate over an explicit observation window:236237```text238lookup: average -5m unaligned of latency239```240241- `average` smooths noisy utilization, rate, latency, and utilization-like signals.242- `min` requires every observed numeric sample to remain active, appropriate for persisted binary fault states.243- `max` preserves worst-case excursions when the incident is defined by peaks.244- `countif` expresses percent-of-observed-time semantics.245246This reduces noise but cannot prevent a stable aggregate from hovering near one threshold. A 5-minute average near 100 ms247can still cross a 100 ms threshold repeatedly.248249### Layer 2 — separate raise and clear thresholds250251For policy thresholds whose signal may hover near the boundary, use a state-dependent predicate:252253```text254warn: $this > (($status >= $WARNING) ? (90) : (100))255crit: $this > (($status == $CRITICAL) ? (105) : (110))256```257258This changes one threshold into two thresholds:259260- clear-to-warning raises above 100;261- the warning predicate becomes false at or below 90 (CLEAR when the critical predicate is also false);262- critical can independently use another raise/clear pair.263264Important semantics:265266- This is threshold hysteresis, without a time delay.267- The alert continues evaluating at its normal `every:` cadence.268- It only changes the boundary used by the current status, so a genuine crossing of the recovery threshold acts269 immediately.270- Preserve a non-finite guard around the complete expression when `UNDEFINED` must remain possible.271272Prefer this when independent raise/clear boundaries are meaningful and the signal is expected to linger near one boundary.273Do not use it to redefine a categorical exact condition into a policy band.274275### Layer 3 — delay transition notifications276277Use `delay:` when notification execution should wait after a state change:278279```text280delay: down 5m multiplier 1.5 max 1h281```282283- `up` is selected when the new numeric status is greater than the old; `down` otherwise.284 This includes `UNDEFINED (-1)` → `CLEAR (1)` using `up`, not just warning/critical escalation.285 Owners: `src/health/health_event_loop.c` (delay selection), `src/health/rrdcalc.h` (status values).286- `multiplier` grows the delay when the state changes during the delay.287- `max` caps the accumulated delay.288289This is the only layer that postpones an alert transition notification. It can suppress rapid clear/reactivate290notification cycles, but it can also postpone notice of a real incident. Use it sparingly and record the expected291notification delay in the alert contract. The status still changes on the evaluation beat: `health_event_loop.c`292updates it immediately, while `health_notifications.c` checks the notification due time.293294### Selection procedure2952961. Establish whether the incident is categorical, threshold policy, or derived arithmetic.2972. Select the smallest truthful `lookup:` window and aggregation first.2983. For a noisy policy threshold, choose explicit raise/clear thresholds before adding transition delay.2994. Add `delay:` only when rapid transition notifications are independently harmful and later notification is acceptable.3005. Test each layer: input noise, boundary crossing, recovery, reactivation, non-finite input, partial gap, and the exact301 expected notification time.302303### Persistence Intent304305Treat another system's `for: D` as an operator intent to suppress transient conditions. It is not a requirement to emulate306that system's pending-state machine. Choose the closest safe Netdata-native behavior from the source's actual numeric307state space, set an explicit `every:`, and disclose the differences:308309- For a binary source where **1 means the active fault**, `min -5m unaligned` with an active predicate is true only when310 every **observed numeric value** in the selected window is active. This is a Netdata observation-window adaptation, not311 Prometheus `for: 5m`.312- For a binary source where **0 means the active fault**, use the complementary aggregation/predicate that requires all313 observed values to be zero; consult the lookup reference and prove it with state-sequence tests.314- For a tri-state or enumerated source, do not apply a binary `min`/`max` rule by analogy. Use an exact predicate over the315 full state space. For example, `countif(!=target)` returns the percentage of observed values outside `target`; zero means316 every observed value matched.317- `min`, `max`, and `countif` operate on the numeric samples they receive. Test active-to-other-state transitions in both318 directions and record the intended partial-gap behavior.319- A new chart may become runnable with up to one chart update interval less history than the requested lookup window.320 Therefore an already-active condition can raise up to roughly one source beat before `D` after chart creation. Do not321 conceal this with a hand-authored "window complete" flag.322- A missing sample does not reset an observation window. Values before and after a partial gap may contribute to the same323 lookup. Collection-failure ownership remains separate unless the alert contract explicitly owns freshness.324- One health rule has one historical database lookup. A predicate combining multiple dimensions cannot gain exact325 historical persistence by looking up one dimension and combining it with the others' current values. Prefer, in order:326 a source-owned derived dimension when the persisted compound condition is essential; otherwise a truthful current-state327 adaptation; never a mixed-time formula that changes the incident meaning.328- Do not lengthen the window mechanically by one assumed collector interval. Collector cadence is configurable, and that329 does not repair partial gaps or create a source-engine pending state.330331For every persistence adaptation, prove: chart startup, observed active history, each recovery state, each higher/lower332enumerated state, a partial source gap, a stale non-runnable lookup, collection resumption, chart obsoletion, and the333configured evaluation cadence. Never invent a `pending` state that Netdata does not expose, and never declare fidelity334from the look of an expression alone.335336## Keep Ownership And Identity Non-Duplicating337338- Search existing stock alerts before adding one. Reuse an existing alert only when it really owns the same logical339 incident; disclose routing/severity/lifecycle differences rather than silently relabeling it.340- Keep source collection failure, component/API collection failure, source data-state failure, and client-observed failure341 as separate owners when they identify different operator actions.342- Filter templates with chart labels only when they select the intended RRDSET instance without changing its identity.343 A current metadata label may be used as a filter only when the alert contract explicitly wants that current metadata;344 do not turn it into `instances.by_labels` merely to make filtering convenient. Exclude known named rules from generic345 fallbacks, including special sources whose recovery is chart removal rather than zero.346- Preserve ordinary zero recovery. Do not convert an active-to-zero source into disappearance, and do not treat a347 disappearing source as a normal CLEAR.348- Use the ordering guide for template/alarm precedence and user-versus-stock override behavior. Same-name definitions are349 an override mechanism; different names coexist and can therefore duplicate incidents.350351## Validate The Actual Contract352353Run the smallest relevant tests first, then the full affected suite. A complete alert change normally needs all applicable354items below:3553561. Run `/usr/sbin/netdata -W healthconfigtest` for the built-in health parser and lookup suite.3572. Add or update a focused test that reads the shipped alert template and asserts its context, labels, lookup, units,358 cadence, expressions, routing, source ownership, and declared fidelity—not merely a copied expected string.3593. Test the signal's lifecycle through the real query/health runtime where practical. If a lower-level deterministic model360 is necessary, derive it directly from runtime timestamps and numeric-point selection; do not pass an arbitrary361 `windowComplete` flag or label skipped NULLs as continuous evaluation. Cover startup, active transition, normal zero362 recovery, a true all-null query, partial-null behavior, stale non-runnable behavior, collection resumption, known363 disappearance/`REMOVED`, and label identity.3644. For an expression that relies on `NaN`, test the evaluator result directly. Check both direct `NaN` propagation and any365 comparison/conditional branch; do not infer the result from ordinary floating-point intuition.3665. Run collector/profile validation when the alert depends on a collector or profile change. Include source absence and367 collision-bearing labels where relevant.3686. Search for same-incident alerts, duplicate contexts, old names, fallback overlap, and generated artifacts. Record the369 result in the SOW.3707. For an externally sourced alert pack, commit a source-pinned mapping that records the original condition, scope,371 severity, persistence intent, supported releases, Netdata owner, adaptation, and known differences. Tests MUST consume372 that mapping rather than restating the intended result independently.3738. Validate every published configuration example through the same job-construction prerequisites users need. In374 particular, a job referencing `vnode:` is incomplete unless the example defines or clearly links the required vnode.3759. Run `git diff --check` and the project-required validation/review gate before claiming completion.376377`healthconfigtest` runs built-in health parser and lookup cases. It does not load every stock health template, prove that a378template attaches to the intended chart, or prove the runtime lifecycle. Cover those separately with source-aware contract379and transition tests.380381## Completion Check382383Before requesting review, confirm all of the following:384385- The alert has exactly one logical owner and a stable scope.386- Its NIDL instance map shows one monitored component and one instance-level alert target; any required aggregate is a387 source-owned higher-level RRDSET, not an alert-side merge.388- Its source state values, gaps, absence, and recovery have been tested rather than assumed.389- Its `NaN`, `UNDEFINED`, `CLEAR`, and `REMOVED` transitions match the recorded contract.390- Its timing is the closest safe Netdata adaptation, with startup/gap/stale differences disclosed; `delay:` is not391 standing in for another engine's persistence state machine.392- Notification defaults follow the approved product policy.393- No shared health/query behavior was added or assumed without the required separate scope approval.394395## Authoritative References396397- Syntax, variables, lookups, and stock patterns: `src/health/REFERENCE.md`398- State model and missing-data summary: `src/health/README.md`399- NIDL component/instance/dimension/label model: `docs/NIDL-Framework.md`400- Template/alarm and user/stock precedence: `src/health/alert-configuration-ordering.md`401- Alert eligibility, lookup execution, and `REMOVED`: `src/health/health_event_loop.c`402- `$now`, `$last_collected_t`, `$update_every`, dimension freshness, same-chart variables, cross-chart/context403 variables, alert variables, and label-score selection: `src/health/health_variable.c`404- Equal-label score implementation: `src/database/rrdlabels.c:rrdlabels_common_count()`405- Query gaps and grouping: `src/web/api/queries/query-execute.c` and the relevant grouping implementation406- `NaN` expression semantics: `src/libnetdata/eval/eval-evaluate.c`