Add support for multiple volumes as well as defining the volume you want to track
This commit is contained in:
parent
cfd47caf72
commit
9fa48bc6e5
@ -175,7 +175,8 @@
|
|||||||
"cpuUsage": "CPU Usage",
|
"cpuUsage": "CPU Usage",
|
||||||
"memUsage": "MEM Usage",
|
"memUsage": "MEM Usage",
|
||||||
"systemTempC": "System Temp",
|
"systemTempC": "System Temp",
|
||||||
"poolUsage": "Pool Usage"
|
"poolUsage": "Pool Usage",
|
||||||
|
"volumeUsage": "Volume Usage"
|
||||||
},
|
},
|
||||||
"deluge": {
|
"deluge": {
|
||||||
"download": "Download",
|
"download": "Download",
|
||||||
|
|||||||
@ -306,7 +306,7 @@ export function cleanServiceGroups(groups) {
|
|||||||
if (enableBlocks !== undefined) cleanedService.widget.enableBlocks = JSON.parse(enableBlocks);
|
if (enableBlocks !== undefined) cleanedService.widget.enableBlocks = JSON.parse(enableBlocks);
|
||||||
if (enableNowPlaying !== undefined) cleanedService.widget.enableNowPlaying = JSON.parse(enableNowPlaying);
|
if (enableNowPlaying !== undefined) cleanedService.widget.enableNowPlaying = JSON.parse(enableNowPlaying);
|
||||||
}
|
}
|
||||||
if (type === "diskstation") {
|
if (["diskstation", "qnap"].includes(type)) {
|
||||||
if (volume) cleanedService.widget.volume = volume;
|
if (volume) cleanedService.widget.volume = volume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export default function Component({ service }) {
|
|||||||
<Block label="qnap.cpuUsage" />
|
<Block label="qnap.cpuUsage" />
|
||||||
<Block label="qnap.memUsage" />
|
<Block label="qnap.memUsage" />
|
||||||
<Block label="qnap.systemTempC" />
|
<Block label="qnap.systemTempC" />
|
||||||
<Block label="qnap.poolUsage" />
|
<Block label={(widget.volume) ? "qnap.volumeUsage" : "qnap.poolUsage" } />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -32,9 +32,30 @@ export default function Component({ service }) {
|
|||||||
const totalMemory = statusData.system.total_memory._cdata;
|
const totalMemory = statusData.system.total_memory._cdata;
|
||||||
const freeMemory = statusData.system.free_memory._cdata;
|
const freeMemory = statusData.system.free_memory._cdata;
|
||||||
const systemTempC = statusData.system.cpu_tempc._text;
|
const systemTempC = statusData.system.cpu_tempc._text;
|
||||||
|
let volumeTotalSize = 0;
|
||||||
|
let volumeFreeSize = 0;
|
||||||
|
let validVolume = true;
|
||||||
|
|
||||||
const volumeTotalSize = statusData.volume.volumeUse.total_size._cdata;
|
if(Array.isArray(statusData.volume.volumeUseList.volumeUse)){
|
||||||
const volumeFreeSize = statusData.volume.volumeUse.free_size._cdata;
|
if(widget.volume){
|
||||||
|
const volumeSelected = statusData.volume.volumeList.volume.findIndex(vl => vl.volumeLabel._cdata === widget.volume);
|
||||||
|
if(volumeSelected !== -1){
|
||||||
|
volumeTotalSize = statusData.volume.volumeUseList.volumeUse[volumeSelected].total_size._cdata;
|
||||||
|
volumeFreeSize = statusData.volume.volumeUseList.volumeUse[volumeSelected].free_size._cdata;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
validVolume = false;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
statusData.volume.volumeUseList.volumeUse.forEach((volume) => {
|
||||||
|
volumeTotalSize += Number(volume.total_size._cdata);
|
||||||
|
volumeFreeSize += Number(volume.free_size._cdata);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
volumeTotalSize = statusData.volume.volumeUseList.volumeUse.total_size._cdata;
|
||||||
|
volumeFreeSize = statusData.volume.volumeUseList.volumeUse.free_size._cdata;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
@ -51,8 +72,8 @@ export default function Component({ service }) {
|
|||||||
value={t("common.number", { value: systemTempC, maximumFractionDigits: 1, style: "unit", unit: "celsius" })}
|
value={t("common.number", { value: systemTempC, maximumFractionDigits: 1, style: "unit", unit: "celsius" })}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="qnap.poolUsage"
|
label={(widget.volume) ? "qnap.volumeUsage" : "qnap.poolUsage" }
|
||||||
value={t("common.percent", { value: (((volumeTotalSize - volumeFreeSize) / volumeTotalSize) * 100).toFixed(0) })}
|
value={(validVolume) ? t("common.percent", { value: (((volumeTotalSize - volumeFreeSize) / volumeTotalSize) * 100).toFixed(0) }) : "invalid"}
|
||||||
/>
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -99,6 +99,6 @@ export default async function qnapProxyHandler(req, res) {
|
|||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
system: systemStatsData.QDocRoot.func.ownContent.root,
|
system: systemStatsData.QDocRoot.func.ownContent.root,
|
||||||
volume: volumeStatsData.QDocRoot.volumeUseList
|
volume: volumeStatsData.QDocRoot
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user