From 563471bfc716cb3116ea738366af5d37aa46bb37 Mon Sep 17 00:00:00 2001 From: Peuuuur-Noel Date: Mon, 6 May 2024 18:48:16 +0000 Subject: [PATCH] - Change the way nchan process is restart - Update refresh for non multi (Unraid pre 6.12) --- .../plugins/gpustat/GPUStatSettings.page | 9 +- .../emhttp/plugins/gpustat/css/style.css | 8 +- .../emhttp/plugins/gpustat/gpustatus.page | 29 ++-- .../emhttp/plugins/gpustat/gpustatus.php | 24 ---- .../gpustat/gpustatusmovablemulti.page | 2 +- .../emhttp/plugins/gpustat/nchan/gpustat | 57 +++++--- .../emhttp/plugins/gpustat/scripts/gpustat.js | 126 ++++++++++-------- 7 files changed, 132 insertions(+), 123 deletions(-) diff --git a/src/gpustat/usr/local/emhttp/plugins/gpustat/GPUStatSettings.page b/src/gpustat/usr/local/emhttp/plugins/gpustat/GPUStatSettings.page index dc621f9..e610e20 100644 --- a/src/gpustat/usr/local/emhttp/plugins/gpustat/GPUStatSettings.page +++ b/src/gpustat/usr/local/emhttp/plugins/gpustat/GPUStatSettings.page @@ -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); } diff --git a/src/gpustat/usr/local/emhttp/plugins/gpustat/css/style.css b/src/gpustat/usr/local/emhttp/plugins/gpustat/css/style.css index 66981c4..b1d67ed 100644 --- a/src/gpustat/usr/local/emhttp/plugins/gpustat/css/style.css +++ b/src/gpustat/usr/local/emhttp/plugins/gpustat/css/style.css @@ -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; } \ No newline at end of file diff --git a/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.page b/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.page index f4fe4ef..67a68b2 100644 --- a/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.page +++ b/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.page @@ -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" --- - + @@ -164,13 +160,7 @@ Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.12.0-b Active Apps - - - - - - - + @@ -353,10 +343,13 @@ Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.12.0-b + diff --git a/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.php b/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.php index 6b0f28a..44d85f1 100644 --- a/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.php +++ b/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatus.php @@ -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(); @@ -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) ; - } diff --git a/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatusmovablemulti.page b/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatusmovablemulti.page index 0a906f7..7880451 100644 --- a/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatusmovablemulti.page +++ b/src/gpustat/usr/local/emhttp/plugins/gpustat/gpustatusmovablemulti.page @@ -90,7 +90,7 @@ foreach ($multigpus as $id=>$gpu) { $layout = GPULayout($gpu["vendor"],$gpustat_cfg) ; $mytiles[$pluginname.$k]['column'.$j] = << + $stats diff --git a/src/gpustat/usr/local/emhttp/plugins/gpustat/nchan/gpustat b/src/gpustat/usr/local/emhttp/plugins/gpustat/nchan/gpustat index f23545c..d752cd6 100755 --- a/src/gpustat/usr/local/emhttp/plugins/gpustat/nchan/gpustat +++ b/src/gpustat/usr/local/emhttp/plugins/gpustat/nchan/gpustat @@ -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; } diff --git a/src/gpustat/usr/local/emhttp/plugins/gpustat/scripts/gpustat.js b/src/gpustat/usr/local/emhttp/plugins/gpustat/scripts/gpustat.js index 828f12f..1a900cd 100644 --- a/src/gpustat/usr/local/emhttp/plugins/gpustat/scripts/gpustat.js +++ b/src/gpustat/usr/local/emhttp/plugins/gpustat/scripts/gpustat.js @@ -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 = $(''); + const 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 = () => {