SystemHealthyView.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { useEffect, useState } from 'react';
  2. import { useNavigationHook } from '../../hooks/Navigation';
  3. import { useInterval } from '../../hooks/SystemView';
  4. import { PrometheusHttp } from '../../http/Prometheus';
  5. import { ALL_ROUTER_TYPES } from '../../router/Types';
  6. interface ITimeRangeOption {
  7. label: string;
  8. value: number;
  9. step: string;
  10. }
  11. const SystemHealthyView = () => {
  12. useNavigationHook(ALL_ROUTER_TYPES.SYSTEM);
  13. const INTERVAL = 60000;
  14. const timeRangeOptions: ITimeRangeOption[] = [
  15. {
  16. label: '1h',
  17. value: 60 * 60 * 1000,
  18. step: '3m',
  19. },
  20. {
  21. label: '24h',
  22. value: 24 * 60 * 60 * 1000,
  23. step: '60m',
  24. },
  25. {
  26. label: '7d',
  27. value: 7 * 24 * 60 * 60 * 1000,
  28. step: '8h',
  29. },
  30. ];
  31. const [timeRange, setTimeRange] = useState<ITimeRangeOption>(
  32. timeRangeOptions[0]
  33. );
  34. const [nodes, setNodes] = useState<any>();
  35. const updateData = async () => {
  36. const curT = new Date().getTime();
  37. const result: any = await PrometheusHttp.getHealthyData({
  38. start: curT - timeRange.value,
  39. end: curT,
  40. step: timeRange.step,
  41. });
  42. console.log(result);
  43. setNodes(result.data);
  44. };
  45. useEffect(() => {
  46. updateData();
  47. }, []);
  48. useInterval(() => {
  49. console.log('interval');
  50. updateData();
  51. }, INTERVAL);
  52. return <div></div>;
  53. };
  54. export default SystemHealthyView;