* feat: move types * feat: add maintenance alert * feat: move to config/base class to have fallback values on missing exports * fix: wrong import for types * Revert "fix: wrong import for types" This reverts commit ca2b2e3a68464cfa1b4aef4d99978de02591df74. * Revert "feat: move to config/base class to have fallback values on missing exports" This reverts commit 9932ea2590193aabd248fbba6b2c3a215da45d18. * fix: imports * chore: formatting * fix: handle filtering for global status * fix: pass props * fix: ignore active maintenances when sending notifications * fix: mark as warning when monitor is in maintenance * fix: title width & warning icon * fix: remove accordeons again * alert config/style changes, worker code improve * update example config * update example config * set monitors to be optional --------- Co-authored-by: lyc8503 <[email protected]>
101 lines
1.9 KiB
TypeScript
101 lines
1.9 KiB
TypeScript
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 '@/types/config'
|
|
import { iataToCountry } from '@/util/iata'
|
|
|
|
ChartJS.register(
|
|
CategoryScale,
|
|
LinearScale,
|
|
PointElement,
|
|
LineElement,
|
|
Title,
|
|
ChartTooltip,
|
|
Legend,
|
|
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,
|
|
}))
|
|
|
|
let data = {
|
|
datasets: [
|
|
{
|
|
data: latencyData,
|
|
borderColor: 'rgb(112, 119, 140)',
|
|
borderWidth: 2,
|
|
radius: 0,
|
|
cubicInterpolationMode: 'monotone' as const,
|
|
tension: 0.4,
|
|
},
|
|
],
|
|
}
|
|
|
|
let options = {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
interaction: {
|
|
mode: 'index' as const,
|
|
intersect: false,
|
|
},
|
|
animation: {
|
|
duration: 0,
|
|
},
|
|
plugins: {
|
|
tooltip: {
|
|
callbacks: {
|
|
label: (item: any) => {
|
|
if (item.parsed.y) {
|
|
return `${item.parsed.y}ms (${iataToCountry(item.raw.loc)})`
|
|
}
|
|
},
|
|
},
|
|
},
|
|
legend: {
|
|
display: false,
|
|
},
|
|
title: {
|
|
display: true,
|
|
text: 'Response times(ms)',
|
|
align: 'start' as const,
|
|
},
|
|
},
|
|
scales: {
|
|
x: {
|
|
type: 'time' as const,
|
|
ticks: {
|
|
source: 'auto' as const,
|
|
maxRotation: 0,
|
|
autoSkip: true,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
return (
|
|
<div style={{ height: '150px' }}>
|
|
<Line options={options} data={data} />
|
|
</div>
|
|
)
|
|
}
|