Skip to main content
The Health extension sends a report each time NervesHub asks for one. A report carries the device’s metrics, any metadata you add, and its currently raised alarms. NervesHub uses the report for the device’s health status, the Health tab charts, and the alarms shown on the device page. For what NervesHub does with the reports, see Health monitoring.

Requirements

  • nerves_hub_link 2.6.0 or later.
  • NervesHub 2.3.0 or later.
  • Metric history charts and health profiles need ClickHouse on the instance. Without it, devices still report and NervesHub still shows current values. See Feature prerequisites.

Enable it

1

Keep Health in your firmware

NervesHubLink.Extensions.Health is in the default extension_modules list. You only need to act if you set extension_modules yourself, because that setting replaces the default list:
2

Turn it on for the product

In Product settings, on the General tab, switch on Health in the Device extensions card. A product created in the web UI starts with every extension on. A product created through the API or nh starts with every extension off.
3

Check the device setting

On the device’s Settings tab, Health in the Extensions card is on by default.

Check that it works

Reconnect the device if it was connected before you turned Health on. Then open the device in NervesHub. The Health card on the Details tab and the Now card on the Health tab show the latest readings. NervesHub asks for a report shortly after the extension attaches, then on an interval. See When reports are sent. To see what the device would report, without sending it:

What is reported by default

The default report, NervesHubLink.Extensions.Health.DefaultReport, samples three metric sets: One more metric set is available but not in the defaults: The default report also sends the device’s currently raised alarms. See Alarms.

Choose the metric sets

Set metric_sets to control what is sampled. Use :defaults (or :default) to keep the three default sets and add to them:
Name sets one by one to send only some of the defaults:
Set metric_sets: [] to send no metric sets.

Add your own metrics

Implement the NervesHubLink.Extensions.Health.MetricSet behaviour. It has one callback, sample/0, which returns a map of metric names to numbers:
Then add the module to metric_sets. For a single value, you can skip the module and give the default report a value or an MFA under metrics:
NervesHub applies these limits to the metrics in each report:
  • A name longer than 64 bytes is dropped.
  • At most 20 names per report are kept, in sorted order. The instance operator can raise this with DEVICE_METRICS_MAX_KEYS_PER_REPORT.
  • A value that is not a number is dropped.
The three default metric sets use 11 names. When NervesHub drops something, it stores the rest of the report and raises a product notification. Custom metrics appear on the device’s Health tab. To have one affect the device’s health status, add it to a health profile.

Add metadata

Metadata is a map of string keys to string values. Each value is a string or an MFA that returns one:

Alarms

The default report sends every alarm currently raised on the device. It reads them from alarmist when your project depends on it, and from Erlang’s :alarm_handler otherwise (nerves_hub_link 2.8.0 and later). The nerves_hub_link guide recommends alarmist. Alarms travel inside the health report, so NervesHub learns about a change the next time it asks for a report. NervesHub never raises an alarm itself. Thresholds on metrics are a separate feature, health profiles.

Ignore disk-full alarms for a mount

Erlang raises :disk_almost_full for / at startup on a Nerves device, because the read-only root filesystem is sized to fit the firmware. The default report filters that alarm out. To change which mounts are ignored (nerves_hub_link 2.9.0 and later):
This list replaces the default. Include "/" if you still want it ignored.

Replace the report

Implement NervesHubLink.Extensions.Health.Report and point the config at your module:
The behaviour’s callbacks are timestamp/0, metadata/0, alarms/0, metrics/0, checks/0 and connectivity/0.

When reports are sent

NervesHub sets the pace. The device answers each health:check with one report. These are instance settings (FEATURES_HEALTH_INTERVAL_MINUTES, FEATURES_HEALTH_UI_POLLING_SECONDS, FEATURES_HEALTH_FIRST_CHECK_WINDOW_SECONDS). You cannot change them from firmware.