More sane defaults
This commit is contained in:
parent
753992d390
commit
81e561304a
@ -20,7 +20,6 @@ _Note: unfortunately, the package used for getting CPU temp ([systeminformation]
|
|||||||
cpu: true
|
cpu: true
|
||||||
memory: true
|
memory: true
|
||||||
disk: /disk/mount/path
|
disk: /disk/mount/path
|
||||||
network: default # options: 'default' or active network interface name
|
|
||||||
cputemp: true
|
cputemp: true
|
||||||
tempmin: 0 # optional, minimum cpu temp
|
tempmin: 0 # optional, minimum cpu temp
|
||||||
tempmax: 100 # optional, maximum cpu temp
|
tempmax: 100 # optional, maximum cpu temp
|
||||||
@ -28,6 +27,7 @@ _Note: unfortunately, the package used for getting CPU temp ([systeminformation]
|
|||||||
units: imperial # only used by cpu temp, options: 'imperial' or 'metric'
|
units: imperial # only used by cpu temp, options: 'imperial' or 'metric'
|
||||||
refresh: 3000 # optional, in ms
|
refresh: 3000 # optional, in ms
|
||||||
diskUnits: bytes # optional, bytes (default) or bbytes. Only applies to disk
|
diskUnits: bytes # optional, bytes (default) or bbytes. Only applies to disk
|
||||||
|
network: true # uses 'default' or specify a network interface name
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also pass a `label` option, which allows you to group resources under named sections,
|
You can also pass a `label` option, which allows you to group resources under named sections,
|
||||||
|
|||||||
@ -7,17 +7,11 @@ import Error from "../widget/error";
|
|||||||
|
|
||||||
export default function Network({ options, refresh = 1500 }) {
|
export default function Network({ options, refresh = 1500 }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
if (options.network === true) options.network = "default";
|
||||||
|
|
||||||
const { data, error } = useSWR(
|
const { data, error } = useSWR(`/api/widgets/resources?type=network&interfaceName=${options.network}`, {
|
||||||
`/api/widgets/resources?type=network${
|
refreshInterval: refresh,
|
||||||
options.network || (options.network !== "default" && options.network === `false`)
|
});
|
||||||
? `&interfaceName=${options.network}`
|
|
||||||
: ""
|
|
||||||
}`,
|
|
||||||
{
|
|
||||||
refreshInterval: refresh,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error || data?.error) {
|
if (error || data?.error) {
|
||||||
return <Error />;
|
return <Error />;
|
||||||
|
|||||||
@ -7,8 +7,7 @@ const logger = createLogger("resources");
|
|||||||
const si = require("systeminformation");
|
const si = require("systeminformation");
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const { type, target } = req.query;
|
const { type, target, interfaceName = "default" } = req.query;
|
||||||
let { interfaceName } = req.query;
|
|
||||||
|
|
||||||
if (type === "cpu") {
|
if (type === "cpu") {
|
||||||
const load = await si.currentLoad();
|
const load = await si.currentLoad();
|
||||||
@ -60,7 +59,9 @@ export default async function handler(req, res) {
|
|||||||
|
|
||||||
if (type === "network") {
|
if (type === "network") {
|
||||||
let networkData = await si.networkStats();
|
let networkData = await si.networkStats();
|
||||||
if (interfaceName !== "default" && interfaceName !== undefined && interfaceName !== "false") {
|
let interfaceDefault;
|
||||||
|
logger.debug("networkData:", JSON.stringify(networkData));
|
||||||
|
if (interfaceName && interfaceName !== "default") {
|
||||||
networkData = networkData.filter((network) => network.iface === interfaceName)["0"];
|
networkData = networkData.filter((network) => network.iface === interfaceName)["0"];
|
||||||
if (!networkData) {
|
if (!networkData) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
@ -68,8 +69,7 @@ export default async function handler(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const interfaceDefault = await si.networkInterfaceDefault();
|
interfaceDefault = await si.networkInterfaceDefault();
|
||||||
interfaceName = interfaceDefault;
|
|
||||||
networkData = networkData.filter((network) => network.iface === interfaceDefault)["0"];
|
networkData = networkData.filter((network) => network.iface === interfaceDefault)["0"];
|
||||||
if (!networkData) {
|
if (!networkData) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
@ -79,7 +79,7 @@ export default async function handler(req, res) {
|
|||||||
}
|
}
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
network: networkData,
|
network: networkData,
|
||||||
interface: interfaceName,
|
interface: interfaceName !== "default" ? interfaceName : interfaceDefault,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user