The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add charts for CPU and memory usage
Joshen Limb792c5afcb72
diff --git a/studio/components/interfaces/BillingV2/Usage/Activity.tsx b/studio/components/interfaces/BillingV2/Usage/Activity.tsxnew file mode 100644index 00000000000..fddd1725ad4--- /dev/null+++ b/studio/components/interfaces/BillingV2/Usage/Activity.tsx@@ -0,0 +1,79 @@+import { useParams } from 'common'+import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'+import dayjs from 'dayjs'+import { DATE_FORMAT } from 'lib/constants'+import BarChart from './BarChart'+import { generateUsageData } from './Usage.utils'++const Activity = () => {+ const { ref } = useParams()++ const currentDate = 1682669326710 / 1000+ const startDate = dayjs.unix(currentDate).subtract(24, 'hour').format(DATE_FORMAT)+ const endDate = dayjs.unix(currentDate).format(DATE_FORMAT)++ const { data: ioBudgetData, isLoading: isLoadingIoBudgetData } = useInfraMonitoringQuery({+ projectRef: ref,+ attribute: 'disk_io_budget',+ startDate,+ endDate,+ interval: '1h',+ })++ return (+ <>+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="sticky top-16">+ <p className="text-base">Activity</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ </div>+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="grid grid-cols-12">+ <div className="col-span-5">+ <div className="sticky top-16">+ <p className="text-base">IO Budget</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ <div className="col-span-7 space-y-6">+ <div className="space-y-1">+ <p>IO budget per day</p>+ <p className="text-sm text-scale-1000">+ Just FYI for now its a percentage for IO budget, which is different from what the+ figma designs are (in minutes). We will need o11y or infra to help update this+ </p>+ </div>+ {isLoadingIoBudgetData ? (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ ) : (+ <BarChart+ attribute="disk_io_budget"+ data={generateUsageData('disk_io_budget', 30)}+ reference={{+ value: 65,+ label: 'FREE QUOTA',+ x: 60,+ y: 49,+ width: 200,+ height: 24,+ }}+ />+ )}+ </div>+ </div>+ </div>+ </div>+ </>+ )+}++export default Activitydiff --git a/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsxnew file mode 100644index 00000000000..835dcd19e03--- /dev/null+++ b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx@@ -0,0 +1,79 @@+import { useParams } from 'common'+import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'+import dayjs from 'dayjs'+import { DATE_FORMAT } from 'lib/constants'+import BarChart from './BarChart'+import { generateUsageData } from './Usage.utils'++const Bandwidth = () => {+ const { ref } = useParams()++ const currentDate = 1682669326710 / 1000+ const startDate = dayjs.unix(currentDate).subtract(24, 'hour').format(DATE_FORMAT)+ const endDate = dayjs.unix(currentDate).format(DATE_FORMAT)++ const { data: ioBudgetData, isLoading: isLoadingIoBudgetData } = useInfraMonitoringQuery({+ projectRef: ref,+ attribute: 'disk_io_budget',+ startDate,+ endDate,+ interval: '1h',+ })++ return (+ <>+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="sticky top-16">+ <p className="text-base">Bandwidth</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ </div>+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="grid grid-cols-12">+ <div className="col-span-5">+ <div className="sticky top-16">+ <p className="text-base">IO Budget</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ <div className="col-span-7 space-y-6">+ <div className="space-y-1">+ <p>IO budget per day</p>+ <p className="text-sm text-scale-1000">+ Just FYI for now its a percentage for IO budget, which is different from what the+ figma designs are (in minutes). We will need o11y or infra to help update this+ </p>+ </div>+ {isLoadingIoBudgetData ? (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ ) : (+ <BarChart+ attribute="disk_io_budget"+ data={generateUsageData('disk_io_budget', 30)}+ reference={{+ value: 65,+ label: 'FREE QUOTA',+ x: 60,+ y: 49,+ width: 200,+ height: 24,+ }}+ />+ )}+ </div>+ </div>+ </div>+ </div>+ </>+ )+}++export default Bandwidthdiff --git a/studio/components/interfaces/BillingV2/Usage/BarChart.tsx b/studio/components/interfaces/BillingV2/Usage/BarChart.tsxindex ee0f627ff85..c332818ce47 100644--- a/studio/components/interfaces/BillingV2/Usage/BarChart.tsx+++ b/studio/components/interfaces/BillingV2/Usage/BarChart.tsx@@ -7,6 +7,7 @@ import {XAxis,Bar,ReferenceLine,+ Cell,} from 'recharts'// [Joshen] I don't think I should be replacing ChartHandler just yet as the styling of the usage charts@@ -25,17 +26,37 @@ export interface BarChartProps {data: DataPoint[]attribute: stringreference?: Reference+ unit?: string+ yDomain?: number[]}-const BarChart = ({ data, attribute, reference }: BarChartProps) => {+const BarChart = ({ data, attribute, reference, unit, yDomain }: BarChartProps) => {return (<div className="w-full h-[200px]"><ResponsiveContainer width="100%" height={200}>- <ComposedChart data={data} margin={{ top: 0, right: 0, left: 0, bottom: 0 }}>- <CartesianGrid vertical={false} strokeDasharray="3 3" />- <XAxis dataKey="" />- <YAxis width={28} axisLine={false} tickLine={{ stroke: 'none' }} />- <Bar dataKey={attribute} fill="#EEE" />+ <ComposedChart data={data} margin={{ top: 0, right: 0, left: 10, bottom: 0 }}>+ <CartesianGrid vertical={false} strokeDasharray="3 3" className="stroke-scale-800" />+ <XAxis dataKey="period_start" />+ <YAxis+ width={28}+ axisLine={false}+ tickLine={{ stroke: 'none' }}+ domain={yDomain}+ unit={unit}+ />+ <Bar dataKey={attribute}>+ {data.map((entry) => {+ return (+ <Cell+ className={+ reference !== undefined && Number(entry[attribute]) >= reference.value+ ? 'fill-amber-900'+ : 'fill-scale-1200'+ }+ />+ )+ })}+ </Bar>{reference && (<ReferenceLiney={reference.value}@@ -46,7 +67,7 @@ const BarChart = ({ data, attribute, reference }: BarChartProps) => {width={reference.width}height={reference.height}>- <div className="text-[0.7rem] font-bold text-amber-900 bg-amber-300 w-fit p-1.5 py-0.5 rounded-md">+ <div className="text-[0.7rem] font-bold text-scale-1200 bg-scale-100 w-fit p-1.5 py-0.5 rounded-md">{reference.label}</div></foreignObject>diff --git a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsxindex 7ecea76d216..f5f0f6b5a0c 100644--- a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx+++ b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx@@ -1,46 +1,96 @@import { useParams } from 'common'import ShimmeringLoader from 'components/ui/ShimmeringLoader'import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'+import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'import dayjs from 'dayjs'import { DATE_FORMAT } from 'lib/constants'import BarChart from './BarChart'-import { generateUsageData } from './Usage.utils'const Infrastructure = () => {const { ref } = useParams()+ const { data: subscription } = useProjectSubscriptionQuery({ projectRef: ref })+ const { current_period_start, current_period_end } = subscription?.billing ?? {}+ const startDate = new Date((current_period_start ?? 0) * 1000).toISOString()+ const endDate = new Date((current_period_end ?? 0) * 1000).toISOString()- const currentDate = 1682669326710 / 1000- const startDate = dayjs.unix(currentDate).subtract(24, 'hour').format(DATE_FORMAT)- const endDate = dayjs.unix(currentDate).format(DATE_FORMAT)+ const { data: cpuUsageData, isLoading: isLoadingCpuUsageData } = useInfraMonitoringQuery({+ projectRef: ref,+ attribute: 'cpu_usage',+ startDate,+ endDate,+ interval: '1d',+ modifier: (x: number) => x * 100,+ })- const { data: ioBudgetData, isLoading: isLoadingIoBudgetData } = useInfraMonitoringQuery({+ const { data: memoryUsageData, isLoading: isLoadingMemoryUsageData } = useInfraMonitoringQuery({projectRef: ref,- attribute: 'disk_io_budget',+ attribute: 'ram_usage',startDate,endDate,- interval: '1h',+ interval: '1d',})return (<>+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="sticky top-16">+ <p className="text-base">Infrastructure</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ </div>++ {/* CPU USAGE */}<div className="border-b"><div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16"><div className="grid grid-cols-12"><div className="col-span-5"><div className="sticky top-16">- <p className="text-base">IO Budget</p>+ <p className="text-base">CPU</p><p className="text-sm text-scale-1000">Some description here</p></div></div><div className="col-span-7 space-y-6"><div className="space-y-1">- <p>IO budget per day</p>- <p className="text-sm text-scale-1000">- Just FYI for now its a percentage for IO budget, which is different from what the- figma designs are (in minutes). We will need o11y or infra to help update this- </p>+ <p>Max CPU usage each day</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ {isLoadingCpuUsageData ? (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ ) : (+ <BarChart+ attribute="cpu_usage"+ data={cpuUsageData?.data ?? []}+ unit={cpuUsageData?.format}+ yDomain={[0, 100]}+ />+ )}+ </div>+ </div>+ </div>+ </div>++ {/* MEMORY USAGE */}+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="grid grid-cols-12">+ <div className="col-span-5">+ <div className="sticky top-16">+ <p className="text-base">Memory</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ <div className="col-span-7 space-y-6">+ <div className="space-y-1">+ <p>Max memory usage each day</p>+ <p className="text-sm text-scale-1000">Some description here</p></div>- {isLoadingIoBudgetData ? (+ {isLoadingMemoryUsageData ? (<div className="space-y-2"><ShimmeringLoader /><ShimmeringLoader className="w-3/4" />@@ -48,16 +98,10 @@ const Infrastructure = () => {</div>) : (<BarChart- attribute="disk_io_budget"- data={generateUsageData('disk_io_budget', 30)}- reference={{- value: 65,- label: 'FREE QUOTA',- x: 60,- y: 49,- width: 200,- height: 24,- }}+ attribute="ram_usage"+ data={memoryUsageData?.data ?? []}+ unit={memoryUsageData?.format}+ yDomain={[0, 100]}/>)}</div>diff --git a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsxnew file mode 100644index 00000000000..00834ccb337--- /dev/null+++ b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx@@ -0,0 +1,79 @@+import { useParams } from 'common'+import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'+import dayjs from 'dayjs'+import { DATE_FORMAT } from 'lib/constants'+import BarChart from './BarChart'+import { generateUsageData } from './Usage.utils'++const SizeAndCounts = () => {+ const { ref } = useParams()++ const currentDate = 1682669326710 / 1000+ const startDate = dayjs.unix(currentDate).subtract(24, 'hour').format(DATE_FORMAT)+ const endDate = dayjs.unix(currentDate).format(DATE_FORMAT)++ const { data: ioBudgetData, isLoading: isLoadingIoBudgetData } = useInfraMonitoringQuery({+ projectRef: ref,+ attribute: 'disk_io_budget',+ startDate,+ endDate,+ interval: '1h',+ })++ return (+ <>+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="sticky top-16">+ <p className="text-base">Size & Counts</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ </div>+ <div className="border-b">+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">+ <div className="grid grid-cols-12">+ <div className="col-span-5">+ <div className="sticky top-16">+ <p className="text-base">IO Budget</p>+ <p className="text-sm text-scale-1000">Some description here</p>+ </div>+ </div>+ <div className="col-span-7 space-y-6">+ <div className="space-y-1">+ <p>IO budget per day</p>+ <p className="text-sm text-scale-1000">+ Just FYI for now its a percentage for IO budget, which is different from what the+ figma designs are (in minutes). We will need o11y or infra to help update this+ </p>+ </div>+ {isLoadingIoBudgetData ? (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ <ShimmeringLoader className="w-1/2" />+ </div>+ ) : (+ <BarChart+ attribute="disk_io_budget"+ data={generateUsageData('disk_io_budget', 30)}+ reference={{+ value: 65,+ label: 'FREE QUOTA',+ x: 60,+ y: 49,+ width: 200,+ height: 24,+ }}+ />+ )}+ </div>+ </div>+ </div>+ </div>+ </>+ )+}++export default SizeAndCountsdiff --git a/studio/components/interfaces/BillingV2/Usage/Usage.tsx b/studio/components/interfaces/BillingV2/Usage/Usage.tsxindex 45fd184500a..956b48669ff 100644--- a/studio/components/interfaces/BillingV2/Usage/Usage.tsx+++ b/studio/components/interfaces/BillingV2/Usage/Usage.tsx@@ -5,6 +5,9 @@ import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscripimport { useEffect, useState } from 'react'import { Button, IconCheckCircle, Listbox } from 'ui'import Infrastructure from './Infrastructure'+import Bandwidth from './Bandwidth'+import SizeAndCounts from './SizeAndCounts'+import Activity from './Activity'const Usage = () => {const { ref } = useParams()@@ -72,22 +75,9 @@ const Usage = () => {</div><Infrastructure />-- <div className="border-b">- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">- Segment 2- </div>- </div>- <div className="border-b">- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">- Segment 3- </div>- </div>- <div className="border-b">- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">- Segment 4- </div>- </div>+ {/* <Bandwidth />+ <SizeAndCounts />+ <Activity /> */}</>)}diff --git a/studio/components/interfaces/BillingV2/Usage/Usage.utils.ts b/studio/components/interfaces/BillingV2/Usage/Usage.utils.tsindex 9406c4fbcce..b795682583b 100644--- a/studio/components/interfaces/BillingV2/Usage/Usage.utils.ts+++ b/studio/components/interfaces/BillingV2/Usage/Usage.utils.ts@@ -6,7 +6,7 @@ export const generateUsageData = (attribute: string, days: number): DataPoint[]return tempArray.map((x, idx) => {return {loopId: (idx + 1).toString(),- period_start: '',+ period_start: `${idx + 1}`,[attribute]: Math.floor(Math.random() * 100).toString(),}})diff --git a/studio/data/analytics/daily-stats-query.ts b/studio/data/analytics/daily-stats-query.tsindex 70bac3c155b..2655fecdec8 100644--- a/studio/data/analytics/daily-stats-query.ts+++ b/studio/data/analytics/daily-stats-query.ts@@ -49,10 +49,18 @@ export type DailyStatsVariables = {startDate?: stringendDate?: stringinterval?: string+ dateFormat?: string}export async function getDailyStats(- { projectRef, attribute, startDate, endDate, interval = '1d' }: DailyStatsVariables,+ {+ projectRef,+ attribute,+ startDate,+ endDate,+ interval = '1d',+ dateFormat = 'DD MMM',+ }: DailyStatsVariables,signal?: AbortSignal) {if (!projectRef) throw new Error('Project ref is required')diff --git a/studio/data/analytics/infra-monitoring-query.ts b/studio/data/analytics/infra-monitoring-query.tsindex c9bdf9a42fb..cf0323ebfba 100644--- a/studio/data/analytics/infra-monitoring-query.ts+++ b/studio/data/analytics/infra-monitoring-query.ts@@ -4,13 +4,16 @@ import { API_URL } from 'lib/constants'import { useCallback } from 'react'import { analyticsKeys } from './keys'import { AnalyticsData } from './constants'+import dayjs from 'dayjs'export type InfraMonitoringVariables = {projectRef?: string- attribute?: 'cpu_usage' | 'disk_io_budget' | 'ram_usage'+ attribute: 'cpu_usage' | 'disk_io_budget' | 'ram_usage'startDate?: stringendDate?: stringinterval?: string+ dateFormat?: string+ modifier?: (x: number) => number}export async function getInfraMonitoring(@@ -20,7 +23,7 @@ export async function getInfraMonitoring(if (!projectRef) throw new Error('Project ref is required')if (!attribute) throw new Error('Attribute is required')if (!startDate) throw new Error('Start date is required')- if (!endDate) throw new Error('Start date is required')+ if (!endDate) throw new Error('End date is required')const data = await get(`${API_URL}/projects/${projectRef}/infra-monitoring?attribute=${attribute}&startDate=${encodeURIComponent(@@ -36,7 +39,15 @@ export type InfraMonitoringData = Awaited<ReturnType<typeof getInfraMonitoring>>export type InfraMonitoringError = unknownexport const useInfraMonitoringQuery = <TData = InfraMonitoringData>(- { projectRef, attribute, startDate, endDate, interval = '1d' }: InfraMonitoringVariables,+ {+ projectRef,+ attribute,+ startDate,+ endDate,+ interval = '1d',+ dateFormat = 'DD MMM',+ modifier,+ }: InfraMonitoringVariables,{enabled = true,...options@@ -47,7 +58,26 @@ export const useInfraMonitoringQuery = <TData = InfraMonitoringData>(({ signal }) =>getInfraMonitoring({ projectRef, attribute, startDate, endDate, interval }, signal),{- enabled: enabled && typeof projectRef !== 'undefined',+ enabled:+ enabled &&+ typeof projectRef !== 'undefined' &&+ typeof attribute !== 'undefined' &&+ typeof startDate !== 'undefined' &&+ typeof endDate !== 'undefined',+ // @ts-ignore+ select(data) {+ return {+ ...data,+ data: data.data.map((x) => {+ return {+ ...x,+ [attribute]:+ modifier !== undefined ? modifier(Number(x[attribute])) : Number(x[attribute]),+ period_start: dayjs(x.period_start).format(dateFormat),+ }+ }),+ }+ },...options,})diff --git a/studio/styles/ui.scss b/studio/styles/ui.scssindex 54b9fc584d4..e080e04ecde 100644--- a/studio/styles/ui.scss+++ b/studio/styles/ui.scss@@ -446,9 +446,6 @@}.recharts-reference-line {line {- @apply stroke-amber-900;- }- text {- @apply text-xs fill-amber-900 bg-amber-600;+ @apply stroke-scale-1000;}}\ No newline at end of file