prometheus/web/ui/react-app/src/pages/status/Status.tsx

113 lines
3.4 KiB
TypeScript
Raw Normal View History

2019-11-12 05:35:47 -08:00
import React, { Fragment, FC } from 'react';
import { Table } from 'reactstrap';
import { withStatusIndicator } from '../../components/withStatusIndicator';
import { useFetch } from '../../hooks/useFetch';
import { usePathPrefix } from '../../contexts/PathPrefixContext';
import { API_PATH } from '../../constants/constants';
2019-11-12 05:35:47 -08:00
interface StatusPageProps {
2020-02-03 06:14:25 -08:00
data: Record<string, string>;
title: string;
2019-11-12 05:35:47 -08:00
}
2019-11-02 08:53:32 -07:00
2020-02-03 06:14:25 -08:00
export const statusConfig: Record<
string,
{ title?: string; customizeValue?: (v: any, key: string) => any; customRow?: boolean; skip?: boolean }
> = {
2019-11-02 08:53:32 -07:00
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' },
corruptionCount: { title: 'WAL corruptions' },
goroutineCount: { title: 'Goroutines' },
storageRetention: { title: 'Storage retention' },
activeAlertmanagers: {
customRow: true,
2019-11-12 05:35:47 -08:00
customizeValue: (alertMgrs: { url: string }[], key) => {
2019-11-02 08:53:32 -07:00
return (
2019-11-12 05:35:47 -08:00
<Fragment key={key}>
2019-11-02 08:53:32 -07:00
<tr>
<th>Endpoint</th>
</tr>
{alertMgrs.map(({ url }) => {
const { origin, pathname } = new URL(url);
return (
<tr key={url}>
<td>
<a href={url}>{origin}</a>
{pathname}
</td>
</tr>
);
})}
</Fragment>
);
},
},
droppedAlertmanagers: { skip: true },
};
2020-02-03 06:14:25 -08:00
export const StatusContent: FC<StatusPageProps> = ({ data, title }) => {
2019-11-12 05:35:47 -08:00
return (
<>
2020-02-03 06:14:25 -08:00
<h2>{title}</h2>
<Table className="h-auto" size="sm" bordered striped>
<tbody>
{Object.entries(data).map(([k, v]) => {
const { title = k, customizeValue = (val: any) => val, customRow, skip } = statusConfig[k] || {};
if (skip) {
return null;
}
if (customRow) {
return customizeValue(v, k);
}
return (
<tr key={k}>
<th className="capitalize-title" style={{ width: '35%' }}>
{title}
</th>
<td className="text-break">{customizeValue(v, title)}</td>
</tr>
);
})}
</tbody>
</Table>
</>
2019-11-12 05:35:47 -08:00
);
};
const StatusWithStatusIndicator = withStatusIndicator(StatusContent);
StatusContent.displayName = 'Status';
const Status: FC = () => {
const pathPrefix = usePathPrefix();
const path = `${pathPrefix}/${API_PATH}`;
2019-11-12 05:35:47 -08:00
return (
2020-02-03 06:14:25 -08:00
<>
{[
{ fetchResult: useFetch<Record<string, string>>(`${path}/status/runtimeinfo`), title: 'Runtime Information' },
{ fetchResult: useFetch<Record<string, string>>(`${path}/status/buildinfo`), title: 'Build Information' },
{ fetchResult: useFetch<Record<string, string>>(`${path}/alertmanagers`), title: 'Alertmanagers' },
].map(({ fetchResult, title }) => {
const { response, isLoading, error } = fetchResult;
return (
<StatusWithStatusIndicator
key={title}
2020-02-03 06:14:25 -08:00
data={response.data}
title={title}
isLoading={isLoading}
error={error}
componentTitle={title}
/>
);
})}
</>
2019-11-12 05:35:47 -08:00
);
2019-11-02 08:53:32 -07:00
};
export default Status;