Packages

A 'plugin-based' monitor and alert manager for BEAM Nodes and Hosts

Retired package: Deprecated

Current section

Files

Jump to
pharos src pharos@config.erl
Raw

src/pharos@config.erl

-module(pharos@config).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/pharos/config.gleam").
-export([new/0, with_statistics/2, with_thresholds/2, with_custom_statistics/2, with_custom_thresholds/2, with_alert_sinks/2, with_memory_unit/2, with_soak_period/2, with_cool_period/2, with_default_alert_level/2, threshold_id/1]).
-export_type([threshold/0, alert_sink/0, config/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" User-facing configuration for `pharos.start_link`.\n"
"\n"
" Build a `Config` with `new/0` (sensible defaults), pipe through the\n"
" `with_*` setters to add statistics, thresholds, and tune the alert\n"
" timing knobs, then pass it to `pharos.start_link`.\n"
).
-type threshold() :: {total_memory, float()} |
{process_memory, float()} |
{system_memory, float()} |
{binary_memory, float()} |
{ets_memory, float()} |
{total_run_queue, integer()} |
{cpu_run_queue, integer()} |
{process_count, integer()} |
{atom_count, integer()} |
{port_count, integer()} |
{persistent_term_count, integer()} |
{persistent_term_memory, float()}.
-type alert_sink() :: {log, logging:log_level()}.
-type config() :: {config,
list(pharos@statistic:statistic()),
list(threshold()),
list(pharos@probe:probe()),
list(pharos@probe:probe_threshold()),
list(alert_sink()),
pharos@measurement:memory_unit(),
integer(),
integer(),
pharos@alert:alert_level()}.
-file("src/pharos/config.gleam", 90).
?DOC(
" Sensible defaults: no statistics, no thresholds, log alerts at\n"
" `Warning`, scale memory in `Mb`, 30 s soak, 60 s cool, default alert\n"
" level `Warning`. Pipe through `with_*` setters to customise.\n"
).
-spec new() -> config().
new() ->
{config, [], [], [], [], [{log, warning}], mb, 30000, 60000, warning}.
-file("src/pharos/config.gleam", 105).
?DOC(" Set the statistics to poll. Replaces any previously configured list.\n").
-spec with_statistics(config(), list(pharos@statistic:statistic())) -> config().
with_statistics(Config, Statistics) ->
{config,
Statistics,
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
erlang:element(6, Config),
erlang:element(7, Config),
erlang:element(8, Config),
erlang:element(9, Config),
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 110).
?DOC(" Set the thresholds to evaluate. Replaces any previously configured list.\n").
-spec with_thresholds(config(), list(threshold())) -> config().
with_thresholds(Config, Thresholds) ->
{config,
erlang:element(2, Config),
Thresholds,
erlang:element(4, Config),
erlang:element(5, Config),
erlang:element(6, Config),
erlang:element(7, Config),
erlang:element(8, Config),
erlang:element(9, Config),
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 115).
?DOC(" Set the custom probes to poll. Replaces any previously configured list.\n").
-spec with_custom_statistics(config(), list(pharos@probe:probe())) -> config().
with_custom_statistics(Config, Probes) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
Probes,
erlang:element(5, Config),
erlang:element(6, Config),
erlang:element(7, Config),
erlang:element(8, Config),
erlang:element(9, Config),
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 120).
?DOC(" Set the custom probe thresholds. Replaces any previously configured list.\n").
-spec with_custom_thresholds(config(), list(pharos@probe:probe_threshold())) -> config().
with_custom_thresholds(Config, Thresholds) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
Thresholds,
erlang:element(6, Config),
erlang:element(7, Config),
erlang:element(8, Config),
erlang:element(9, Config),
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 128).
?DOC(" Set the alert sinks. Replaces any previously configured list.\n").
-spec with_alert_sinks(config(), list(alert_sink())) -> config().
with_alert_sinks(Config, Sinks) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
Sinks,
erlang:element(7, Config),
erlang:element(8, Config),
erlang:element(9, Config),
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 134).
?DOC(
" Set the memory unit used for threshold comparisons and decoded\n"
" measurements.\n"
).
-spec with_memory_unit(config(), pharos@measurement:memory_unit()) -> config().
with_memory_unit(Config, Unit) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
erlang:element(6, Config),
Unit,
erlang:element(8, Config),
erlang:element(9, Config),
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 140).
?DOC(
" Set the soak period (milliseconds a threshold must stay breached before\n"
" firing). Set to 0 to fire immediately.\n"
).
-spec with_soak_period(config(), integer()) -> config().
with_soak_period(Config, Milliseconds) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
erlang:element(6, Config),
erlang:element(7, Config),
Milliseconds,
erlang:element(9, Config),
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 146).
?DOC(
" Set the cool-down period (milliseconds recovery must hold before\n"
" resolving).\n"
).
-spec with_cool_period(config(), integer()) -> config().
with_cool_period(Config, Milliseconds) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
erlang:element(6, Config),
erlang:element(7, Config),
erlang:element(8, Config),
Milliseconds,
erlang:element(10, Config)}.
-file("src/pharos/config.gleam", 151).
?DOC(" Set the default alert level attached to firing alerts.\n").
-spec with_default_alert_level(config(), pharos@alert:alert_level()) -> config().
with_default_alert_level(Config, Level) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
erlang:element(6, Config),
erlang:element(7, Config),
erlang:element(8, Config),
erlang:element(9, Config),
Level}.
-file("src/pharos/config.gleam", 162).
?DOC(
" Stable string id derived from a threshold variant. Used to register\n"
" per-threshold alert managers under a deterministic name so they can be\n"
" looked up after a restart.\n"
).
-spec threshold_id(threshold()) -> binary().
threshold_id(Threshold) ->
case Threshold of
{total_memory, _} ->
<<"total_memory"/utf8>>;
{process_memory, _} ->
<<"process_memory"/utf8>>;
{system_memory, _} ->
<<"system_memory"/utf8>>;
{binary_memory, _} ->
<<"binary_memory"/utf8>>;
{ets_memory, _} ->
<<"ets_memory"/utf8>>;
{total_run_queue, _} ->
<<"total_run_queue"/utf8>>;
{cpu_run_queue, _} ->
<<"cpu_run_queue"/utf8>>;
{process_count, _} ->
<<"process_count"/utf8>>;
{atom_count, _} ->
<<"atom_count"/utf8>>;
{port_count, _} ->
<<"port_count"/utf8>>;
{persistent_term_count, _} ->
<<"persistent_term_count"/utf8>>;
{persistent_term_memory, _} ->
<<"persistent_term_memory"/utf8>>
end.