diff --git a/reporter/main.go b/reporter/main.go index 91663d2..71d8bca 100644 --- a/reporter/main.go +++ b/reporter/main.go @@ -27,7 +27,7 @@ var ( Url = flag.String("url", "", "The http url of tianji, for example: https://tianji.msgbyte.com") WorkspaceId = flag.String("workspace", "", "The workspace id for tianji, this should be a uuid") Name = flag.String("name", "", "The identification name for this machine") - Interval = flag.Int("interval", 20.0, "Input the INTERVAL") + Interval = flag.Int("interval", 10.0, "Input the INTERVAL, seconed") IsVnstat = flag.Bool("vnstat", false, "Use vnstat for traffic statistics, linux only") ) diff --git a/src/client/hooks/useIntervalUpdate.ts b/src/client/hooks/useIntervalUpdate.ts new file mode 100644 index 0000000..15b7103 --- /dev/null +++ b/src/client/hooks/useIntervalUpdate.ts @@ -0,0 +1,17 @@ +import { useEffect, useReducer } from 'react'; + +export function useIntervalUpdate(timeout: number) { + // update list in 10 second + const [inc, update] = useReducer((state) => state + 1, 0); + useEffect(() => { + const timer = window.setInterval(() => { + update(); + }, timeout); + + return () => { + window.clearInterval(timer); + }; + }, []); + + return inc; +} diff --git a/src/client/pages/Servers.tsx b/src/client/pages/Servers.tsx index 93e4057..38a90c8 100644 --- a/src/client/pages/Servers.tsx +++ b/src/client/pages/Servers.tsx @@ -1,12 +1,15 @@ -import React, { useEffect, useMemo, useRef, useState } from 'react'; +import React, { useEffect, useMemo, useReducer, useRef, useState } from 'react'; import { Badge, Button, + Empty, Form, Input, Modal, Steps, + Switch, Table, + Tooltip, Typography, } from 'antd'; import { ColumnsType } from 'antd/es/table'; @@ -22,9 +25,12 @@ import { useCurrentWorkspaceId } from '../store/user'; import { useWatch } from '../hooks/useWatch'; import { Loading } from '../components/Loading'; import { without } from 'lodash-es'; +import { useIntervalUpdate } from '../hooks/useIntervalUpdate'; +import clsx from 'clsx'; export const Servers: React.FC = React.memo(() => { const [isModalOpen, setIsModalOpen] = useState(false); + const [hideOfflineServer, setHideOfflineServer] = useState(false); const handleOk = () => { setIsModalOpen(false); @@ -34,7 +40,15 @@ export const Servers: React.FC = React.memo(() => {