import React, { FC, Fragment } from 'react'; import { RouteComponentProps } from '@reach/router'; import { Alert, Table } from 'reactstrap'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSpinner } from '@fortawesome/free-solid-svg-icons'; import { useFetch } from '../utils/useFetch'; import PathPrefixProps from '../PathPrefixProps'; export interface Stats { name: string; value: number; } export interface TSDBMap { seriesCountByMetricName: Array; labelValueCountByLabelName: Array; memoryInBytesByLabelName: Array; seriesCountByLabelValuePair: Array; } const paddingStyle = { padding: '10px', }; function createTable(title: string, unit: string, stats: Array) { return (

{title}

{stats.map((element: Stats, i: number) => { return ( ); })}
Name {unit}
{element.name} {element.value}
); } const TSDBStatus: FC = ({ pathPrefix }) => { const { response, error } = useFetch(`${pathPrefix}/api/v1/status/tsdb`); const headStats = () => { const stats: TSDBMap = response && response.data; if (error) { return ( Error: Error fetching TSDB Status: {error.message} ); } else if (stats) { return (

Head Cardinality Stats

{createTable('Top 10 label names with value count', 'Count', stats.labelValueCountByLabelName)} {createTable('Top 10 series count by metric names', 'Count', stats.seriesCountByMetricName)} {createTable('Top 10 label names with high memory usage', 'Bytes', stats.memoryInBytesByLabelName)} {createTable('Top 10 series count by label value pairs', 'Count', stats.seriesCountByLabelValuePair)}
); } return ; }; return (

TSDB Status

{headStats()}
); }; export default TSDBStatus;