import React, { FC, Fragment } from 'react'; import { RouteComponentProps } from '@reach/router'; import { Table, Alert } from 'reactstrap'; import useFetches from '../hooks/useFetches'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSpinner } from '@fortawesome/free-solid-svg-icons'; const ENDPOINTS = ['../api/v1/status/runtimeinfo', '../api/v1/status/buildinfo', '../api/v1/alertmanagers']; const sectionTitles = ['Runtime Information', 'Build Information', 'Alertmanagers']; interface StatusConfig { [k: string]: { title?: string; customizeValue?: (v: any) => any; customRow?: boolean; skip?: boolean }; } type StatusPageState = Array<{ [k: string]: string }>; 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 }[]) => { return ( Endpoint {alertMgrs.map(({ url }) => { const { origin, pathname } = new URL(url); return ( {origin} {pathname} ); })} ); }, }, droppedAlertmanagers: { skip: true }, }; const Status = () => { const { response: data, error, isLoading } = useFetches(ENDPOINTS); if (error) { return ( Error: Error fetching status: {error.message} ); } else if (isLoading) { return ( ); } return data ? data.map((statuses, i) => { return (

{sectionTitles[i]}

{Object.entries(statuses).map(([k, v]) => { const { title = k, customizeValue = (val: any) => val, customRow, skip } = statusConfig[k] || {}; if (skip) { return null; } if (customRow) { return customizeValue(v); } return ( ); })}
{title} {customizeValue(v)}
); }) : null; }; export default Status as FC;