metrics.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. import { Auth, Realtime, Storage } from 'icons'
  2. import { ActivityIcon, DatabaseIcon, HeartIcon, ServerIcon } from 'lucide-react'
  3. import { ReactNode } from 'react'
  4. export type Metric = {
  5. key: string
  6. label: string
  7. provider?: string
  8. category?: MetricCategory
  9. id?: string
  10. }
  11. type MetricCategory = {
  12. label: string
  13. icon: (className?: string) => ReactNode
  14. key: string
  15. }
  16. export const METRIC_CATEGORIES = {
  17. API: {
  18. label: 'All API usage',
  19. icon: (className?: string) => <ActivityIcon size={16} className={className} />,
  20. key: 'api',
  21. },
  22. API_DATABASE: {
  23. label: 'Database API',
  24. icon: (className?: string) => <DatabaseIcon size={16} className={className} />,
  25. key: 'api_database',
  26. },
  27. API_AUTH: {
  28. label: 'Authentication',
  29. icon: (className?: string) => <Auth size={16} className={className} />,
  30. key: 'api_auth',
  31. },
  32. API_STORAGE: {
  33. label: 'Storage',
  34. icon: (className?: string) => <Storage size={16} className={className} />,
  35. key: 'api_storage',
  36. },
  37. API_REALTIME: {
  38. label: 'Realtime',
  39. icon: (className?: string) => <Realtime size={16} className={className} />,
  40. key: 'api_realtime',
  41. },
  42. INSTANCE: {
  43. label: 'Instance health',
  44. icon: (className?: string) => <HeartIcon size={16} className={className} />,
  45. key: 'instance',
  46. },
  47. SUPAVISOR: {
  48. label: 'Supavisor',
  49. icon: (className?: string) => <ServerIcon size={16} className={className} />,
  50. key: 'supavisor',
  51. },
  52. }
  53. // [Joshen] Eventually we can remove some charts here from DEPRECATED_REPORTS from Reports.constants.ts
  54. export const METRICS: Metric[] = [
  55. {
  56. key: 'avg_cpu_usage',
  57. label: 'Average CPU % Usage',
  58. provider: 'infra-monitoring',
  59. category: METRIC_CATEGORIES.INSTANCE,
  60. },
  61. {
  62. key: 'max_cpu_usage',
  63. label: 'Max CPU % Usage',
  64. provider: 'infra-monitoring',
  65. category: METRIC_CATEGORIES.INSTANCE,
  66. },
  67. {
  68. key: 'disk_io_consumption',
  69. label: 'Disk IO % Consumed',
  70. provider: 'infra-monitoring',
  71. category: METRIC_CATEGORIES.INSTANCE,
  72. },
  73. {
  74. key: 'disk_io_budget',
  75. label: 'Disk IO % Remaining',
  76. provider: 'infra-monitoring',
  77. category: METRIC_CATEGORIES.INSTANCE,
  78. },
  79. {
  80. key: 'ram_usage',
  81. label: 'Memory % Usage',
  82. provider: 'infra-monitoring',
  83. category: METRIC_CATEGORIES.INSTANCE,
  84. },
  85. {
  86. key: 'total_realtime_egress',
  87. label: 'Realtime Connection Egress',
  88. provider: 'daily-stats',
  89. category: METRIC_CATEGORIES.API,
  90. },
  91. {
  92. key: 'total_realtime_requests',
  93. label: 'Realtime Connection Requests',
  94. provider: 'daily-stats',
  95. category: METRIC_CATEGORIES.API_REALTIME,
  96. },
  97. {
  98. key: 'total_realtime_ingress',
  99. label: 'Realtime Connection Ingress',
  100. provider: 'daily-stats',
  101. category: METRIC_CATEGORIES.API_REALTIME,
  102. },
  103. /**
  104. * API
  105. */
  106. {
  107. key: 'total_rest_ingress',
  108. label: 'API Ingress',
  109. provider: 'daily-stats',
  110. category: METRIC_CATEGORIES.API_DATABASE,
  111. },
  112. {
  113. key: 'total_rest_egress',
  114. label: 'API Egress',
  115. provider: 'daily-stats',
  116. category: METRIC_CATEGORIES.API_DATABASE,
  117. },
  118. {
  119. key: 'total_rest_requests',
  120. label: 'API Requests',
  121. provider: 'daily-stats',
  122. category: METRIC_CATEGORIES.API_DATABASE,
  123. },
  124. {
  125. key: 'total_rest_get_requests',
  126. label: 'API GET Requests',
  127. provider: 'daily-stats',
  128. category: METRIC_CATEGORIES.API_DATABASE,
  129. },
  130. {
  131. key: 'total_rest_post_requests',
  132. label: 'API POST Requests',
  133. provider: 'daily-stats',
  134. category: METRIC_CATEGORIES.API_DATABASE,
  135. },
  136. {
  137. key: 'total_rest_patch_requests',
  138. label: 'API PATCH Requests',
  139. provider: 'daily-stats',
  140. category: METRIC_CATEGORIES.API_DATABASE,
  141. },
  142. {
  143. key: 'total_rest_delete_requests',
  144. label: 'API DELETE Requests',
  145. provider: 'daily-stats',
  146. category: METRIC_CATEGORIES.API_DATABASE,
  147. },
  148. {
  149. key: 'total_rest_options_requests',
  150. label: 'API OPTIONS Requests',
  151. provider: 'daily-stats',
  152. category: METRIC_CATEGORIES.API_DATABASE,
  153. },
  154. /**
  155. * Auth
  156. */
  157. {
  158. key: 'total_auth_billing_period_mau',
  159. label: 'Auth Monthly Active User',
  160. provider: 'daily-stats',
  161. category: METRIC_CATEGORIES.API_AUTH,
  162. },
  163. {
  164. key: 'total_auth_billing_period_sso_mau',
  165. label: 'Auth Monthly Active SSO User',
  166. provider: 'daily-stats',
  167. category: METRIC_CATEGORIES.API_AUTH,
  168. },
  169. {
  170. key: 'total_auth_ingress',
  171. label: 'Auth Ingress',
  172. provider: 'daily-stats',
  173. category: METRIC_CATEGORIES.API_AUTH,
  174. },
  175. {
  176. key: 'total_auth_egress',
  177. label: 'Auth Egress',
  178. provider: 'daily-stats',
  179. category: METRIC_CATEGORIES.API_AUTH,
  180. },
  181. {
  182. key: 'total_auth_requests',
  183. label: 'Auth Requests',
  184. provider: 'daily-stats',
  185. category: METRIC_CATEGORIES.API_AUTH,
  186. },
  187. {
  188. key: 'total_auth_get_requests',
  189. label: 'Auth GET Requests',
  190. provider: 'daily-stats',
  191. category: METRIC_CATEGORIES.API_AUTH,
  192. },
  193. {
  194. key: 'total_auth_post_requests',
  195. label: 'Auth POST Requests',
  196. provider: 'daily-stats',
  197. category: METRIC_CATEGORIES.API_AUTH,
  198. },
  199. {
  200. key: 'total_auth_patch_requests',
  201. label: 'Auth PATCH Requests',
  202. provider: 'daily-stats',
  203. category: METRIC_CATEGORIES.API_AUTH,
  204. },
  205. {
  206. key: 'total_auth_options_requests',
  207. label: 'Auth OPTIONS Requests',
  208. provider: 'daily-stats',
  209. category: METRIC_CATEGORIES.API_AUTH,
  210. },
  211. /**
  212. * Storage
  213. */
  214. {
  215. key: 'total_storage_ingress',
  216. label: 'Storage Ingress',
  217. provider: 'daily-stats',
  218. category: METRIC_CATEGORIES.API_STORAGE,
  219. },
  220. {
  221. key: 'total_storage_egress',
  222. label: 'Storage Egress',
  223. provider: 'daily-stats',
  224. category: METRIC_CATEGORIES.API_STORAGE,
  225. },
  226. {
  227. key: 'total_storage_image_render_count',
  228. label: 'Storage Image Transformations',
  229. provider: 'daily-stats',
  230. category: METRIC_CATEGORIES.API_STORAGE,
  231. },
  232. {
  233. key: 'total_storage_requests',
  234. label: 'Storage Requests',
  235. provider: 'daily-stats',
  236. category: METRIC_CATEGORIES.API_STORAGE,
  237. },
  238. {
  239. key: 'total_storage_get_requests',
  240. label: 'Storage GET Requests',
  241. provider: 'daily-stats',
  242. category: METRIC_CATEGORIES.API_STORAGE,
  243. },
  244. {
  245. key: 'total_storage_post_requests',
  246. label: 'Storage POST Requests',
  247. provider: 'daily-stats',
  248. category: METRIC_CATEGORIES.API_STORAGE,
  249. },
  250. {
  251. key: 'total_storage_delete_requests',
  252. label: 'Storage DELETE Requests',
  253. provider: 'daily-stats',
  254. category: METRIC_CATEGORIES.API_STORAGE,
  255. },
  256. {
  257. key: 'total_storage_options_requests',
  258. label: 'Storage OPTIONS Requests',
  259. provider: 'daily-stats',
  260. category: METRIC_CATEGORIES.API_STORAGE,
  261. },
  262. {
  263. key: 'total_auth_delete_requests',
  264. label: 'Auth DELETE Requests',
  265. provider: 'daily-stats',
  266. category: METRIC_CATEGORIES.API_AUTH,
  267. },
  268. {
  269. key: 'total_egress',
  270. label: 'All Egress',
  271. provider: 'daily-stats',
  272. category: METRIC_CATEGORIES.API,
  273. },
  274. {
  275. key: 'total_get_requests',
  276. label: 'All GET Requests',
  277. provider: 'daily-stats',
  278. category: METRIC_CATEGORIES.API,
  279. },
  280. {
  281. key: 'total_cached_egress',
  282. label: 'All Cached Egress',
  283. provider: 'daily-stats',
  284. category: METRIC_CATEGORIES.API_STORAGE,
  285. },
  286. {
  287. key: 'total_storage_patch_requests',
  288. label: 'Storage PATCH Requests',
  289. provider: 'daily-stats',
  290. category: METRIC_CATEGORIES.API_STORAGE,
  291. },
  292. {
  293. key: 'total_requests',
  294. label: 'All Requests',
  295. provider: 'daily-stats',
  296. category: METRIC_CATEGORIES.API,
  297. },
  298. {
  299. key: 'total_patch_requests',
  300. label: 'All PATCH Requests',
  301. provider: 'daily-stats',
  302. category: METRIC_CATEGORIES.API,
  303. },
  304. {
  305. key: 'total_post_requests',
  306. label: 'All POST Requests',
  307. provider: 'daily-stats',
  308. category: METRIC_CATEGORIES.API,
  309. },
  310. {
  311. key: 'total_ingress',
  312. label: 'All Ingress',
  313. provider: 'daily-stats',
  314. category: METRIC_CATEGORIES.API,
  315. },
  316. {
  317. key: 'total_delete_requests',
  318. label: 'All DELETE Requests',
  319. provider: 'daily-stats',
  320. category: METRIC_CATEGORIES.API,
  321. },
  322. {
  323. key: 'total_options_requests',
  324. label: 'All OPTIONS Requests',
  325. provider: 'daily-stats',
  326. category: METRIC_CATEGORIES.API,
  327. },
  328. /** Supavisor */
  329. {
  330. key: 'total_supavisor_egress_bytes',
  331. label: 'Shared Pooler Egress',
  332. provider: 'daily-stats',
  333. category: METRIC_CATEGORIES.SUPAVISOR,
  334. },
  335. ]
  336. export const TIME_PERIODS_BILLING = [
  337. {
  338. key: 'currentBillingCycle',
  339. label: 'Current billing cycle',
  340. interval: '1d',
  341. },
  342. {
  343. key: 'previousBillingCycle',
  344. label: 'Previous billing cycle',
  345. interval: '1d',
  346. },
  347. ]
  348. export const TIME_PERIODS_REPORTS = [
  349. {
  350. key: '7d',
  351. label: 'Last 7 days',
  352. interval: '1d',
  353. },
  354. {
  355. key: '30d',
  356. label: 'Last 30 days',
  357. interval: '1d',
  358. },
  359. {
  360. key: 'startMonth',
  361. label: 'This month',
  362. interval: '1d',
  363. },
  364. ]
  365. export const TIME_PERIODS_INFRA = [
  366. {
  367. key: '10m',
  368. label: 'Last 10 minutes',
  369. },
  370. {
  371. key: '30m',
  372. label: 'Last 30 minutes',
  373. },
  374. {
  375. key: '1h',
  376. label: 'Last hour',
  377. },
  378. {
  379. key: '3h',
  380. label: 'Last 3 hours',
  381. },
  382. {
  383. key: '1d',
  384. label: 'Last 24 hours',
  385. },
  386. {
  387. key: '7d',
  388. label: 'Last 7 days',
  389. },
  390. ]