-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: resources network widget (#4327)
- Loading branch information
Showing
6 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import useSWR from "swr"; | ||
import { FaNetworkWired } from "react-icons/fa"; | ||
import { useTranslation } from "next-i18next"; | ||
|
||
import Resource from "../widget/resource"; | ||
import Error from "../widget/error"; | ||
|
||
export default function Network({ options, refresh = 1500 }) { | ||
const { t } = useTranslation(); | ||
// eslint-disable-next-line no-param-reassign | ||
if (options.network === true) options.network = "default"; | ||
|
||
const { data, error } = useSWR(`/api/widgets/resources?type=network&interfaceName=${options.network}`, { | ||
refreshInterval: refresh, | ||
}); | ||
|
||
if (error || data?.error) { | ||
return <Error />; | ||
} | ||
|
||
if (!data || !data.network) { | ||
return ( | ||
<Resource | ||
icon={FaNetworkWired} | ||
value="- ↑" | ||
label="- ↓" | ||
expandedValue="- ↑" | ||
expandedLabel="- ↓" | ||
percentage="0" | ||
wide | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Resource | ||
icon={FaNetworkWired} | ||
value={`${t("common.byterate", { value: data.network.tx_sec })} ↑`} | ||
label={`${t("common.byterate", { value: data.network.rx_sec })} ↓`} | ||
expandedValue={`${t("common.bytes", { value: data.network.tx_bytes })} ↑`} | ||
expandedLabel={`${t("common.bytes", { value: data.network.rx_bytes })} ↓`} | ||
expanded={options.expanded} | ||
wide | ||
percentage={(100 * data.network.rx_sec) / (data.network.rx_sec + data.network.tx_sec)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters