TSDBStatus.tsx 3.7 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
import { useFetch } from '../../hooks/useFetch';
B
Boyko 已提交
6
import { withStatusIndicator } from '../../components/withStatusIndicator';
7 8
import { usePathPrefix } from '../../contexts/PathPrefixContext';
import { API_PATH } from '../../constants/constants';
9

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

15 16
interface HeadStats {
  numSeries: number;
17
  numLabelPairs: number;
18 19 20 21 22
  chunkCount: number;
  minTime: number;
  maxTime: number;
}

23
export interface TSDBMap {
24
  headStats: HeadStats;
B
Boyko 已提交
25 26 27 28
  seriesCountByMetricName: Stats[];
  labelValueCountByLabelName: Stats[];
  memoryInBytesByLabelName: Stats[];
  seriesCountByLabelValuePair: Stats[];
29 30
}

B
Boyko 已提交
31
export const TSDBStatusContent: FC<TSDBMap> = ({
32
  headStats,
B
Boyko 已提交
33 34 35 36 37
  labelValueCountByLabelName,
  seriesCountByMetricName,
  memoryInBytesByLabelName,
  seriesCountByLabelValuePair,
}) => {
38
  const unixToTime = (unix: number): string => new Date(unix).toISOString();
39
  const { chunkCount, numSeries, numLabelPairs, minTime, maxTime } = headStats;
40 41 42
  const stats = [
    { header: 'Number of Series', value: numSeries },
    { header: 'Number of Chunks', value: chunkCount },
43
    { header: 'Number of Label Pairs', value: numLabelPairs },
44 45 46
    { header: 'Current Min Time', value: `${unixToTime(minTime)} (${minTime})` },
    { header: 'Current Max Time', value: `${unixToTime(maxTime)} (${maxTime})` },
  ];
47
  return (
B
Boyko 已提交
48 49
    <div>
      <h2>TSDB Status</h2>
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
      <h3 className="p-2">Head Stats</h3>
      <div className="p-2">
        <Table bordered size="sm" striped>
          <thead>
            <tr>
              {stats.map(({ header }) => {
                return <th key={header}>{header}</th>;
              })}
            </tr>
          </thead>
          <tbody>
            <tr>
              {stats.map(({ header, value }) => {
                return <td key={header}>{value}</td>;
              })}
            </tr>
          </tbody>
        </Table>
      </div>
B
Boyko 已提交
69 70 71 72 73 74 75 76 77 78 79 80
      <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>
81
                <tr>
B
Boyko 已提交
82 83
                  <th>Name</th>
                  <th>{unit}</th>
84
                </tr>
B
Boyko 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
              </thead>
              <tbody>
                {stats.map(({ name, value }) => {
                  return (
                    <tr key={name}>
                      <td>{name}</td>
                      <td>{value}</td>
                    </tr>
                  );
                })}
              </tbody>
            </Table>
          </div>
        );
      })}
100 101
    </div>
  );
B
Boyko 已提交
102 103 104 105
};
TSDBStatusContent.displayName = 'TSDBStatusContent';

const TSDBStatusContentWithStatusIndicator = withStatusIndicator(TSDBStatusContent);
106

107 108 109
const TSDBStatus: FC<RouteComponentProps> = () => {
  const pathPrefix = usePathPrefix();
  const { response, error, isLoading } = useFetch<TSDBMap>(`${pathPrefix}/${API_PATH}/status/tsdb`);
110 111

  return (
B
Boyko 已提交
112 113 114 115 116 117
    <TSDBStatusContentWithStatusIndicator
      error={error}
      isLoading={isLoading}
      {...response.data}
      componentTitle="TSDB Status information"
    />
118 119 120 121
  );
};

export default TSDBStatus;