Packages

Example integration — monitors this application's own BEAM VM health, with its dashboard panel bundled in the same package as a separate module (Integrations.Self.Display) — one install, both halves; a release without raven_web simply runs the monitor headless.

Current section

Files

Jump to
raven_integration_self lib integrations self.ex
Raw

lib/integrations/self.ex

defmodule Integrations.Self do
@moduledoc """
Example integration — monitors this application's own BEAM VM health.
Collects stats directly from the VM: memory, process count, run queue,
uptime, Elixir version, OTP version, and node name. No network calls,
no external dependencies.
Collection only — see `Integrations.Self.Display` (same package) for the
dashboard panel. `Display.BundledDefault` auto-hooks it whenever this
monitor starts.
"""
use CodeNameRaven.Monitor
def integration_id, do: "com.neonhippo.raven.self"
def version, do: "1.2.0"
@impl true
def target_uri(_params) do
{:ok, "raven://instance/#{CodeNameRaven.Runtime.instance_id()}"}
end
@impl true
def collect(_params, state) do
memory = :erlang.memory()
{uptime_ms, _} = :erlang.statistics(:wall_clock)
result = %{
node: node() |> to_string(),
elixir_version: System.version(),
otp_version: :erlang.system_info(:otp_release) |> to_string(),
uptime_seconds: div(uptime_ms, 1_000),
process_count: :erlang.system_info(:process_count),
run_queue: :erlang.statistics(:run_queue),
memory: %{
total: memory[:total],
processes: memory[:processes],
binary: memory[:binary],
ets: memory[:ets]
}
}
{:ok, result, state}
end
@impl true
# If we can read our own stats, we are alive.
def healthy?(_result), do: :up
end