mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Observability Dashboard: unified overview for service health and
database infrastructure with interactive charts and metric cards (CPU,
memory, disk I/O, connections, error rate, slow queries).
* Service Health Monitoring: per-service health cards and a
multi-service table with error/warning counts and drill-down links to
reports/logs.
* Interval Selector: new chart-interval dropdown with plan-aware
retention messaging.
* Menu & Reports: updated Observability menu with Overview entry and
Custom Reports management.
* **Documentation**
* Added a footer link to troubleshooting guides.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
37 lines
920 B
TypeScript
37 lines
920 B
TypeScript
import useDbQuery from 'hooks/analytics/useDbQuery'
|
|
import { useMemo } from 'react'
|
|
|
|
export const useSlowQueriesCount = (projectRef?: string, refreshKey: number = 0) => {
|
|
// SQL to count queries with total execution time > 1000ms (1 second)
|
|
// refreshKey is used in useMemo to force recomputation when refresh is triggered
|
|
const sql = useMemo(
|
|
() => `
|
|
-- observability-slow-queries-count
|
|
set search_path to public, extensions;
|
|
|
|
SELECT
|
|
count(*)::int as slow_queries_count
|
|
FROM pg_stat_statements
|
|
WHERE total_exec_time + total_plan_time > 1000;
|
|
`,
|
|
[refreshKey]
|
|
)
|
|
|
|
const { data, isLoading, error } = useDbQuery({
|
|
sql,
|
|
})
|
|
|
|
const slowQueriesCount = useMemo(() => {
|
|
if (!data || !Array.isArray(data) || data.length === 0) {
|
|
return 0
|
|
}
|
|
return data[0]?.slow_queries_count ?? 0
|
|
}, [data])
|
|
|
|
return {
|
|
slowQueriesCount,
|
|
isLoading,
|
|
error,
|
|
}
|
|
}
|