// glossary-ignore-file: the section is for the superadmin only. import Link from "next/link"; import { notFound } from "next/navigation"; import { Activity, Pause, Play, Trash2 } from "lucide-react"; import { describeTarget, FEATURES, observeRemindMin, getMonitor, isSuperadmin, monitorChecks, monitorIncidents, monitorView } from "@peppa/core"; import { loadEnv } from "@peppa/shared"; import { LiveRefresh } from "@/components/LiveRefresh"; import { Hidden } from "@/components/cards"; import { CheckStrip, KIND_LABEL, MonitorFields, OutageLine, pct, StateBadge } from "@/components/Observability"; import { ago, Disclosure, Empty, Flash, PageHeader, Section } from "@/components/common"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Workspace } from "@/components/Workspace"; import { requireUser } from "@/lib/auth"; import { db } from "@/lib/db"; import { getT } from "@/lib/i18n"; import { deleteMonitorAction, pauseMonitorAction, updateMonitorAction } from "../actions"; export const dynamic = "force-dynamic"; const PAGE = 100; const when = (iso: string) => new Date(iso).toLocaleString("ru-RU", { day: "2-digit", month: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" }); export default async function MonitorPage({ params, searchParams }: { params: Promise<{ id: string }>; searchParams: Promise<{ error?: string; page?: string }> }) { const user = await requireUser(); const t = await getT(); if (!(await isSuperadmin(db, user))) notFound(); const { id } = await params; const { error, page } = await searchParams; const found = getMonitor(Number(id)); if (!found) notFound(); const m = monitorView(found); const p = Math.max(0, Number(page) || 0); const checks = monitorChecks(m.id, { limit: PAGE + 1, offset: p * PAGE }); const incidents = monitorIncidents(m.id); const web = loadEnv().PEPPA_WEB_URL; return (
{t("Observability")}} title={<>{m.name}} > {t(KIND_LABEL[m.kind])} {describeTarget(m, web)}
{t("Аптайм 24 ч:")} {pct(m.uptime24h)} {t("7 дней:")} {pct(m.uptime7d)} {m.stateSince ? t("в этом состоянии {ago}", { ago: ago(new Date(m.stateSince), t) }) : ""}
{m.lastDetail?.reason ?

{String(m.lastDetail.reason)}

: null}

{m.kind === "heartbeat" && (

{t("Сервис отмечается запросом GET или POST по адресу:")} {describeTarget(m, web)}

)}

{t("Раз в {n} с · «не работает» после {f} неудач подряд · «работает» после {r} удач · создал {who}", { n: m.intervalSec, f: m.failThreshold, r: m.recoverThreshold, who: m.createdBy })} {" · "} {(m.remindMin ?? observeRemindMin()) ? t("напоминание раз в {n} мин", { n: m.remindMin ?? observeRemindMin() }) : t("без напоминаний")}

{t("Что отключать при сбое:")} {m.features.length ? m.features.map((f) => t(FEATURES[f].label)).join(", ") : t("ничего")}

{t("Удалить")}}>
{t("Удалить мониторинг вместе с журналом?")}
{incidents.length === 0 ? ( {t("Сбоев не было.")} ) : (
    {incidents.map((i) => (
  • {when(i.startedAt)} → {i.endedAt ? when(i.endedAt) : t("сейчас")} {i.reason} {i.quiet && {t("(вместе с интернетом, без сообщения)")}} {i.reminders > 0 && {t("напоминаний: {n}", { n: i.reminders })}}
  • ))}
)}
{checks.length === 0 ? ( {t("Проверок ещё не было.")} ) : (
{checks.slice(0, PAGE).map((c) => ( ))}
{when(c.at)} {!c.ok ? t("неудача") : c.degraded ? t("нестабильно") : "ok"} {c.latencyMs != null ? t("{n} мс", { n: c.latencyMs }) : ""} {String(c.detail.reason ?? "")}{c.detail.status != null ? ` · ${c.detail.status}` : ""}
)}
{p > 0 && {t("← новее")}} {checks.length > PAGE && {t("старее →")}}
); }