Raxol.Core.Runtime.Plugins.ResourceBudget (Raxol Core v2.4.0)

Copy Markdown View Source

Runtime resource monitoring per plugin.

Tracks actual resource usage against declared budgets from plugin manifests. Runs on a configurable timer (default 5s) and takes action when plugins exceed their budgets.

Actions (configurable per plugin):

  • :warn -- log warning + emit telemetry event
  • :throttle -- reduce event delivery rate to plugin
  • :kill -- unload the plugin via PluginLifecycle

Summary

Functions

Checks resource usage for a specific plugin against its budget.

Returns a specification to start this module under a supervisor.

Checks all monitored plugins and returns their status.

Sets the enforcement action for a plugin.

Returns whether a plugin is currently throttled.

Types

action()

@type action() :: :warn | :throttle | :kill

budget()

@type budget() :: %{
  max_memory_mb: number(),
  max_cpu_percent: number(),
  max_ets_tables: non_neg_integer(),
  max_processes: non_neg_integer()
}

usage()

@type usage() :: %{
  memory_mb: number(),
  cpu_percent: number(),
  ets_tables: non_neg_integer(),
  processes: non_neg_integer()
}

Functions

check(plugin_id)

@spec check(atom()) :: {:ok, usage()} | {:over_budget, usage(), budget()}

Checks resource usage for a specific plugin against its budget.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

monitor_all()

@spec monitor_all() :: [{atom(), :ok | :over_budget}]

Checks all monitored plugins and returns their status.

set_action(plugin_id, action)

@spec set_action(atom(), action()) :: :ok

Sets the enforcement action for a plugin.

start_link(opts \\ [])

throttled?(plugin_id)

@spec throttled?(atom()) :: boolean()

Returns whether a plugin is currently throttled.