towerops/lib/towerops/monitoring/check.ex
Graham McIntire 1c400259fc
fix: use microsecond precision for ICMP latency measurements
- Changed ping module to use microsecond timer resolution instead of millisecond
- Prevents 0ms readings for very fast pings (localhost, local network)
- Updated response_time_ms to float type to store decimal precision
- Migration converts existing integer values to float
2026-01-18 12:52:29 -06:00

30 lines
846 B
Elixir

defmodule Towerops.Monitoring.Check do
@moduledoc """
Monitoring check schema for device reachability status.
Records the result of each monitoring check (success/failure) with latency.
"""
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "monitoring_checks" do
field :status, Ecto.Enum, values: [:success, :failure]
field :response_time_ms, :float
field :checked_at, :utc_datetime
belongs_to :device, Towerops.Devices.Device
timestamps(type: :utc_datetime, updated_at: false)
end
@doc false
def changeset(check, attrs) do
check
|> cast(attrs, [:device_id, :status, :response_time_ms, :checked_at])
|> validate_required([:device_id, :status, :checked_at])
|> foreign_key_constraint(:device_id)
end
end