import React, { Fragment, FC } from 'react'; import { RouteComponentProps } from '@reach/router'; import { Table } from 'reactstrap'; import { withStatusIndicator } from '../withStatusIndicator'; import { useFetch } from '../utils/useFetch'; import PathPrefixProps from '../PathPrefixProps'; const sectionTitles = ['Runtime Information', 'Build Information', 'Alertmanagers']; interface StatusConfig { [k: string]: { title?: string; customizeValue?: (v: any, key: string) => any; customRow?: boolean; skip?: boolean }; } type StatusPageState = { [k: string]: string }; interface StatusPageProps { data?: StatusPageState[]; } export const statusConfig: StatusConfig = { startTime: { title: 'Start time', customizeValue: (v: string) => new Date(v).toUTCString() }, CWD: { title: 'Working directory' }, reloadConfigSuccess: { title: 'Configuration reload', customizeValue: (v: boolean) => (v ? 'Successful' : 'Unsuccessful'), }, lastConfigTime: { title: 'Last successful configuration reload' }, chunkCount: { title: 'Head chunks' }, timeSeriesCount: { title: 'Head time series' }, corruptionCount: { title: 'WAL corruptions' }, goroutineCount: { title: 'Goroutines' }, storageRetention: { title: 'Storage retention' }, activeAlertmanagers: { customRow: true, customizeValue: (alertMgrs: { url: string }[], key) => { return ( Endpoint {alertMgrs.map(({ url }) => { const { origin, pathname } = new URL(url); return ( {origin} {pathname} ); })} ); }, }, droppedAlertmanagers: { skip: true }, }; export const StatusContent: FC = ({ data = [] }) => { return ( <> {data.map((statuses, i) => { return ( {sectionTitles[i]} {Object.entries(statuses).map(([k, v], i) => { const { title = k, customizeValue = (val: any) => val, customRow, skip } = statusConfig[k] || {}; if (skip) { return null; } if (customRow) { return customizeValue(v, k); } return ( {title} {customizeValue(v, title)} ); })} ); })} > ); }; const StatusWithStatusIndicator = withStatusIndicator(StatusContent); StatusContent.displayName = 'Status'; const Status: FC = ({ pathPrefix = '' }) => { const path = `${pathPrefix}/api/v1`; const status = useFetch(`${path}/status/runtimeinfo`); const runtime = useFetch(`${path}/status/buildinfo`); const build = useFetch(`${path}/alertmanagers`); let data; if (status.response.data && runtime.response.data && build.response.data) { data = [status.response.data, runtime.response.data, build.response.data]; } return ( ); }; export default Status;