Kepler.SystemMonitor (Kepler v0.1.0)

Copy Markdown View Source

Tier 0: thresholds the VM enforces on Kepler's behalf.

:erlang.system_monitor/2 costs nothing in steady state. You hand the VM a set of thresholds and a message arrives only when one is exceeded — no polling, no sampling, no handler on a hot path. It is the cheapest signal available on the BEAM and the first place to look when you want to know about long garbage collections, oversized heaps, or ports that keep going busy.

watch :long_gc do
  source system_monitor: {:long_gc, 500}
  fire immediately
end

There is only one

A node has exactly one system monitor, and setting it replaces whatever was there. :observer uses it. :recon uses it. Your own code may use it. Kepler therefore checks first and, by default, yields: if something else holds the monitor, Kepler logs which watches are inactive and leaves the existing monitor alone.

Set config :kepler, system_monitor: [takeover: true] if you would rather Kepler win — but understand that this breaks whoever held it, silently, from their point of view.

On shutdown Kepler restores the previous monitor if it still owns it.

Thresholds

Several watches may declare the same monitor type with different thresholds. Kepler installs the most sensitive of them and routes each message to the watches whose own threshold it actually exceeded, so a {:long_gc, 500} and a {:long_gc, 2_000} watch behave independently rather than the second one firing on every message the first one wanted.

Summary

Functions

Returns a specification to start this module under a supervisor.

The value a monitor message reports, for the type that has a threshold.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

observed(type, info)

@spec observed(atom(), term()) :: number() | nil

The value a monitor message reports, for the type that has a threshold.

Exposed for testing; there is no reason to call it.