import { Table } from "@mantine/core"; import { useSuspenseAPIQuery } from "../api/api"; import { TSDBStatusResult } from "../api/responseTypes/tsdbStatus"; import { formatTimestamp } from "../lib/formatTime"; import { useSettings } from "../state/settingsSlice"; import InfoPageStack from "../components/InfoPageStack"; import InfoPageCard from "../components/InfoPageCard"; export default function TSDBStatusPage() { const { data: { data: { headStats, labelValueCountByLabelName, seriesCountByMetricName, memoryInBytesByLabelName, seriesCountByLabelValuePair, }, }, } = useSuspenseAPIQuery({ path: `/status/tsdb` }); const { useLocalTime } = useSettings(); const unixToTime = (unix: number): string => { const formatted = formatTimestamp(unix, useLocalTime); if (formatted === "Invalid Date") { if (numSeries === 0) { return "No datapoints yet"; } return `Error parsing time (${unix})`; } return formatted; }; const { chunkCount, numSeries, numLabelPairs, minTime, maxTime } = headStats; const stats = [ { name: "Number of Series", value: numSeries }, { name: "Number of Chunks", value: chunkCount }, { name: "Number of Label Pairs", value: numLabelPairs }, { name: "Current Min Time", value: `${unixToTime(minTime / 1000)}` }, { name: "Current Max Time", value: `${unixToTime(maxTime / 1000)}` }, ]; return ( {[ { title: "TSDB Head Status", stats, formatAsCode: false, }, { title: "Top 10 label names with value count", stats: labelValueCountByLabelName, formatAsCode: true, }, { title: "Top 10 series count by metric names", stats: seriesCountByMetricName, formatAsCode: true, }, { title: "Top 10 label names with high memory usage", unit: "Bytes", stats: memoryInBytesByLabelName, formatAsCode: true, }, { title: "Top 10 series count by label value pairs", stats: seriesCountByLabelValuePair, formatAsCode: true, }, ].map(({ title, unit = "Count", stats, formatAsCode }) => ( Name {unit} {stats.map(({ name, value }) => ( {formatAsCode ? {name} : name} {value} ))}
))}
); }