MCPcopy Create free account
hub / github.com/cameri/nostream / getRelayUptimeSeconds

Function getRelayUptimeSeconds

src/cli/commands/info.ts:58–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56}
57
58const getRelayUptimeSeconds = async (): Promise<number | null> => {
59 const idResult = await runCommandWithOutput('docker', ['compose', 'ps', '-q', 'nostream'], { timeoutMs: 1000 })
60 if (!idResult.ok || idResult.code !== 0) {
61 return null
62 }
63
64 const containerId = idResult.stdout.trim()
65 if (!containerId) {
66 return null
67 }
68
69 const startedAtResult = await runCommandWithOutput('docker', ['inspect', '--format', '{{.State.StartedAt}}', containerId], {
70 timeoutMs: 1000,
71 })
72 if (!startedAtResult.ok || startedAtResult.code !== 0) {
73 return null
74 }
75
76 const startedAtRaw = startedAtResult.stdout.trim()
77 const startedAtMs = Date.parse(startedAtRaw)
78 if (!Number.isFinite(startedAtMs)) {
79 return null
80 }
81
82 const seconds = Math.max(0, Math.floor((Date.now() - startedAtMs) / 1000))
83 return seconds
84}
85
86const formatUptime = (uptimeSeconds: number | null): string => {
87 if (uptimeSeconds === null) {

Callers 1

getInfoPayloadFunction · 0.85

Calls 1

runCommandWithOutputFunction · 0.90

Tested by

no test coverage detected