Packages

Library for tracking HTTP status code rates and service health monitoring

Current section

Files

Jump to
status_code_tracker lib status_code_tracker config.ex
Raw

lib/status_code_tracker/config.ex

defmodule StatusCodeTracker.Config do
defstruct keep_unhealthy?: false,
time_window_seconds: 60,
error_threshold: 10,
unhealthy_action: nil,
unhealthy_status_code: 503,
verbose?: false,
extra_checks: nil,
unhealthy_message: nil
def new(opts \\ []) do
%__MODULE__{
keep_unhealthy?: Keyword.get(opts, :keep_unhealthy?, false),
time_window_seconds: Keyword.get(opts, :time_window_seconds, 60),
error_threshold: Keyword.get(opts, :error_threshold, 10),
unhealthy_status_code: Keyword.get(opts, :unhealthy_status_code, 503),
verbose?: Keyword.get(opts, :verbose?, true),
unhealthy_action:
Keyword.get(opts, :unhealthy_action, fn ->
:noop
end),
extra_checks:
Keyword.get(opts, :extra_checks, fn ->
false
end),
unhealthy_message:
Keyword.get(opts, :unhealthy_message, "Service unhealthy due to many 5xx")
}
end
def get_config do
Application.get_env(:status_code_tracker, :settings, [])
|> __MODULE__.new()
end
end