MCPcopy
hub / github.com/deepnote/deepnote / fetchMetrics

Function fetchMetrics

packages/cli/src/utils/metrics.ts:33–58  ·  view source on GitHub ↗
(
  port: number,
  timeoutMs: number = METRICS_FETCH_TIMEOUT_MS
)

Source from the content-addressed store, hash-verified

31
32/** Fetch resource metrics from the Jupyter server */
33export async function fetchMetrics(
34 port: number,
35 timeoutMs: number = METRICS_FETCH_TIMEOUT_MS
36): Promise<JupyterMetricsResponse | null> {
37 const controller = new AbortController()
38 const timeoutId = setTimeout(() => controller.abort(), timeoutMs)
39
40 try {
41 const response = await fetch(`http://localhost:${port}/api/metrics/v1`, {
42 signal: controller.signal,
43 })
44 clearTimeout(timeoutId)
45 if (!response.ok) return null
46 const json = await response.json()
47 const result = JupyterMetricsResponseSchema.safeParse(json)
48 if (!result.success) {
49 debug(`Schema validation failed: ${result.error.message}`)
50 return null
51 }
52 return result.data
53 } catch (error) {
54 clearTimeout(timeoutId)
55 debug(`Failed to fetch metrics: ${error instanceof Error ? error.message : String(error)}`)
56 return null
57 }
58}
59
60/** Format bytes as human-readable string */
61export function formatBytes(bytes: number): string {

Callers 5

metrics.test.tsFile · 0.90
startMetricsMonitoringFunction · 0.90
captureMemoryBeforeBlockFunction · 0.90
recordBlockProfileFunction · 0.90
outputHumanRunSummaryFunction · 0.90

Calls 1

debugFunction · 0.90

Tested by

no test coverage detected