TSDBStatus.tsx 2.4 KB
Newer Older
B
Boyko 已提交
1
import React, { FC } from 'react';
2
import { RouteComponentProps } from '@reach/router';
B
Boyko 已提交
3 4
import { Table } from 'reactstrap';

B
Boyko 已提交
5 6
import { useFetch } from '../../hooks/useFetch';
import PathPrefixProps from '../../types/PathPrefixProps';
B
Boyko 已提交
7
import { withStatusIndicator } from '../../components/withStatusIndicator';
8

B
Boyko 已提交
9
interface Stats {
10 11 12 13 14
  name: string;
  value: number;
}

export interface TSDBMap {
B
Boyko 已提交
15 16 17 18
  seriesCountByMetricName: Stats[];
  labelValueCountByLabelName: Stats[];
  memoryInBytesByLabelName: Stats[];
  seriesCountByLabelValuePair: Stats[];
19 20
}

B
Boyko 已提交
21 22 23 24 25 26
export const TSDBStatusContent: FC<TSDBMap> = ({
  labelValueCountByLabelName,
  seriesCountByMetricName,
  memoryInBytesByLabelName,
  seriesCountByLabelValuePair,
}) => {
27
  return (
B
Boyko 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41
    <div>
      <h2>TSDB Status</h2>
      <h3 className="p-2">Head Cardinality Stats</h3>
      {[
        { title: 'Top 10 label names with value count', stats: labelValueCountByLabelName },
        { title: 'Top 10 series count by metric names', stats: seriesCountByMetricName },
        { title: 'Top 10 label names with high memory usage', unit: 'Bytes', stats: memoryInBytesByLabelName },
        { title: 'Top 10 series count by label value pairs', stats: seriesCountByLabelValuePair },
      ].map(({ title, unit = 'Count', stats }) => {
        return (
          <div className="p-2" key={title}>
            <h3>{title}</h3>
            <Table bordered size="sm" striped>
              <thead>
42
                <tr>
B
Boyko 已提交
43 44
                  <th>Name</th>
                  <th>{unit}</th>
45
                </tr>
B
Boyko 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
              </thead>
              <tbody>
                {stats.map(({ name, value }) => {
                  return (
                    <tr key={name}>
                      <td>{name}</td>
                      <td>{value}</td>
                    </tr>
                  );
                })}
              </tbody>
            </Table>
          </div>
        );
      })}
61 62
    </div>
  );
B
Boyko 已提交
63 64 65 66
};
TSDBStatusContent.displayName = 'TSDBStatusContent';

const TSDBStatusContentWithStatusIndicator = withStatusIndicator(TSDBStatusContent);
67 68

const TSDBStatus: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix }) => {
B
Boyko 已提交
69
  const { response, error, isLoading } = useFetch<TSDBMap>(`${pathPrefix}/api/v1/status/tsdb`);
70 71

  return (
B
Boyko 已提交
72 73 74 75 76 77
    <TSDBStatusContentWithStatusIndicator
      error={error}
      isLoading={isLoading}
      {...response.data}
      componentTitle="TSDB Status information"
    />
78 79 80 81
  );
};

export default TSDBStatus;