Jellyfin: who is watching, and don't update a machine mid-film
New Jellyfin integration (read-only, every 2 minutes): version, restart wanted, streams and transcoding, failed scheduled tasks, item counts, failed sign-ins. Monitoring -> Jellyfin page with a peak-streams history, three alerts, /metrics. When Jellyfin runs on a managed server, an update run asks first if people are streaming (409 "watching" unless startAnyway), and a patch plan waits up to two hours for them before updating that server. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2f082ca5c2
commit
0146eb8bca
38 files changed
+8136
-13
No files matched your search
@@ -11,6 +11,7 @@ import ProxyHosts from "./pages/ProxyHosts";
|
||||
import AlertRules from "./pages/AlertRules";
|
||||
import HomeAssistant from "./pages/HomeAssistant";
|
||||
import Ups from "./pages/Ups";
|
||||
import Jellyfin from "./pages/Jellyfin";
|
||||
import ServiceLevels from "./pages/ServiceLevels";
|
||||
import Duplicati from "./pages/Duplicati";
|
||||
import MyWorkPage from "./pages/MyWork";
|
||||
@@ -158,6 +159,7 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/alert-rules" element={<AlertRules user={user} />} />
|
||||
<Route path="/home-assistant" element={<HomeAssistant user={user} />} />
|
||||
<Route path="/ups" element={<Ups user={user} />} />
|
||||
<Route path="/jellyfin" element={<Jellyfin />} />
|
||||
<Route path="/service-levels" element={<ServiceLevels user={user} />} />
|
||||
<Route path="/duplicati" element={<Duplicati user={user} />} />
|
||||
<Route path="/ports" element={<Ports user={user} />} />
|
||||
|
||||
+46
-1
@@ -766,6 +766,8 @@ export interface UpdateRunInput {
|
||||
templateId: number;
|
||||
limit: string;
|
||||
windowMinutes: number;
|
||||
/** Somebody is streaming from the machine and the person has seen the warning. */
|
||||
startAnyway?: boolean;
|
||||
}
|
||||
|
||||
export interface UpdatesServer {
|
||||
@@ -1194,6 +1196,44 @@ export interface MonthlyReport {
|
||||
renewals: { kind: string; subject: string; at: string; fromDate: string; toDate: string }[];
|
||||
}
|
||||
|
||||
/** One Jellyfin, as its page shows it. */
|
||||
export interface JellyfinStream {
|
||||
user: string;
|
||||
client: string | null;
|
||||
device: string | null;
|
||||
title: string;
|
||||
transcoding: boolean;
|
||||
paused: boolean;
|
||||
}
|
||||
|
||||
export interface JellyfinInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
runsOn: { id: number; name: string } | null;
|
||||
status: { at: string; ok: boolean; error: string | null } | null;
|
||||
fresh: boolean;
|
||||
state: {
|
||||
serverName: string | null;
|
||||
version: string | null;
|
||||
os: string | null;
|
||||
pendingRestart: boolean;
|
||||
updateAvailable: boolean;
|
||||
streams: JellyfinStream[];
|
||||
tasks: { name: string; category: string | null; state: string; lastStatus: string | null; lastEndedAt: string | null; error: string | null }[];
|
||||
counts: { movies: number | null; series: number | null; episodes: number | null; songs: number | null };
|
||||
failedLogins24h: number | null;
|
||||
updatedAt: string;
|
||||
} | null;
|
||||
problems: { key: string; message: string; severity: "warning" | "critical" }[];
|
||||
}
|
||||
|
||||
export interface JellyfinHistory {
|
||||
jellyfin: { id: number; name: string };
|
||||
days: number;
|
||||
points: { t: string; streams: number; transcodes: number }[];
|
||||
}
|
||||
|
||||
/** A check the app could set up for you, from what it already knows. */
|
||||
/** A backup job Duplicati reported, as the page shows it. */
|
||||
export interface DuplicatiBackup {
|
||||
@@ -2108,7 +2148,7 @@ export interface ManualTaskInput {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export type IntegrationType = "proxmox" | "synology" | "semaphore" | "tailscale" | "gitea" | "dockhand" | "uptimekuma" | "phpipam" | "pbs" | "osticket" | "unifi" | "npm" | "homeassistant" | "ups";
|
||||
export type IntegrationType = "proxmox" | "synology" | "semaphore" | "tailscale" | "gitea" | "dockhand" | "uptimekuma" | "phpipam" | "pbs" | "osticket" | "unifi" | "npm" | "homeassistant" | "ups" | "jellyfin";
|
||||
|
||||
export interface IntegrationField {
|
||||
key: string;
|
||||
@@ -2655,6 +2695,11 @@ export const api = {
|
||||
update: (id: number, data: ServiceLevelInput) => request<{ ok: boolean }>(`/api/service-levels/${id}`, { method: "PUT", body: JSON.stringify(data) }),
|
||||
remove: (id: number) => request<void>(`/api/service-levels/${id}`, { method: "DELETE" }),
|
||||
},
|
||||
jellyfin: {
|
||||
list: () => request<{ jellyfins: JellyfinInfo[] }>("/api/jellyfin"),
|
||||
history: (id: number, days: number) => request<JellyfinHistory>(`/api/jellyfin/${id}/history?days=${days}`),
|
||||
watching: (serverId: number) => request<{ watching: { integrationId: number; integrationName: string; streams: JellyfinStream[] }[]; words: string }>(`/api/jellyfin/watching?serverId=${serverId}`),
|
||||
},
|
||||
ups: {
|
||||
list: () => request<{ ups: UpsInfo[] }>("/api/ups"),
|
||||
history: (id: number, days: number) => request<UpsHistory>(`/api/ups/${id}/history?days=${days}`),
|
||||
|
||||
@@ -47,6 +47,7 @@ const INTEGRATION_TYPE_LABELS: Record<IntegrationType, string> = {
|
||||
npm: "Nginx Proxy Manager",
|
||||
homeassistant: "Home Assistant",
|
||||
ups: "UPS",
|
||||
jellyfin: "Jellyfin",
|
||||
};
|
||||
|
||||
const DNS_PROVIDER_LABELS: Record<DnsProviderType, string> = {
|
||||
|
||||
@@ -18,6 +18,7 @@ const TYPE_LABELS: Record<IntegrationType, string> = {
|
||||
npm: "Nginx Proxy Manager",
|
||||
homeassistant: "Home Assistant",
|
||||
ups: "UPS",
|
||||
jellyfin: "Jellyfin",
|
||||
};
|
||||
|
||||
export default function IntegrationEditForm({
|
||||
|
||||
@@ -17,6 +17,7 @@ const TYPE_LABELS: Record<IntegrationType, string> = {
|
||||
npm: "Nginx Proxy Manager",
|
||||
homeassistant: "Home Assistant",
|
||||
ups: "UPS",
|
||||
jellyfin: "Jellyfin",
|
||||
};
|
||||
|
||||
export default function IntegrationForm({ onCreated, onCancel }: { onCreated: () => void; onCancel: () => void }) {
|
||||
|
||||
@@ -42,6 +42,19 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
const [limit, setLimit] = useState(server.name);
|
||||
const [minutes, setMinutes] = useState(90);
|
||||
const [busy, setBusy] = useState(false);
|
||||
// People streaming from a Jellyfin on this machine: the update may restart it, so they are named first and the person asked.
|
||||
const [watching, setWatching] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.jellyfin
|
||||
.watching(server.id)
|
||||
.then((r) => alive && setWatching(r.words))
|
||||
.catch(() => undefined); // no Jellyfin, or it can't be read: nothing to warn about
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [server.id]);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -68,13 +81,13 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
if (!picked) return;
|
||||
const ok = await confirmDialog({
|
||||
title: `Update ${server.name} now?`,
|
||||
message: `This silences alerts for ${server.name} for up to ${WINDOWS.find((w) => w.minutes === minutes)?.label ?? `${minutes} minutes`}, runs "${picked.template.name}" in ${picked.integration.name} limited to ${limit.trim()}, and waits for the server to report again. The playbook may restart it.`,
|
||||
confirmLabel: "Start the update",
|
||||
message: `${watching ? `${watching[0].toUpperCase()}${watching.slice(1)}, and the update may restart the machine. ` : ""}This silences alerts for ${server.name} for up to ${WINDOWS.find((w) => w.minutes === minutes)?.label ?? `${minutes} minutes`}, runs "${picked.template.name}" in ${picked.integration.name} limited to ${limit.trim()}, and waits for the server to report again. The playbook may restart it.`,
|
||||
confirmLabel: watching ? "Update anyway" : "Start the update",
|
||||
});
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.updateRuns.start({ serverId: server.id, integrationId: picked.integration.id, projectId: picked.template.projectId, templateId: picked.template.id, limit: limit.trim(), windowMinutes: minutes });
|
||||
await api.updateRuns.start({ serverId: server.id, integrationId: picked.integration.id, projectId: picked.template.projectId, templateId: picked.template.id, limit: limit.trim(), windowMinutes: minutes, startAnyway: watching !== "" });
|
||||
try {
|
||||
localStorage.setItem(LAST_KEY, picked.key);
|
||||
} catch {
|
||||
@@ -112,6 +125,12 @@ export default function UpdateRunDrawer({ server, onClose, onStarted }: { server
|
||||
<div className="mb-3">
|
||||
<ImpactNote targets={[{ type: "server", id: server.id }]} verb="may look down while it restarts" />
|
||||
</div>
|
||||
{watching && (
|
||||
<div className="alert alert-warning" role="status">
|
||||
<strong>Somebody is watching.</strong> {watching[0].toUpperCase()}
|
||||
{watching.slice(1)}. The update may restart this machine; you will be asked once more.
|
||||
</div>
|
||||
)}
|
||||
<ol className="text-secondary small ps-3 mb-3">
|
||||
<li>Alerts for this server are silenced (a maintenance window).</li>
|
||||
<li>The playbook runs in Semaphore, for this server only.</li>
|
||||
|
||||
@@ -19,6 +19,7 @@ const TYPE_LABELS: Record<string, string> = {
|
||||
npm: "Nginx Proxy Manager",
|
||||
homeassistant: "Home Assistant",
|
||||
ups: "UPS",
|
||||
jellyfin: "Jellyfin",
|
||||
};
|
||||
|
||||
export type WallLevel = "critical" | "warning" | "ok" | "unsure";
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
IconPlugConnected,
|
||||
IconBrandDocker,
|
||||
IconAffiliate,
|
||||
IconMovie,
|
||||
IconPlayerPlay,
|
||||
IconBrandGit,
|
||||
IconServerCog,
|
||||
@@ -121,6 +122,7 @@ export const NAV: NavEntry[] = [
|
||||
{ to: "/uptime-kuma", label: "Uptime Kuma", icon: <IconActivityHeartbeat size={20} /> },
|
||||
{ to: "/home-assistant", label: "Home Assistant", icon: <IconHome2 size={20} /> },
|
||||
{ to: "/ups", label: "UPS", icon: <IconBatteryCharging size={20} /> },
|
||||
{ to: "/jellyfin", label: "Jellyfin", icon: <IconMovie size={20} /> },
|
||||
{ to: "/service-levels", label: "Service levels", icon: <IconTargetArrow size={20} /> },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -29,6 +29,7 @@ const TYPE_LABELS: Record<IntegrationType, string> = {
|
||||
npm: "Nginx Proxy Manager",
|
||||
homeassistant: "Home Assistant",
|
||||
ups: "UPS",
|
||||
jellyfin: "Jellyfin",
|
||||
};
|
||||
|
||||
/** The page each kind of integration gets once it is connected. */
|
||||
@@ -47,6 +48,7 @@ const TYPE_PAGES: Record<IntegrationType, string> = {
|
||||
npm: "/proxy-hosts",
|
||||
homeassistant: "/home-assistant",
|
||||
ups: "/ups",
|
||||
jellyfin: "/jellyfin",
|
||||
};
|
||||
|
||||
/** "pve.example.lan" out of "https://pve.example.lan:8006/", or the text itself when it isn't an address. */
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type JellyfinHistory, type JellyfinInfo } from "../api/client";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import RangeSelect from "../components/RangeSelect";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import TimeChart from "../components/TimeChart";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { useChartRange } from "../utils/chartRanges";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
function Badge({ j }: { j: JellyfinInfo }) {
|
||||
if (!j.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
|
||||
if (!j.state) return <span className="badge bg-secondary-lt text-secondary">Not read yet</span>;
|
||||
if (!j.fresh) return <span className="badge bg-yellow-lt text-yellow">Can’t be read</span>;
|
||||
if (j.problems.some((p) => p.severity === "critical")) return <span className="badge bg-red-lt text-red">Needs a look</span>;
|
||||
if (j.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">Needs a look</span>;
|
||||
return <span className="badge bg-green-lt text-green">Up</span>;
|
||||
}
|
||||
|
||||
const count = (n: number | null, one: string, many: string) => (n === null ? null : `${n.toLocaleString()} ${n === 1 ? one : many}`);
|
||||
|
||||
function History({ id, name }: { id: number; name: string }) {
|
||||
const [days, setDays] = useChartRange(7);
|
||||
const shown = days > 30 ? 30 : days;
|
||||
const [history, setHistory] = useState<JellyfinHistory | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [to, setTo] = useState(() => Date.now());
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.jellyfin
|
||||
.history(id, shown)
|
||||
.then((res) => {
|
||||
if (!alive) return;
|
||||
setHistory(res);
|
||||
setTo(Date.now());
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => alive && setError(readableError(err)));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [id, shown]);
|
||||
const from = to - shown * 86_400_000;
|
||||
const streams = useMemo(
|
||||
() => [
|
||||
{ name: "Streaming", color: "#4299e1", points: (history?.points ?? []).map((p) => ({ t: p.t, v: p.streams })) },
|
||||
{ name: "Transcoded", color: "#f76707", dash: "4 3", points: (history?.points ?? []).map((p) => ({ t: p.t, v: p.transcodes })) },
|
||||
],
|
||||
[history],
|
||||
);
|
||||
return (
|
||||
<div>
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h4 className="mb-0">Who was watching</h4>
|
||||
<div className="ms-auto">
|
||||
<RangeSelect value={shown} onChange={setDays} only={[1, 7, 30]} />
|
||||
</div>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
{!history && !error && <BlockSkeleton lines={3} />}
|
||||
{history && <TimeChart series={streams} from={from} to={to} unit="value" compact label={`${name}: streams at the busiest`} empty="Nothing read in this stretch yet." format={(v) => `${Math.round(v)}`} />}
|
||||
<div className="text-secondary small mt-1">The most that were streaming at once in each stretch — an average would hide the evening somebody watched.</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ j }: { j: JellyfinInfo }) {
|
||||
const s = j.state;
|
||||
const failed = (s?.tasks ?? []).filter((t) => t.lastStatus === "Failed");
|
||||
const libraries = s ? [count(s.counts.movies, "film", "films"), count(s.counts.series, "series", "series"), count(s.counts.episodes, "episode", "episodes"), count(s.counts.songs, "song", "songs")].filter(Boolean) : [];
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
{j.name} <Badge j={j} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">
|
||||
{j.runsOn && (
|
||||
<>
|
||||
runs on <Link to={`/servers/${j.runsOn.id}`}>{j.runsOn.name}</Link> ·{" "}
|
||||
</>
|
||||
)}
|
||||
{j.status ? <>read <TimeAgo value={j.status.at} /></> : "not read yet"}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{j.status && !j.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {j.status.error ?? "no answer"}.</div>}
|
||||
{j.problems.length > 0 && (
|
||||
<ul className="mb-3">
|
||||
{j.problems.map((p) => (
|
||||
<li key={p.key} className={p.severity === "critical" ? "text-red" : ""}>
|
||||
{p.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{s && (
|
||||
<>
|
||||
<div className="text-secondary small mb-3">
|
||||
{[s.serverName && s.serverName !== j.name ? s.serverName : null, s.version ? `version ${s.version}` : null, s.os, s.updateAvailable ? "an update is available" : null].filter(Boolean).join(" · ")}
|
||||
{libraries.length > 0 && <div>{libraries.join(" · ")}</div>}
|
||||
</div>
|
||||
<h4>Streaming now</h4>
|
||||
{s.streams.length === 0 ? (
|
||||
<div className="text-secondary mb-3">Nobody.</div>
|
||||
) : (
|
||||
<div className="table-responsive mb-3">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Who</th>
|
||||
<th>Watching</th>
|
||||
<th>On</th>
|
||||
<th>How</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.streams.map((x, i) => (
|
||||
<tr key={`${x.user}-${i}`}>
|
||||
<td>{x.user}</td>
|
||||
<td>
|
||||
{x.title}
|
||||
{x.paused && <span className="text-secondary"> (paused)</span>}
|
||||
</td>
|
||||
<td className="text-secondary">{[x.client, x.device].filter(Boolean).join(" · ") || "—"}</td>
|
||||
<td>{x.transcoding ? <span className="badge bg-orange-lt text-orange">Transcoded</span> : <span className="badge bg-green-lt text-green">Direct</span>}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
{failed.length > 0 && (
|
||||
<>
|
||||
<h4>Scheduled tasks that failed</h4>
|
||||
<ul className="mb-3">
|
||||
{failed.map((t) => (
|
||||
<li key={t.name}>
|
||||
<strong>{t.name}</strong>
|
||||
{t.lastEndedAt && (
|
||||
<>
|
||||
{" "}
|
||||
— <TimeAgo value={t.lastEndedAt} />
|
||||
</>
|
||||
)}
|
||||
{t.error && <div className="text-secondary small">{t.error}</div>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
{s.failedLogins24h !== null && s.failedLogins24h > 0 && <div className="text-secondary small mb-3">{s.failedLogins24h} failed sign-in{s.failedLogins24h === 1 ? "" : "s"} in the last day.</div>}
|
||||
</>
|
||||
)}
|
||||
{j.enabled && s && <History id={j.id} name={j.name} />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Jellyfin: whether it is up, who is streaming from it right now and whether that is being transcoded, and the things that need a look. */
|
||||
export default function Jellyfin() {
|
||||
const [data, setData] = useState<JellyfinInfo[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.jellyfin
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.jellyfins);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 30_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Jellyfin</h2>
|
||||
<p className="text-secondary">
|
||||
Whether Jellyfin is up and who is watching. It is read every couple of minutes with an API key (see <Link to="/integrations">Integrations</Link>). A Jellyfin that <strong>wants a restart</strong>, a <strong>scheduled task that failed</strong> or a burst of{" "}
|
||||
<strong>failed sign-ins</strong> is an alert; and an update run on the machine it lives on <strong>asks first when somebody is streaming</strong>.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{!data && !error && <BlockSkeleton lines={4} />}
|
||||
{data && data.length === 0 && (
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<EmptyState title="No Jellyfin connected" hint="Add one under Integrations with its address and an API key (Jellyfin → Dashboard → API Keys)." />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((j) => <Card key={j.id} j={j} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ const INTEGRATION_NAMES: Record<string, string> = {
|
||||
npm: "Nginx Proxy Manager",
|
||||
homeassistant: "Home Assistant",
|
||||
ups: "UPS",
|
||||
jellyfin: "Jellyfin",
|
||||
};
|
||||
|
||||
function ColorList({
|
||||
|
||||
Reference in new issue
Block a user