MCPcopy Index your code
hub / github.com/0xUnixIO/pulse / handleNodeMetrics

Method handleNodeMetrics

internal/serverapi/api.go:360–378  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, nodeID string)

Source from the content-addressed store, hash-verified

358}
359
360func (a *API) handleNodeMetrics(w http.ResponseWriter, r *http.Request, nodeID string) {
361 if r.Method != http.MethodGet {
362 writeMethodNotAllowed(w, http.MethodGet)
363 return
364 }
365 client, err := a.clientFor(nodeID)
366 if err != nil {
367 writeNodeError(w, err)
368 return
369 }
370 ctx, cancel := context.WithTimeout(r.Context(), 3*time.Second)
371 defer cancel()
372 out, err := client.Usage(ctx, false)
373 if err != nil {
374 writeJSON(w, http.StatusUnprocessableEntity, map[string]any{"error": err.Error()})
375 return
376 }
377 writeJSON(w, http.StatusOK, out)
378}
379
380// handleAllNodeMetricsStream 推送所有节点的实时指标(SSE)。
381// 所有 SSE 连接共享同一个 metricsHub 广播,避免每个连接独立轮询 DB 导致连接池耗尽。

Callers 1

handleNodeRoutesMethod · 0.95

Calls 6

clientForMethod · 0.95
writeMethodNotAllowedFunction · 0.85
writeNodeErrorFunction · 0.85
writeJSONFunction · 0.70
UsageMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected