Packages

ICMP ping monitor, with its dashboard panel bundled in the same package as a separate module (Integrations.Ping.Display, #299) — one install, both halves; a release without raven_web simply runs the monitor headless.

Current section

Files

Jump to
raven_integration_ping lib integrations ping display.ex
Raw

lib/integrations/ping/display.ex

defmodule Integrations.Ping.Display do
@moduledoc """
Dashboard panel for `Integrations.Ping` (same package).
Nested under the monitor's own namespace deliberately — the package's
top-level module name never changes, and this module's name is
guaranteed distinct from any separately-published standalone display
package. `Display.BundledDefault` auto-hooks this whenever
`Integrations.Ping` starts, the same as if they were still one module.
"""
use CodeNameRaven.Display, category: :infrastructure, size_hint: :medium
@impl true
def display_name, do: "Ping"
@impl true
def compatible_monitors, do: [Integrations.Ping]
@impl true
def render(assigns) do
result = assigns[:result]
assigns = Map.merge(assigns, %{result: result})
~H"""
<div class="space-y-3">
<div class="flex items-start justify-between gap-2">
<div class="min-w-0">
<h2 class="text-sm font-semibold text-base-content truncate">
<%= @config.name || get_in(@config.params, [:host]) || "Ping" %>
</h2>
<p class="text-xs font-mono text-base-content/40 truncate">
<%= get_in(@config.params, [:host]) || get_in(@config.params, ["host"]) %>
</p>
</div>
<CodeNameRaven.MonitorComponents.status_chip status={@status} />
</div>
<div :if={@result} class="grid grid-cols-3 gap-2">
<CodeNameRaven.MonitorComponents.stat
label="Packet Loss"
value={"#{@result.packet_loss_pct}%"} />
<CodeNameRaven.MonitorComponents.stat
label="Avg RTT"
value={if @result.avg_rtt_ms, do: "#{@result.avg_rtt_ms} ms", else: "—"} />
<CodeNameRaven.MonitorComponents.stat
label="Sent / Recv"
value={"#{@result.packets_transmitted}/#{@result.packets_received}"} />
</div>
<CodeNameRaven.MonitorComponents.error_message message={@last_error} />
<CodeNameRaven.MonitorComponents.check_time checked_at={@last_checked_at} />
</div>
"""
end
end