defmodule Integrations.Http.Display do @moduledoc """ Dashboard panel for `Integrations.Http` (same package). Nested under the monitor's own namespace deliberately — `#299`'s split pattern: the package's top-level module name (`Integrations.Http`) never changes, so existing `raven.toml` monitor configs keep resolving unmodified, and this module's name is guaranteed distinct from the separately-published `raven_integration_http_display`'s `Integrations.HttpDisplay` (no dot) — both packages can install and load simultaneously without colliding. `Display.BundledDefault` auto-hooks this whenever `Integrations.Http` starts, the same as if they were still one module — an integrator bundling Monitor and Display in one package, even across two files, is a statement of intent that they belong together by default. """ use CodeNameRaven.Display, category: :web, size_hint: :full def display_timezone, do: "America/Chicago" @impl true def display_name, do: "HTTP Check" @impl true def compatible_monitors, do: [Integrations.Http] @impl true def render(assigns) do window_seconds = assigns.config.display_window_seconds cutoff = DateTime.add(DateTime.utc_now(), -window_seconds, :second) sample_key = Map.get(assigns.config, :target_id) || assigns.config.id samples = CodeNameRaven.Runtime.recent_samples(sample_key, limit: 120) samples = Enum.filter(samples, fn s -> DateTime.compare(s.collected_at, cutoff) != :lt end) local_id = CodeNameRaven.Runtime.instance_id() latest_local = samples |> Enum.filter(&(&1.instance_id == local_id)) |> List.last() result = assigns[:result] || (latest_local && %{ status_code: latest_local.status_code, latency_ms: latest_local.latency_ms, cert_expiry_days: latest_local.metrics["cert_expiry_days"], timing: %{ dns_ms: latest_local.metrics["dns_ms"], tcp_ms: latest_local.metrics["tcp_ms"], ssl_ms: latest_local.metrics["ssl_ms"], ttfb_ms: latest_local.metrics["ttfb_ms"], download_ms: latest_local.metrics["download_ms"] }, redirects: latest_local.metrics["redirects"] }) assigns = Map.merge(assigns, %{samples: samples, local_id: local_id, result: result}) ~H"""
<%= @config.params[:url] %>
Cert Expiry
<%= @result.cert_expiry_days %>d
Redirects
<%= @result.redirects %>
<%= @last_error %>
Checked <%= CodeNameRaven.Timezone.format_datetime(@last_checked_at, __MODULE__) %>
<%= @label %>
<%= @value %>