Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
6.5 kB ยท 244 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245import { OSTinybird } from "@openstatus/tinybird";
import { env } from "../env";
export const tb = new OSTinybird({ token: env.TINY_BIRD_API_KEY, baseUrl: env.TINYBIRD_URL, noop: env.TINYBIRD_NOOP,});
// REMINDER: we could extend the limits (WorkspacePlan) by// knowing which plan the user is on and disable some periodsconst periods = ["1d", "7d", "14d"] as const;const types = ["http", "tcp", "icmp"] as const;
// FIXME: check we we can also use Period from elswheretype Period = (typeof periods)[number];// FIMXE: use JobType instead!type Type = (typeof types)[number];
// REMINDER: extend if neededexport function prepareListByPeriod(period: Period, type: Type = "http") { switch (period) { case "1d": { const getData = { http: tb.legacy_httpListDaily, tcp: tb.legacy_tcpListDaily, icmp: tb.icmpListDaily, } as const; return { getData: getData[type] }; } case "7d": { const getData = { http: tb.legacy_httpListWeekly, tcp: tb.legacy_tcpListWeekly, icmp: tb.icmpListWeekly, } as const; return { getData: getData[type] }; } case "14d": { const getData = { http: tb.legacy_httpListBiweekly, tcp: tb.legacy_tcpListBiweekly, icmp: tb.icmpListBiweekly, } as const; return { getData: getData[type] }; } default: { const getData = { http: tb.legacy_httpListDaily, tcp: tb.legacy_tcpListDaily, icmp: tb.icmpListDaily, } as const; return { getData: getData[type] }; } }}
export function prepareMetricsByPeriod(period: Period, type: Type = "http") { switch (period) { case "1d": { const getData = { http: tb.legacy_httpMetricsDaily, tcp: tb.legacy_tcpMetricsDaily, icmp: tb.icmpMetricsDaily, } as const; return { getData: getData[type] }; } case "7d": { const getData = { http: tb.legacy_httpMetricsWeekly, tcp: tb.legacy_tcpMetricsWeekly, icmp: tb.icmpMetricsWeekly, } as const; return { getData: getData[type] }; } case "14d": { const getData = { http: tb.legacy_httpMetricsBiweekly, tcp: tb.legacy_tcpMetricsBiweekly, icmp: tb.icmpMetricsBiweekly, } as const; return { getData: getData[type] }; } default: { const getData = { http: tb.legacy_httpMetricsDaily, tcp: tb.legacy_tcpMetricsDaily, icmp: tb.icmpMetricsDaily, } as const; return { getData: getData[type] }; } }}
export function prepareMetricByRegionByPeriod( period: Period, type: Type = "http",) { switch (period) { case "1d": { const getData = { http: tb.httpMetricsByRegionDaily, tcp: tb.tcpMetricsByRegionDaily, icmp: tb.icmpMetricsByRegionDaily, } as const; return { getData: getData[type] }; } case "7d": { const getData = { http: tb.httpMetricsByRegionWeekly, tcp: tb.tcpMetricsByRegionWeekly, icmp: tb.icmpMetricsByRegionWeekly, } as const; return { getData: getData[type] }; } case "14d": { const getData = { http: tb.httpMetricsByRegionBiweekly, tcp: tb.tcpMetricsByRegionBiweekly, icmp: tb.icmpMetricsByRegionBiweekly, } as const; return { getData: getData[type] }; } default: { const getData = { http: tb.httpMetricsByRegionDaily, tcp: tb.tcpMetricsByRegionDaily, icmp: tb.icmpMetricsByRegionDaily, } as const; return { getData: getData[type] }; } }}
export function prepareMetricByIntervalByPeriod( period: Period, type: Type = "http",) { switch (period) { case "1d": { const getData = { http: tb.httpMetricsByIntervalDaily, tcp: tb.tcpMetricsByIntervalDaily, icmp: tb.icmpMetricsByIntervalDaily, } as const; return { getData: getData[type] }; } case "7d": { const getData = { http: tb.httpMetricsByIntervalWeekly, tcp: tb.tcpMetricsByIntervalWeekly, icmp: tb.icmpMetricsByIntervalWeekly, } as const; return { getData: getData[type] }; } case "14d": { const getData = { http: tb.httpMetricsByIntervalBiweekly, tcp: tb.tcpMetricsByIntervalBiweekly, icmp: tb.icmpMetricsByIntervalBiweekly, } as const; return { getData: getData[type] }; } default: { const getData = { http: tb.httpMetricsByIntervalDaily, tcp: tb.tcpMetricsByIntervalDaily, icmp: tb.icmpMetricsByIntervalDaily, } as const; return { getData: getData[type] }; } }}
export function prepareStatusByPeriod( period: "7d" | "45d", type: Type = "http",) { switch (period) { case "7d": { const getData = { http: tb.httpStatusWeekly, tcp: tb.tcpStatusWeekly, icmp: tb.icmpStatusWeekly, } as const; return { getData: getData[type] }; } case "45d": { const getData = { http: tb.legacy_httpStatus45d, tcp: tb.legacy_tcpStatus45d, icmp: tb.icmpStatus45d, } as const; return { getData: getData[type] }; } default: { const getData = { http: tb.httpStatusWeekly, tcp: tb.tcpStatusWeekly, icmp: tb.icmpStatusWeekly, } as const; return { getData: getData[type] }; } }}
export function prepareGetByPeriod(period: "30d", type: Type = "http") { switch (period) { case "30d": { const getData = { http: tb.httpGetMonthly, tcp: tb.tcpGetMonthly, icmp: tb.icmpGetMonthly, } as const; return { getData: getData[type] }; } default: { const getData = { http: tb.httpGetMonthly, tcp: tb.tcpGetMonthly, icmp: tb.icmpGetMonthly, } as const; return { getData: getData[type] }; } }}
// FOR MIGRATIONexport type ResponseTimeMetrics = Awaited< ReturnType<OSTinybird["legacy_httpMetricsDaily"]>>["data"][number];
export type ResponseTimeMetricsByRegion = Awaited< ReturnType<OSTinybird["httpMetricsByRegionDaily"]>>["data"][number];
export type ResponseGraph = Awaited< ReturnType<OSTinybird["httpMetricsByIntervalDaily"]>>["data"][number];
export type ResponseStatusTracker = Awaited< ReturnType<OSTinybird["httpStatusWeekly"]>>["data"][number];