Home / Function/ useServiceHealthMetrics() — supabase Function Reference

useServiceHealthMetrics() — supabase Function Reference

Architecture documentation for the useServiceHealthMetrics() function in useServiceHealthMetrics.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  c356cf22_da3f_13fc_2350_53a3eed15996["useServiceHealthMetrics()"]
  a633fd44_7a31_92c2_6573_d41313264107["useObservabilityOverviewData()"]
  a633fd44_7a31_92c2_6573_d41313264107 -->|calls| c356cf22_da3f_13fc_2350_53a3eed15996
  60f37caf_212a_08a5_5fd3_833499e82c44["calculateDateRange()"]
  c356cf22_da3f_13fc_2350_53a3eed15996 -->|calls| 60f37caf_212a_08a5_5fd3_833499e82c44
  b8c0b026_622b_c2e0_9ae2_367bde44bbd7["useServiceHealthQuery()"]
  c356cf22_da3f_13fc_2350_53a3eed15996 -->|calls| b8c0b026_622b_c2e0_9ae2_367bde44bbd7
  c11b4166_ac86_a391_08a9_fad3e789b3f7["calculateAggregatedMetrics()"]
  c356cf22_da3f_13fc_2350_53a3eed15996 -->|calls| c11b4166_ac86_a391_08a9_fad3e789b3f7
  style c356cf22_da3f_13fc_2350_53a3eed15996 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/Observability/useServiceHealthMetrics.ts lines 153–226

export const useServiceHealthMetrics = (
  projectRef: string,
  interval: '1hr' | '1day' | '7day',
  refreshKey: number
) => {
  // Calculate date range based on interval
  // refreshKey is intentionally included to force recalculation when user refreshes
  // eslint-disable-next-line react-hooks/exhaustive-deps
  const { startDate, endDate } = useMemo(() => calculateDateRange(interval), [interval, refreshKey])

  const enabled = Boolean(projectRef)

  // Fetch metrics for each service
  const db = useServiceHealthQuery({ projectRef, serviceKey: 'db', startDate, endDate, enabled })
  const auth = useServiceHealthQuery({
    projectRef,
    serviceKey: 'auth',
    startDate,
    endDate,
    enabled,
  })
  const functions = useServiceHealthQuery({
    projectRef,
    serviceKey: 'functions',
    startDate,
    endDate,
    enabled,
  })
  const storage = useServiceHealthQuery({
    projectRef,
    serviceKey: 'storage',
    startDate,
    endDate,
    enabled,
  })
  const realtime = useServiceHealthQuery({
    projectRef,
    serviceKey: 'realtime',
    startDate,
    endDate,
    enabled,
  })
  const postgrest = useServiceHealthQuery({
    projectRef,
    serviceKey: 'postgrest',
    startDate,
    endDate,
    enabled,
  })

  const services: Record<ServiceKey, ServiceHealthData> = useMemo(
    () => ({
      db,
      auth,
      functions,
      storage,
      realtime,
      postgrest,
    }),
    [db, auth, functions, storage, realtime, postgrest]
  )

  // Calculate aggregated metrics
  const aggregated = useMemo(() => calculateAggregatedMetrics(Object.values(services)), [services])

  const isLoading = Object.values(services).some((s) => s.isLoading)

  return {
    services,
    aggregated,
    isLoading,
    endDate,
  }
}

Subdomains

Frequently Asked Questions

What does useServiceHealthMetrics() do?
useServiceHealthMetrics() is a function in the supabase codebase.
What does useServiceHealthMetrics() call?
useServiceHealthMetrics() calls 3 function(s): calculateAggregatedMetrics, calculateDateRange, useServiceHealthQuery.
What calls useServiceHealthMetrics()?
useServiceHealthMetrics() is called by 1 function(s): useObservabilityOverviewData.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free