format code
This commit is contained in:
1 parent
6157bc0879
commit
eba65bd654
23 files changed
+2380
-2192
No files matched your search
@@ -1,8 +1,13 @@
|
||||
import { MonitorState, MonitorTarget } from "@/uptime.types";
|
||||
import { Box, Tooltip } from "@mantine/core";
|
||||
import { MonitorState, MonitorTarget } from '@/uptime.types'
|
||||
import { Box, Tooltip } from '@mantine/core'
|
||||
|
||||
|
||||
export default function DetailBar({ monitor, state }: { monitor: MonitorTarget, state: MonitorState }) {
|
||||
export default function DetailBar({
|
||||
monitor,
|
||||
state,
|
||||
}: {
|
||||
monitor: MonitorTarget
|
||||
state: MonitorState
|
||||
}) {
|
||||
// const day = new Date()
|
||||
// day.setHours(0, 0, 0, 0)
|
||||
// const dayStart = day.getTime()
|
||||
@@ -12,9 +17,8 @@ export default function DetailBar({ monitor, state }: { monitor: MonitorTarget,
|
||||
}
|
||||
|
||||
const uptimePercentBars = []
|
||||
|
||||
for (let i = 89; i > 0; i--) {
|
||||
|
||||
for (let i = 89; i > 0; i--) {
|
||||
let dayDownTime = 0
|
||||
let dayTotalTime = 0
|
||||
|
||||
@@ -22,14 +26,31 @@ export default function DetailBar({ monitor, state }: { monitor: MonitorTarget,
|
||||
|
||||
uptimePercentBars.push(
|
||||
<Tooltip key={i} label="Tooltip">
|
||||
<div style={{ height: '20px', width: '7px', background: 'green', borderRadius: '2px', marginLeft: '1px', marginRight: '1px' }}/>
|
||||
<div
|
||||
style={{
|
||||
height: '20px',
|
||||
width: '7px',
|
||||
background: 'green',
|
||||
borderRadius: '2px',
|
||||
marginLeft: '1px',
|
||||
marginRight: '1px',
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box style={{ display: 'flex', flexWrap: 'nowrap', marginTop: '10px', marginBottom: '5px' }} visibleFrom='540'>
|
||||
<Box
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexWrap: 'nowrap',
|
||||
marginTop: '10px',
|
||||
marginBottom: '5px',
|
||||
}}
|
||||
visibleFrom="540"
|
||||
>
|
||||
{uptimePercentBars}
|
||||
</Box>
|
||||
|
||||
@@ -42,4 +63,4 @@ export default function DetailBar({ monitor, state }: { monitor: MonitorTarget,
|
||||
</Box> */}
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
+39
-22
@@ -1,8 +1,18 @@
|
||||
import { Line } from "react-chartjs-2"
|
||||
import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip as ChartTooltip, Legend, TimeScale } from 'chart.js'
|
||||
import { Line } from 'react-chartjs-2'
|
||||
import {
|
||||
Chart as ChartJS,
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
LineElement,
|
||||
Title,
|
||||
Tooltip as ChartTooltip,
|
||||
Legend,
|
||||
TimeScale,
|
||||
} from 'chart.js'
|
||||
import 'chartjs-adapter-moment'
|
||||
import { MonitorState, MonitorTarget } from "@/uptime.types"
|
||||
import { iataToCountry } from "@/util/iata"
|
||||
import { MonitorState, MonitorTarget } from '@/uptime.types'
|
||||
import { iataToCountry } from '@/util/iata'
|
||||
|
||||
ChartJS.register(
|
||||
CategoryScale,
|
||||
@@ -15,10 +25,18 @@ ChartJS.register(
|
||||
TimeScale
|
||||
)
|
||||
|
||||
|
||||
export default function DetailChart({ monitor, state }: { monitor: MonitorTarget, state: MonitorState }) {
|
||||
|
||||
const latencyData = state.latency[monitor.id].recent.map((point) => ({ x: point.time * 1000, y: point.ping, loc: point.loc }))
|
||||
export default function DetailChart({
|
||||
monitor,
|
||||
state,
|
||||
}: {
|
||||
monitor: MonitorTarget
|
||||
state: MonitorState
|
||||
}) {
|
||||
const latencyData = state.latency[monitor.id].recent.map((point) => ({
|
||||
x: point.time * 1000,
|
||||
y: point.ping,
|
||||
loc: point.loc,
|
||||
}))
|
||||
|
||||
let data = {
|
||||
datasets: [
|
||||
@@ -28,11 +46,11 @@ export default function DetailChart({ monitor, state }: { monitor: MonitorTarget
|
||||
borderWidth: 2,
|
||||
radius: 0,
|
||||
cubicInterpolationMode: 'monotone' as const,
|
||||
tension: 0.4
|
||||
}
|
||||
]
|
||||
tension: 0.4,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
let options = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
@@ -41,7 +59,7 @@ export default function DetailChart({ monitor, state }: { monitor: MonitorTarget
|
||||
intersect: false,
|
||||
},
|
||||
animation: {
|
||||
duration: 0
|
||||
duration: 0,
|
||||
},
|
||||
plugins: {
|
||||
tooltip: {
|
||||
@@ -50,16 +68,16 @@ export default function DetailChart({ monitor, state }: { monitor: MonitorTarget
|
||||
if (item.parsed.y) {
|
||||
return `${item.parsed.y}ms (${iataToCountry(item.raw.loc)})`
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
legend: {
|
||||
display: false
|
||||
display: false,
|
||||
},
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Response times(ms)',
|
||||
align: 'start' as const
|
||||
align: 'start' as const,
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
@@ -68,10 +86,10 @@ export default function DetailChart({ monitor, state }: { monitor: MonitorTarget
|
||||
ticks: {
|
||||
source: 'auto' as const,
|
||||
maxRotation: 0,
|
||||
autoSkip: true
|
||||
}
|
||||
}
|
||||
}
|
||||
autoSkip: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -80,4 +98,3 @@ export default function DetailChart({ monitor, state }: { monitor: MonitorTarget
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
+28
-15
@@ -1,16 +1,18 @@
|
||||
import { Container, Group, Text } from '@mantine/core';
|
||||
import classes from '@/styles/Header.module.css';
|
||||
import config from '@/uptime.config';
|
||||
|
||||
import { Container, Group, Text } from '@mantine/core'
|
||||
import classes from '@/styles/Header.module.css'
|
||||
import config from '@/uptime.config'
|
||||
|
||||
export default function Header() {
|
||||
|
||||
const linkToElement = (link: { label: string; link: string; highlight?: boolean; }) => {
|
||||
const linkToElement = (link: {
|
||||
label: string
|
||||
link: string
|
||||
highlight?: boolean
|
||||
}) => {
|
||||
return (
|
||||
<a
|
||||
key={link.label}
|
||||
href={link.link}
|
||||
target='_blank'
|
||||
target="_blank"
|
||||
className={classes.link}
|
||||
data-active={link.highlight}
|
||||
>
|
||||
@@ -23,21 +25,32 @@ export default function Header() {
|
||||
<header className={classes.header}>
|
||||
<Container size="md" className={classes.inner}>
|
||||
<div>
|
||||
<a href='https://github.com/lyc8503/UptimeFlare' target='_blank'>
|
||||
<Text size='xl' span>🕒</Text>
|
||||
<Text size='xl' span fw={700} variant="gradient" gradient={{ from: 'blue', to: 'cyan', deg: 90 }}>UptimeFlare</Text>
|
||||
<a href="https://github.com/lyc8503/UptimeFlare" target="_blank">
|
||||
<Text size="xl" span>
|
||||
🕒
|
||||
</Text>
|
||||
<Text
|
||||
size="xl"
|
||||
span
|
||||
fw={700}
|
||||
variant="gradient"
|
||||
gradient={{ from: 'blue', to: 'cyan', deg: 90 }}
|
||||
>
|
||||
UptimeFlare
|
||||
</Text>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<Group gap={5} visibleFrom='sm'>
|
||||
<Group gap={5} visibleFrom="sm">
|
||||
{config.page.links.map(linkToElement)}
|
||||
</Group>
|
||||
|
||||
<Group gap={5} hiddenFrom='sm'>
|
||||
{config.page.links.filter(link => link.highlight).map(linkToElement)}
|
||||
<Group gap={5} hiddenFrom="sm">
|
||||
{config.page.links
|
||||
.filter((link) => link.highlight)
|
||||
.map(linkToElement)}
|
||||
</Group>
|
||||
|
||||
</Container>
|
||||
</header>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
import { Text } from "@mantine/core"
|
||||
import { MonitorState, MonitorTarget } from "@/uptime.types"
|
||||
import { IconAlertCircle, IconCircleCheck } from "@tabler/icons-react"
|
||||
import DetailChart from "./DetailChart"
|
||||
import DetailBar from "./DetailBar"
|
||||
import { Text } from '@mantine/core'
|
||||
import { MonitorState, MonitorTarget } from '@/uptime.types'
|
||||
import { IconAlertCircle, IconCircleCheck } from '@tabler/icons-react'
|
||||
import DetailChart from './DetailChart'
|
||||
import DetailBar from './DetailBar'
|
||||
|
||||
function getColor(percent: number | string, darker: boolean): string {
|
||||
percent = Number(percent)
|
||||
@@ -18,36 +17,71 @@ function getColor(percent: number | string, darker: boolean): string {
|
||||
}
|
||||
}
|
||||
|
||||
export default function MonitorDetail({ monitor, state }: { monitor: MonitorTarget, state: MonitorState }) {
|
||||
export default function MonitorDetail({
|
||||
monitor,
|
||||
state,
|
||||
}: {
|
||||
monitor: MonitorTarget
|
||||
state: MonitorState
|
||||
}) {
|
||||
if (!state.latency[monitor.id])
|
||||
return (
|
||||
<>
|
||||
<Text mt="sm" fw={700}>
|
||||
{monitor.name}
|
||||
</Text>
|
||||
<Text mt="sm" fw={700}>
|
||||
No data available, please make sure you have deployed your workers
|
||||
with latest config and check your worker status!
|
||||
</Text>
|
||||
</>
|
||||
)
|
||||
|
||||
if (!state.latency[monitor.id]) return (
|
||||
<>
|
||||
<Text mt='sm' fw={700}>{monitor.name}</Text>
|
||||
<Text mt='sm' fw={700}>No data available, please make sure you have deployed your workers with latest config and check your worker status!</Text>
|
||||
</>
|
||||
)
|
||||
|
||||
const statusIcon = state.incident[monitor.id].slice(-1)[0].end === undefined ? <IconAlertCircle style={{ width: '1.25em', height: '1.25em', color: '#b91c1c' }} /> : <IconCircleCheck style={{ width: '1.25em', height: '1.25em', color: '#059669' }} />
|
||||
const statusIcon =
|
||||
state.incident[monitor.id].slice(-1)[0].end === undefined ? (
|
||||
<IconAlertCircle
|
||||
style={{ width: '1.25em', height: '1.25em', color: '#b91c1c' }}
|
||||
/>
|
||||
) : (
|
||||
<IconCircleCheck
|
||||
style={{ width: '1.25em', height: '1.25em', color: '#059669' }}
|
||||
/>
|
||||
)
|
||||
|
||||
let totalTime = Date.now() / 1000 - state.incident[monitor.id][0].start[0]
|
||||
let downTime = 0
|
||||
for (let incident of state.incident[monitor.id]) {
|
||||
downTime += (incident.end ?? (Date.now() / 1000)) - incident.start[0]
|
||||
downTime += (incident.end ?? Date.now() / 1000) - incident.start[0]
|
||||
}
|
||||
|
||||
console.log(totalTime)
|
||||
console.log(downTime)
|
||||
const uptimePercent = ((totalTime - downTime) / totalTime * 100).toPrecision(4)
|
||||
const uptimePercent = (
|
||||
((totalTime - downTime) / totalTime) *
|
||||
100
|
||||
).toPrecision(4)
|
||||
|
||||
return (
|
||||
<>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
<Text mt='sm' fw={700} style={{ display: 'inline-flex', alignItems: 'center' }}>{statusIcon} {monitor.name}</Text>
|
||||
<Text mt='sm' fw={700} style={{ display: 'inline', color: getColor(uptimePercent, true) }}>Overall: {uptimePercent}%</Text>
|
||||
<Text
|
||||
mt="sm"
|
||||
fw={700}
|
||||
style={{ display: 'inline-flex', alignItems: 'center' }}
|
||||
>
|
||||
{statusIcon} {monitor.name}
|
||||
</Text>
|
||||
<Text
|
||||
mt="sm"
|
||||
fw={700}
|
||||
style={{ display: 'inline', color: getColor(uptimePercent, true) }}
|
||||
>
|
||||
Overall: {uptimePercent}%
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
<DetailBar monitor={monitor} state={state} />
|
||||
<DetailChart monitor={monitor} state={state} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,26 @@
|
||||
import { MonitorState, MonitorTarget } from "@/uptime.types";
|
||||
import { Card, Center, Divider } from "@mantine/core";
|
||||
import MonitorDetail from "./MonitorDetail";
|
||||
|
||||
export default function MonitorList({ config, state }: { config: any, state: MonitorState }) {
|
||||
import { MonitorState, MonitorTarget } from '@/uptime.types'
|
||||
import { Card, Center, Divider } from '@mantine/core'
|
||||
import MonitorDetail from './MonitorDetail'
|
||||
|
||||
export default function MonitorList({
|
||||
config,
|
||||
state,
|
||||
}: {
|
||||
config: any
|
||||
state: MonitorState
|
||||
}) {
|
||||
return (
|
||||
<Center>
|
||||
<Card shadow="sm" padding="lg" radius="md" ml="xl" mr="xl" mt="xl" withBorder style={{ width: '865px' }}>
|
||||
<Card
|
||||
shadow="sm"
|
||||
padding="lg"
|
||||
radius="md"
|
||||
ml="xl"
|
||||
mr="xl"
|
||||
mt="xl"
|
||||
withBorder
|
||||
style={{ width: '865px' }}
|
||||
>
|
||||
{config.monitors.map((monitor: MonitorTarget) => (
|
||||
<div key={monitor.id}>
|
||||
<Card.Section ml="xs" mr="xs">
|
||||
@@ -17,6 +31,5 @@ export default function MonitorList({ config, state }: { config: any, state: Mon
|
||||
))}
|
||||
</Card>
|
||||
</Center>
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+13
-4
@@ -1,10 +1,19 @@
|
||||
import dynamic from 'next/dynamic'
|
||||
import React from 'react'
|
||||
|
||||
const NoSsr = (props: { children: string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal | React.PromiseLikeOfReactNode | null | undefined }) => (
|
||||
<React.Fragment>{props.children}</React.Fragment>
|
||||
)
|
||||
const NoSsr = (props: {
|
||||
children:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| React.ReactElement<any, string | React.JSXElementConstructor<any>>
|
||||
| Iterable<React.ReactNode>
|
||||
| React.ReactPortal
|
||||
| React.PromiseLikeOfReactNode
|
||||
| null
|
||||
| undefined
|
||||
}) => <React.Fragment>{props.children}</React.Fragment>
|
||||
|
||||
export default dynamic(() => Promise.resolve(NoSsr), {
|
||||
ssr: false
|
||||
ssr: false,
|
||||
})
|
||||
@@ -1,27 +1,46 @@
|
||||
import { Center, Title } from '@mantine/core'
|
||||
import { IconCircleCheck, IconAlertCircle } from '@tabler/icons-react'
|
||||
|
||||
export default function OverallStatus({ state }: { state: { overallUp: number, overallDown: number, lastUpdate: number }}) {
|
||||
|
||||
export default function OverallStatus({
|
||||
state,
|
||||
}: {
|
||||
state: { overallUp: number; overallDown: number; lastUpdate: number }
|
||||
}) {
|
||||
let statusString = ''
|
||||
let icon = <IconAlertCircle style={{ width: 64, height: 64, color: '#b91c1c' }} />
|
||||
let icon = (
|
||||
<IconAlertCircle style={{ width: 64, height: 64, color: '#b91c1c' }} />
|
||||
)
|
||||
if (state.overallUp === 0 && state.overallDown === 0) {
|
||||
statusString = 'No data yet'
|
||||
} else if (state.overallUp === 0) {
|
||||
statusString = 'All systems not operational'
|
||||
} else if (state.overallDown === 0) {
|
||||
statusString = 'All systems operational'
|
||||
icon = <IconCircleCheck style={{ width: 64, height: 64, color: '#059669' }} />
|
||||
icon = (
|
||||
<IconCircleCheck style={{ width: 64, height: 64, color: '#059669' }} />
|
||||
)
|
||||
} else {
|
||||
statusString = `Some systems not operational (${state.overallDown} out of ${state.overallUp + state.overallDown})`
|
||||
statusString = `Some systems not operational (${state.overallDown} out of ${
|
||||
state.overallUp + state.overallDown
|
||||
})`
|
||||
}
|
||||
|
||||
return (<>
|
||||
<Center>
|
||||
{icon}
|
||||
</Center>
|
||||
<Title mt="sm" style={{ textAlign: 'center' }} order={1}>{statusString}</Title>
|
||||
<Title mt="sm" style={{ textAlign: 'center', color: '#70778c' }} order={5}>Last updated on: {`${new Date(state.lastUpdate * 1000).toLocaleString()} (${Math.round(Date.now() / 1000) - state.lastUpdate} sec ago)`}</Title>
|
||||
</>)
|
||||
return (
|
||||
<>
|
||||
<Center>{icon}</Center>
|
||||
<Title mt="sm" style={{ textAlign: 'center' }} order={1}>
|
||||
{statusString}
|
||||
</Title>
|
||||
<Title
|
||||
mt="sm"
|
||||
style={{ textAlign: 'center', color: '#70778c' }}
|
||||
order={5}
|
||||
>
|
||||
Last updated on:{' '}
|
||||
{`${new Date(state.lastUpdate * 1000).toLocaleString()} (${
|
||||
Math.round(Date.now() / 1000) - state.lastUpdate
|
||||
} sec ago)`}
|
||||
</Title>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user