towerops/lib/towerops/monitoring/monitoring_check.ex
Graham McIntire a61abd836c
fix: cloud poller automatic rebalancing
- create MonitoringCheck schema for the monitoring_checks table, fixing
  silent data loss where ping results were dropped by the wrong schema
- update agent channel and device monitor worker to use new schema
- fix Stats queries to use MonitoringCheck instead of Check schema
- add list_online_cloud_pollers and list_cloud_polled_devices queries
- add CloudLatencyProbeWorker to dispatch cross-agent latency probes
  every 8 hours via PubSub to all online cloud pollers
- scope AgentLatencyEvaluator to cloud pollers only with cloud_only
  filter, lower min_checks (5), wider time window (48h), and
  device-level assignments to avoid changing site/org defaults
- update cron schedule: probes at 0/8/16h, evaluation at 0:30/8:30/16:30
- refactor monitoring.ex and http_executor.ex to fix credo complexity
2026-02-12 15:32:33 -06:00

37 lines
1 KiB
Elixir

defmodule Towerops.Monitoring.MonitoringCheck do
@moduledoc """
Schema for the `monitoring_checks` table.
Stores ping/monitoring check results from agents and the Phoenix server.
Each record captures the device status, response time, and which agent
performed the check.
"""
use Ecto.Schema
import Ecto.Changeset
alias Towerops.Agents.AgentToken
alias Towerops.Devices.Device
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "monitoring_checks" do
field :status, :string
field :response_time_ms, :float
field :checked_at, :utc_datetime
belongs_to :device, Device
belongs_to :agent_token, AgentToken
timestamps(type: :utc_datetime, updated_at: false)
end
def changeset(monitoring_check, attrs) do
monitoring_check
|> cast(attrs, [:device_id, :agent_token_id, :status, :response_time_ms, :checked_at])
|> validate_required([:device_id, :status, :checked_at])
|> foreign_key_constraint(:device_id)
|> foreign_key_constraint(:agent_token_id)
end
end