mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
Add Disk Usage Percentage Stat (#154)
Added disk usage percentage hardware stat Updated Settings-General UI to have table-layout for metrics and other info Added a `synchronized` modifier to the command runner due to some InterruptedThreadExceptions that were spuriously showing up while getting stats. Added additional stack trace logging when issues arise.
This commit is contained in:
@@ -1,21 +1,47 @@
|
||||
<template>
|
||||
<div>
|
||||
<v-row class="pa-4">
|
||||
<span>{{ infoTabs.join(' — ') }}</span>
|
||||
<table class="infoTable">
|
||||
<tr>
|
||||
<th class="infoElem"> Version </th>
|
||||
<th class="infoElem"> Hardware Model </th>
|
||||
<th class="infoElem"> Platform </th>
|
||||
<th class="infoElem"> GPU Acceleration </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="infoElem">{{ version.replace(" ", "") }}</td>
|
||||
<td class="infoElem">{{ hwModel.replace(" ", "") }}</td>
|
||||
<td class="infoElem">{{ platform.replace(" ", "") }}</td>
|
||||
<td class="infoElem">{{ gpuAccel.replace(" ", "") }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table class="infoTable">
|
||||
<tr>
|
||||
<th class="infoElem"> CPU Usage </th>
|
||||
<th class="infoElem"> CPU Temp </th>
|
||||
<th class="infoElem"> CPU Memory Usage </th>
|
||||
<th class="infoElem"> GPU Memory Usage </th>
|
||||
<th class="infoElem"> Disk Usage </th>
|
||||
</tr>
|
||||
<tr v-if="metrics.cpuUtil !== 'N/A'">
|
||||
<td class="infoElem">{{ metrics.cpuUtil.replace(" ", "") }}%</td>
|
||||
<td class="infoElem">{{ parseInt(metrics.cpuTemp) }}° C</td>
|
||||
<td class="infoElem">{{ metrics.ramUtil.replace(" ", "") }}MB of {{ metrics.cpuMem }}MB</td>
|
||||
<td class="infoElem">{{ metrics.gpuMemUtil.replace(" ", "") }}MB of {{ metrics.gpuMem }}MB</td>
|
||||
<td class="infoElem">{{ metrics.diskUtilPct.replace(" ", "") }}</td>
|
||||
</tr>
|
||||
<tr v-if="metrics.cpuUtil === 'N/A'">
|
||||
<td class="infoElem">---</td>
|
||||
<td class="infoElem">---</td>
|
||||
<td class="infoElem">---</td>
|
||||
<td class="infoElem">---</td>
|
||||
<td class="infoElem">---</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</v-row>
|
||||
|
||||
<div v-if="metrics.cpuUtil !== 'N/A'">
|
||||
<v-row class="pa-4">
|
||||
<span>CPU Usage: {{ metrics.cpuUtil.replace(" ", "") }}%</span>
|
||||
–
|
||||
<span>CPU Temp: {{ parseInt(metrics.cpuTemp) }}° C</span>
|
||||
–
|
||||
<span>CPU Memory Usage: {{ metrics.ramUtil.replace(" ", "") }}MB of {{ metrics.cpuMem }}MB</span>
|
||||
–
|
||||
<span>GPU Memory Usage: {{ metrics.gpuMemUtil }}MB of {{ metrics.gpuMem }}MB</span>
|
||||
</v-row>
|
||||
</div>
|
||||
|
||||
<v-row>
|
||||
<v-col
|
||||
cols="12"
|
||||
@@ -120,19 +146,24 @@ export default {
|
||||
settings() {
|
||||
return this.$store.state.settings.general;
|
||||
},
|
||||
infoTabs() {
|
||||
let ret = [];
|
||||
let idx = 0;
|
||||
ret[idx++] = `Version: ${this.settings.version}`;
|
||||
version() {
|
||||
return `${this.settings.version}`;
|
||||
},
|
||||
hwModel() {
|
||||
if (this.settings.hardwareModel !== '') {
|
||||
ret[idx++] = `Hardware model: ${this.settings.hardwareModel}`;
|
||||
return `${this.settings.hardwareModel}`;
|
||||
} else {
|
||||
return `Unknown`;
|
||||
}
|
||||
ret[idx++] = `Platform: ${this.settings.hardwarePlatform}`;
|
||||
ret[idx++] = `GPU Acceleration: ${this.settings.gpuAcceleration ? "Enabled" : "Unsupported"}${this.settings.gpuAcceleration ? " (" + this.settings.gpuAcceleration + " mode)" : ""}`
|
||||
|
||||
return ret;
|
||||
},
|
||||
platform() {
|
||||
return `${this.settings.hardwarePlatform}`;
|
||||
},
|
||||
gpuAccel() {
|
||||
return `${this.settings.gpuAcceleration ? "Enabled" : "Unsupported"}${this.settings.gpuAcceleration ? " (" + this.settings.gpuAcceleration + " mode)" : ""}`
|
||||
},
|
||||
metrics() {
|
||||
console.log(this.$store.state.metrics);
|
||||
return this.$store.state.metrics;
|
||||
}
|
||||
},
|
||||
@@ -169,4 +200,23 @@ export default {
|
||||
.v-btn {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.infoTable{
|
||||
border: 1px solid;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0px;
|
||||
border-radius: 5px;
|
||||
text-align: left;
|
||||
margin-bottom: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.infoElem {
|
||||
padding-right: 15px;
|
||||
padding-bottom: 1px;
|
||||
padding-top: 1px;
|
||||
padding-left: 10px;
|
||||
border-right: 1px solid;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -43,6 +43,7 @@ public class HardwareConfig {
|
||||
public final String gpuMemoryCommand;
|
||||
public final String ramUtilCommand;
|
||||
public final String gpuMemUsageCommand;
|
||||
public final String diskUsageCommand;
|
||||
|
||||
// Device stuff
|
||||
public final String restartHardwareCommand;
|
||||
@@ -67,6 +68,7 @@ public class HardwareConfig {
|
||||
ramUtilCommand = "";
|
||||
ledBlinkCommand = "";
|
||||
gpuMemUsageCommand = "";
|
||||
diskUsageCommand = "";
|
||||
|
||||
restartHardwareCommand = "";
|
||||
vendorFOV = -1;
|
||||
@@ -91,6 +93,7 @@ public class HardwareConfig {
|
||||
String gpuMemoryCommand,
|
||||
String ramUtilCommand,
|
||||
String gpuMemUsageCommand,
|
||||
String diskUsageCommand,
|
||||
String restartHardwareCommand,
|
||||
double vendorFOV,
|
||||
List<Integer> blacklistedResIndices) {
|
||||
@@ -110,6 +113,7 @@ public class HardwareConfig {
|
||||
this.gpuMemoryCommand = gpuMemoryCommand;
|
||||
this.ramUtilCommand = ramUtilCommand;
|
||||
this.gpuMemUsageCommand = gpuMemUsageCommand;
|
||||
this.diskUsageCommand = diskUsageCommand;
|
||||
this.restartHardwareCommand = restartHardwareCommand;
|
||||
this.vendorFOV = vendorFOV;
|
||||
this.blacklistedResIndices = blacklistedResIndices;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Photon Vision.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonvision.common.hardware.metrics;
|
||||
|
||||
public class DiskMetrics extends MetricsBase {
|
||||
public String getUsedDiskPct() {
|
||||
if (diskUsageCommand.isEmpty()) return "";
|
||||
return execute(diskUsageCommand);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package org.photonvision.common.hardware.metrics;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import org.photonvision.common.configuration.HardwareConfig;
|
||||
import org.photonvision.common.hardware.Platform;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
@@ -39,6 +41,9 @@ public abstract class MetricsBase {
|
||||
// RAM
|
||||
public static String ramUsageCommand = "free --mega | awk -v i=2 -v j=3 'FNR == i {print $j}'";
|
||||
|
||||
// Disk
|
||||
public static String diskUsageCommand = "df ./ --output=pcent | tail -n +2";
|
||||
|
||||
private static ShellExec runCommand = new ShellExec(true, true);
|
||||
|
||||
public static void setConfig(HardwareConfig config) {
|
||||
@@ -50,14 +55,20 @@ public abstract class MetricsBase {
|
||||
gpuMemoryCommand = config.gpuMemoryCommand;
|
||||
gpuMemUsageCommand = config.gpuMemUsageCommand;
|
||||
|
||||
diskUsageCommand = config.diskUsageCommand;
|
||||
|
||||
ramUsageCommand = config.ramUtilCommand;
|
||||
}
|
||||
|
||||
public static String execute(String command) {
|
||||
public static synchronized String execute(String command) {
|
||||
try {
|
||||
runCommand.executeBashCommand(command);
|
||||
return runCommand.getOutput();
|
||||
} catch (Exception e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
|
||||
logger.error(
|
||||
"Command: \""
|
||||
+ command
|
||||
@@ -71,7 +82,10 @@ public abstract class MetricsBase {
|
||||
+ "\nError completed: "
|
||||
+ runCommand.isErrorCompleted()
|
||||
+ "\nExit code: "
|
||||
+ runCommand.getExitCode());
|
||||
+ runCommand.getExitCode()
|
||||
+ "\n Exception: "
|
||||
+ e.toString()
|
||||
+ sw.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class MetricsPublisher {
|
||||
private static CPUMetrics cpuMetrics;
|
||||
private static GPUMetrics gpuMetrics;
|
||||
private static RAMMetrics ramMetrics;
|
||||
private static DiskMetrics diskMetrics;
|
||||
|
||||
public static MetricsPublisher getInstance() {
|
||||
return Singleton.INSTANCE;
|
||||
@@ -39,6 +40,7 @@ public class MetricsPublisher {
|
||||
cpuMetrics = new CPUMetrics();
|
||||
gpuMetrics = new GPUMetrics();
|
||||
ramMetrics = new RAMMetrics();
|
||||
diskMetrics = new DiskMetrics();
|
||||
}
|
||||
|
||||
public void stopTask() {
|
||||
@@ -61,6 +63,7 @@ public class MetricsPublisher {
|
||||
metrics.put("gpuMem", gpuMetrics.getGPUMemorySplit());
|
||||
metrics.put("ramUtil", ramMetrics.getUsedRam());
|
||||
metrics.put("gpuMemUtil", gpuMetrics.getMallocedMemory());
|
||||
metrics.put("diskUtilPct", diskMetrics.getUsedDiskPct());
|
||||
|
||||
var retMap = new HashMap<String, Object>();
|
||||
retMap.put("metrics", metrics);
|
||||
|
||||
Reference in New Issue
Block a user