Skip to content

Commit

Permalink
- Change the way nchan process is restart
Browse files Browse the repository at this point in the history
- Update refresh for non multi (Unraid pre 6.12)
  • Loading branch information
Peuuuur-Noel committed May 6, 2024
1 parent c53a469 commit 563471b
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,7 @@ Title="GPU Statistics"
$cfg = NULL ;
if ($_POST['#apply'] == "_(Apply)_") {
array_map(function($k, $v) use (&$cfg) { if($k[0] != "#") $cfg[$k] = $v; }, array_keys($_POST), $_POST );
save_cfg($cfg,$gpustat_data) ;

// Restart nchan gpustat if not running when refresh setting set to Yes
$pid = exec('pgrep gpustat');
if (!$pid && $_POST['UIREFRESH'] == '1' && $gpustat_cfg['UIREFRESH'] != '1') {
exec('/usr/local/emhttp/plugins/gpustat/nchan/gpustat &>/dev/null &');
}

save_cfg($cfg,$gpustat_data);
$gpustat_cfg = parse_plugin_cfg("gpustat", true);
unset($_POST);
}
Expand Down
8 changes: 6 additions & 2 deletions src/gpustat/usr/local/emhttp/plugins/gpustat/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
margin-top: 0;
}

span.gpu {
.gpustat span.gpu {
width: 150px;
display: inline-block;
}

.gpu-image {
.gpustat .gpu-image {
padding-left: 8px;
height: 32px;
width: 32px;
}

.gpustat .usage-disk > span {
transition: width 0.5s;
}
29 changes: 11 additions & 18 deletions src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.page
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Menu="Dashboard"
Icon="gpustat.png"
Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.12.0-beta6', '<')"
Nchan="gpustat"
---
<?php
/*
Expand Down Expand Up @@ -31,11 +32,6 @@ Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.12.0-b

$gpu_nv = $gpu_intel = $gpu_amd = $gpu_unknown = false;

$apps = [
'plex', 'jellyfin', 'handbrake', 'emby', 'tdarr', 'unmanic', 'dizquetv', 'ersatztv',
'fileflows', 'frigate', 'deepstack', 'nsfminer', 'shinobipro', 'foldinghome', 'compreface',
];

switch ($gpustat_cfg['VENDOR']) {
case "nvidia":
$gpu_nv = true;
Expand All @@ -59,7 +55,7 @@ Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.12.0-b

<table id='db-box1' class='dash_gpustat dashboard box1' style='display:none'>
<thead sort='953'><tr class='hidden'><td></td><td colspan='3'></td><td></td></tr></thead>
<tbody sort='953' class='sortable'>
<tbody sort='953' class='gpustat sortable'>
<tr>
<td></td>
<td class='next' colspan='3'>
Expand Down Expand Up @@ -164,13 +160,7 @@ Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.12.0-b
<tr class="dash_gpustat_toggle gpu-enviro">
<td></td>
<td>Active Apps</td>
<td colspan="2">
<?php foreach($apps as $app): ?>
<span id="gpu-img-span-<?= $app; ?>" class='gpu-img-span gpu-img-span-<?= $app; ?>'>
<img id='gpu-<?= $app; ?>' class='gpu-image' src="/plugins/gpustat/images/<?= $app; ?>.png">
</span>
<?php endforeach; ?>
</td>
<td colspan="2" class="gpu-active-apps"></td>
<td></td>
</tr>
<?php endif; ?>
Expand Down Expand Up @@ -353,10 +343,13 @@ Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.12.0-b
</table>
<?php endif; ?>
<script type="text/javascript" src="/plugins/gpustat/scripts/gpustat.js"></script>

<script type="text/javascript">
$(gpustat_status);
if (<?=$gpustat_cfg['UIREFRESH'];?>) {
setInterval(gpustat_status, <?=max(abs($display['refresh']), $gpustat_cfg['UIREFRESHINT']);?>);
}
$(gpustat_dash);
$(gpustat_status);
const gpustat_ws = new NchanSubscriber('/sub/gpustat');
gpustat_ws.on('message', (data) => {
parseStats(JSON.parse(data));
});
gpustat_ws.start();
$(gpustat_dash);
</script>
24 changes: 0 additions & 24 deletions src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
include 'lib/Nvidia.php';
include 'lib/Intel.php';
include 'lib/AMD.php';
include 'lib/Error.php';

use gpustat\lib\AMD;
use gpustat\lib\Main;
use gpustat\lib\Nvidia;
use gpustat\lib\Intel;
use gpustat\lib\Error;

if (!isset($gpustat_cfg)) {
$gpustat_cfg = Main::getSettings();
Expand All @@ -47,26 +45,4 @@
$gpustat_cfg['inventory'] = true;
// Settings page looks for $gpustat_data specifically -- inventory all supported GPU types
$gpustat_data = array_merge((new Nvidia($gpustat_cfg))->getInventory(), (new Intel($gpustat_cfg))->getInventory(), (new AMD($gpustat_cfg))->getInventory());
} else {

switch ($gpustat_cfg['VENDOR']) {
case 'amd':
$data = (new AMD($gpustat_cfg))->getStatistics();
break;
case 'intel':
$data = (new Intel($gpustat_cfg))->getStatistics();
break;
case 'nvidia':
$data = (new Nvidia($gpustat_cfg))->getStatistics();
break;
default:
print_r(Error::get(Error::CONFIG_SETTINGS_NOT_VALID));
}
$json = $data ;
header('Content-Type: application/json');
header('Content-Length:' . ES . strlen($json));
echo $json;
file_put_contents("/tmp/gpujson2","Time = ".date(DATE_RFC2822)."\n") ;
file_put_contents("/tmp/gpujson2",$json."\n",FILE_APPEND) ;

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ foreach ($multigpus as $id=>$gpu) {
$layout = GPULayout($gpu["vendor"],$gpustat_cfg) ;
$mytiles[$pluginname.$k]['column'.$j] =
<<<EOT
<tbody title="_(GPU #$i Stats)_" data-gpu-id="{$gpu['id']}">
<tbody title="_(GPU #$i Stats)_" data-gpu-id="{$gpu['id']}" class="gpustat">
<tr><td><i class='icon-hardware f32'></i>
$stats
<a href="Dashboard/Settings/GPUStatSettings" title="_(Go to GPU Statistics settings)_"><i class="fa fa-fw fa-cog control"></i></a></td></tr>
Expand Down
57 changes: 39 additions & 18 deletions src/gpustat/usr/local/emhttp/plugins/gpustat/nchan/gpustat
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,69 @@ use gpustat\lib\Nvidia;
use gpustat\lib\Intel;
use gpustat\lib\Error;

$gpustat_multi_enable = version_compare(parse_ini_file('/etc/unraid-version')['version'], '6.12.0-beta5', '>');

while (true) {
$gpustat_cfg = Main::getSettings();
$multi = urldecode($gpustat_cfg["MULTIGPUJSON"]);
$multigpus = json_decode($multi, true);
$data = array() ;
$data = array();

if ($gpustat_multi_enable) {
$multi = urldecode($gpustat_cfg["MULTIGPUJSON"]);
$multigpus = json_decode($multi, true);
} else {
$multigpus = [
[
'vendor' => $gpustat_cfg["VENDOR"],
'guid' => $gpustat_cfg["GPUID"],
'id' => null,
],
];
}

foreach ($multigpus as $gpu) {
$gpustat_cfg["VENDOR"] = $gpu['vendor'] ;
$gpustat_cfg["GPUID"] = $gpu['guid'] ;
$gpustat_cfg["PCIID"] = $gpu['id'] ;
if ($gpustat_multi_enable) {
$gpustat_cfg["VENDOR"] = $gpu['vendor'];
$gpustat_cfg["GPUID"] = $gpu['guid'];
$gpustat_cfg["PCIID"] = $gpu['id'];
}

switch ($gpu['vendor']) {
case 'amd':
$return = (new AMD($gpustat_cfg))->getStatistics();
$decode = json_decode($return, true);
$data[$gpu["id"]] = $decode;
break;
case 'intel':
$return = (new Intel($gpustat_cfg))->getStatistics();
$decode = json_decode($return, true);
$data[$gpu["id"]] = $decode;
break;
case 'nvidia':
$return = (new Nvidia($gpustat_cfg))->getStatistics() ;
$decode = json_decode($return, true);
$data[$gpu["id"]] = $decode;
$return = (new Nvidia($gpustat_cfg))->getStatistics();
break;
default:
print_r(Error::get(Error::CONFIG_SETTINGS_NOT_VALID));
}
}

// Test data
// $data = array_merge($data, json_decode('{"00:02.0": {"clock": 100, "fan": 50, "memclock": 500, "memutil": 55, "memused": 55, "power": "100W", "powermax": 500, "rxutil": 50, "txutil": 60, "temp": 50, "tempmax": 200, "util": "40%", "vendor": "Intel", "name": "AlderLake-S GT1", "3drender": "50%", "blitter": "50%", "interrupts": 100, "powerutil": "10%", "video": "20%", "videnh": "30%"}, "09:00.0": {"clock": 0, "fan": "N\/A", "memclock": "N\/A", "memutil": "N\/A", "memused": "N\/A", "power": "N\/A", "powermax": "N\/A", "rxutil": "N\/A", "txutil": "N\/A", "temp": "N\/A", "tempmax": "N\/A", "util": "0%", "vendor": "Intel", "name": "DG2 [Arc A770]", "3drender": "0%", "blitter": "0%", "interrupts": 0, "powerutil": "0%", "video": "0%", "videnh": "0%"}, "08:00.0": {"active_apps":[{"name": "plex", "mem": 214, "count": 2}], "clock": "810", "fan": "30%", "memclock": "2808", "memutil": "50%", "memused": "50", "power": "28W", "powermax": "87", "rxutil": 50, "txutil": 60, "temp": "41 \u00b0C", "tempmax": "101 \u00b0C", "util": "77%", "vendor": "NVIDIA", "name": "Quadro K4000", "clockmax": "810", "memclockmax": "2808", "memtotal": "3018", "encutil": "50%", "decutil": "50%", "pciemax": 500, "perfstate": "P0", "throttled": "No", "thrtlrsn": "", "pciegen": 2, "pciegenmax": 2, "pciewidth": 1, "pciewidthmax": 16, "sessions": 2, "uuid": "GPU-ef6c0299-f1bc-7b5c-5291-7cd1a012f8bd"}, "0c:00.0": {"clock": 2110.5, "fan": 200, "memclock": 2220.1, "memutil": "21.2%", "memused": 47.51, "power": 50, "powermax": 200, "rxutil": "N\/A", "txutil": 67, "temp": "38 \u00b0C", "tempmax": 105, "util": "90%", "vendor": "AMD", "name": "Radeon RX 6400\/6500 XT\/6500M", "event": "80%", "vertex": "70%", "texture": "60%", "shaderexp": "50%", "sequencer": "40%", "shaderinter": "30%", "scancon": "30%", "primassem": "30%", "depthblk": "30%", "colorblk": "30%", "gfxtrans": "44.1%", "transused": 11.57, "memclockutil": "9.6%", "clockutil": "21.6%", "tempunit": "C", "fanmax": 5550, "voltage": 77.7, "voltageunit": "V"}}', true));
if ($gpustat_multi_enable) {
$decode = json_decode($return, true);

if ($decode != NULL) {
$data[$gpu["id"]] = $decode;
}

// Test data
// $data = array_merge($data, json_decode('{"00:02.0": {"clock": 100, "fan": 50, "memclock": 500, "memutil": 55, "memused": 55, "power": "100W", "powermax": 500, "rxutil": 50, "txutil": 60, "temp": 50, "tempmax": 200, "util": "40%", "vendor": "Intel", "name": "AlderLake-S GT1", "3drender": "50%", "blitter": "50%", "interrupts": 100, "powerutil": "10%", "video": "20%", "videnh": "30%"}, "09:00.0": {"clock": 0, "fan": "N\/A", "memclock": "N\/A", "memutil": "N\/A", "memused": "N\/A", "power": "N\/A", "powermax": "N\/A", "rxutil": "N\/A", "txutil": "N\/A", "temp": "N\/A", "tempmax": "N\/A", "util": "0%", "vendor": "Intel", "name": "DG2 [Arc A770]", "3drender": "0%", "blitter": "0%", "interrupts": 0, "powerutil": "0%", "video": "0%", "videnh": "0%"}, "08:00.0": {"active_apps":[{"name": "plex", "mem": 214, "count": 2}], "clock": "810", "fan": "30%", "memclock": "2808", "memutil": "50%", "memused": "50", "power": "28W", "powermax": "87", "rxutil": 50, "txutil": 60, "temp": "41 \u00b0C", "tempmax": "101 \u00b0C", "util": "77%", "vendor": "NVIDIA", "name": "Quadro K4000", "clockmax": "810", "memclockmax": "2808", "memtotal": "3018", "encutil": "50%", "decutil": "50%", "pciemax": 500, "perfstate": "P0", "throttled": "No", "thrtlrsn": "", "pciegen": 2, "pciegenmax": 2, "pciewidth": 1, "pciewidthmax": 16, "sessions": 2, "uuid": "GPU-ef6c0299-f1bc-7b5c-5291-7cd1a012f8bd"}, "0c:00.0": {"clock": 2110.5, "fan": 200, "memclock": 2220.1, "memutil": "21.2%", "memused": 47.51, "power": 50, "powermax": 200, "rxutil": "N\/A", "txutil": 67, "temp": "38 \u00b0C", "tempmax": 105, "util": "90%", "vendor": "AMD", "name": "Radeon RX 6400\/6500 XT\/6500M", "event": "80%", "vertex": "70%", "texture": "60%", "shaderexp": "50%", "sequencer": "40%", "shaderinter": "30%", "scancon": "30%", "primassem": "30%", "depthblk": "30%", "colorblk": "30%", "gfxtrans": "44.1%", "transused": 11.57, "memclockutil": "9.6%", "clockutil": "21.6%", "tempunit": "C", "fanmax": 5550, "voltage": 77.7, "voltageunit": "V"}}', true));

$json = json_encode($data) ;
$json = json_encode($data);
} else {
$json = $return;
}
}

publish('gpustat', $json);

file_put_contents("/tmp/gpujson", "Time = " . date(DATE_RFC2822) . "\n" . $json . "\n") ;
file_put_contents("/tmp/gpujson", "Time = " . date(DATE_RFC2822) . PHP_EOL . $json . PHP_EOL);

// Stop nchan gpustat if refresh setting set to No and remove it from /var/run/nchan.pid
if ($gpustat_cfg['UIREFRESH'] != '1') {
exec('sed -i "/plugins\/gpustat\/nchan\/gpustat/d" /var/run/nchan.pid');
exit;
}

Expand Down
126 changes: 74 additions & 52 deletions src/gpustat/usr/local/emhttp/plugins/gpustat/scripts/gpustat.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,63 +22,85 @@
SOFTWARE.
*/

const gpustat_status = () => {
$.getJSON('/plugins/gpustat/gpustatus.php', (data) => {
if (data) {
switch (data["vendor"]) {
case 'NVIDIA':
// Nvidia Slider Bars
$('.gpu-memclockbar').removeAttr('style').css('width', data["memclock"] / data["memclockmax"] * 100 + "%");
$('.gpu-gpuclockbar').removeAttr('style').css('width', data["clock"] / data["clockmax"] * 100 + "%");
$('.gpu-powerbar').removeAttr('style').css('width', parseInt(data["power"].replace("W","") / data["powermax"] * 100) + "%");
$('.gpu-rxutilbar').removeAttr('style').css('width', parseInt(data["rxutil"] / data["pciemax"] * 100) + "%");
$('.gpu-txutilbar').removeAttr('style').css('width', parseInt(data["txutil"] / data["pciemax"] * 100) + "%");
const parseStats = (data) => {
if (data) {
switch (data["vendor"]) {
case 'NVIDIA':
// Nvidia Slider Bars
$('.gpu-memclockbar').removeAttr('style').css('width', data["memclock"] / data["memclockmax"] * 100 + "%");
$('.gpu-gpuclockbar').removeAttr('style').css('width', data["clock"] / data["clockmax"] * 100 + "%");
$('.gpu-powerbar').removeAttr('style').css('width', parseInt(data["power"].replace("W","") / data["powermax"] * 100) + "%");
$('.gpu-rxutilbar').removeAttr('style').css('width', parseInt(data["rxutil"] / data["pciemax"] * 100) + "%");
$('.gpu-txutilbar').removeAttr('style').css('width', parseInt(data["txutil"] / data["pciemax"] * 100) + "%");

let nvidiabars = ['util', 'memutil', 'encutil', 'decutil', 'fan'];
nvidiabars.forEach(function (metric) {
$('.gpu-'+metric+'bar').removeAttr('style').css('width', data[metric]);
});
let nvidiabars = ['util', 'memutil', 'encutil', 'decutil', 'fan'];
nvidiabars.forEach(function (metric) {
$('.gpu-'+metric+'bar').removeAttr('style').css('width', data[metric]);
});

if (data["appssupp"]) {
data["appssupp"].forEach(function (app) {
if (data[app + "using"]) {
$('.gpu-img-span-'+app).css('display', "inline");
$('#gpu-'+app).attr('title', "Count: " + data[app+"count"] + " Memory: " + data[app+"mem"] + "MB");
} else {
$('.gpu-img-span-'+app).css('display', "none");
$('#gpu-'+app).attr('title', "");
}
});
}
break;
case 'Intel':
// Intel Slider Bars
let intelbars = ['3drender', 'blitter', 'video', 'videnh', 'powerutil'];
intelbars.forEach(function (metric) {
$('.gpu-'+metric+'bar').removeAttr('style').css('width', data[metric]);
});
break;
case 'AMD':
$('.gpu-powerbar').removeAttr('style').css('width', parseInt(data["power"] / data["powermax"] * 100) + "%");
$('.gpu-fanbar').removeAttr('style').css('width', parseInt(data["fan"] / data["fanmax"] * 100) + "%");
let amdbars = [
'util', 'event', 'vertex',
'texture', 'shaderexp', 'sequencer',
'shaderinter', 'scancon', 'primassem',
'depthblk', 'colorblk', 'memutil',
'gfxtrans', 'memclockutil', 'clockutil'
];
amdbars.forEach(function (metric) {
$('.gpu-'+metric+'bar').removeAttr('style').css('width', data[metric]);
if (data["appssupp"]) {
data["appssupp"].forEach(function (app) {
if (data[app + "using"]) {
$('.gpu-img-span-'+app).css('display', "inline");
$('#gpu-'+app).attr('title', "Count: " + data[app+"count"] + " Memory: " + data[app+"mem"] + "MB");
} else {
$('.gpu-img-span-'+app).css('display', "none");
$('#gpu-'+app).attr('title', "");
}
});
break;
}
}
break;
case 'Intel':
// Intel Slider Bars
let intelbars = ['3drender', 'blitter', 'video', 'videnh', 'powerutil'];
intelbars.forEach(function (metric) {
$('.gpu-'+metric+'bar').removeAttr('style').css('width', data[metric]);
});
break;
case 'AMD':
$('.gpu-powerbar').removeAttr('style').css('width', parseInt(data["power"] / data["powermax"] * 100) + "%");
$('.gpu-fanbar').removeAttr('style').css('width', parseInt(data["fan"] / data["fanmax"] * 100) + "%");
let amdbars = [
'util', 'event', 'vertex',
'texture', 'shaderexp', 'sequencer',
'shaderinter', 'scancon', 'primassem',
'depthblk', 'colorblk', 'memutil',
'gfxtrans', 'memclockutil', 'clockutil'
];
amdbars.forEach(function (metric) {
$('.gpu-'+metric+'bar').removeAttr('style').css('width', data[metric]);
});
break;
}

$.each(data, function (key, data) {
$('.gpu-'+key).html(data);
})
if (data["active_apps"]) {
const appList = [];
$('.gpu-active-apps .gpu-img-span').each(function () {
appList.push($(this).data('name'));
});
const active_apps = [];
data["active_apps"].forEach(function (app) {
active_apps.push(app.name);
const title = 'Count: ' + app.count + ' - Memory: ' + app.mem + 'MB';
if (appList.includes(app.name)) {
$('.gpu-active-apps span[data-name="' + app.name + '"] img').attr('title', title);
} else {
const img = $('<img class="gpu-image" src="/plugins/gpustat/images/' + app.name + '.png" title="' + title + '">');
const span = $('<span class="gpu-img-span" data-name="' + app.name + '"></span>');
span.append(img);
$('.gpu-active-apps').append(span);
}
});
$('.gpu-active-apps td span.gpu-img-span').each(function () {
if (!active_apps.includes($(this).data('name')))
$(this).remove();
});
}
});

$.each(data, function (key, data) {
$('.gpu-'+key).html(data);
})
}
};

const gpustat_dash = () => {
Expand Down

0 comments on commit 563471b

Please sign in to comment.