Aggiunge monitoraggio ops: health check, log scanner, dashboard e notifiche.

Introduce incidenti con dedup, job Sidekiq ogni 3 min, scan log cron, /up/deep,
dashboard /admin/ops e push ntfy; include Sentry opzionale e fix test suite.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-12 08:16:47 +02:00
parent ce8939fffb
commit 52cfffb83f
44 changed files with 1396 additions and 24 deletions

View File

@@ -84,26 +84,57 @@ module Admin
def disk_usage_for(path)
return unavailable_disk unless path.present? && (Dir.exist?(path) || File.exist?(path))
usage = disk_usage_via_statvfs(path) || disk_usage_via_df(path)
return unavailable_disk unless usage
usage.merge(dir_size_bytes: recordings_dir_size(path))
rescue StandardError
unavailable_disk
end
def disk_usage_via_statvfs(path)
return nil unless File.respond_to?(:statvfs)
stat = File.statvfs(path)
total = stat.blocks * stat.frsize
free = stat.bavail * stat.frsize
used = total - free
build_disk_usage(path, total: total, used: used, free: free)
rescue StandardError
nil
end
def disk_usage_via_df(path)
output = shell_out("df -B1 --output=size,used,avail,pcent,target #{Shellwords.escape(path)} 2>/dev/null").strip
line = output.lines.map(&:strip).reject(&:blank?).last
return nil if line.blank? || line.start_with?("Filesystem")
parts = line.split
return nil if parts.size < 5
total = parts[0].to_i
used = parts[1].to_i
free = parts[2].to_i
pct = parts[3].delete("%").to_f
build_disk_usage(path, total: total, used: used, free: free, used_percent: pct)
rescue StandardError
nil
end
def build_disk_usage(path, total:, used:, free:, used_percent: nil)
{
path: path,
total_bytes: total,
used_bytes: used,
free_bytes: free,
used_percent: total.positive? ? ((used.to_f / total) * 100).round(1) : 0.0,
dir_size_bytes: recordings_dir_size(path)
used_percent: used_percent || (total.positive? ? ((used.to_f / total) * 100).round(1) : 0.0)
}
rescue StandardError
unavailable_disk
end
def recordings_dir_size(path)
return nil unless path == RECORDINGS_PATH && Dir.exist?(path)
`du -sb #{Shellwords.escape(path)} 2>/dev/null`.split.first.to_i
shell_out("du -sb #{Shellwords.escape(path)} 2>/dev/null").split.first.to_i
rescue StandardError
nil
end
@@ -112,6 +143,10 @@ module Admin
{ path: nil, total_bytes: nil, used_bytes: nil, free_bytes: nil, used_percent: nil, dir_size_bytes: nil }
end
def shell_out(cmd)
`#{cmd}`
end
def read_network
rx, tx = parse_net_bytes
prev = MetricsStore.net_totals