-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use websocket (nchan) instead of ajax polling to refresh data in dashboard #28
base: master
Are you sure you want to change the base?
Changes from 2 commits
d780d5e
c53a469
563471b
18759a2
8a70c00
67ee4b6
1b492f2
6c08b3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ private function detectApplication (SimpleXMLElement $process) | |
foreach ($commands as $command) { | ||
if (strpos($process->process_name, $command) !== false) { | ||
// For Handbrake/ffmpeg: arguments tell us which application called it | ||
if (in_array($command, ['ffmpeg', 'HandbrakeCLI', 'python3.8','python3'])) { | ||
if (in_array($command, ['ffmpeg', 'HandbrakeCLI', 'python3.8', 'python3'])) { | ||
if (isset($process->pid)) { | ||
$pid_info = $this->getFullCommand((int) $process->pid); | ||
if (!empty($pid_info) && strlen($pid_info) > 0) { | ||
|
@@ -113,9 +113,19 @@ private function detectApplication (SimpleXMLElement $process) | |
} | ||
} | ||
} | ||
$this->pageData[$app . 'using'] = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These would still be required for non multi i.e. pre 6.12 unless same changes are applied to the pages and js as this common for both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also updated code for pre 6.12. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nchan can only be used if os is 6.10 or greater. Not sure if there will be users running pre 6.10 Non multy should use ajax updates for backwards compatibilty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will revert it and use ajax polling for non multigpu. Sorry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted to ajax polling for non multi. |
||
$this->pageData[$app . 'mem'] += (int)$this->stripText(' MiB', $process->used_memory); | ||
$this->pageData[$app . 'count']++; | ||
|
||
$usedMemory = (int) $this->stripText(' MiB', $process->used_memory); | ||
$index = array_search($app, array_column($this->pageData['active_apps'], 'name')); | ||
if ($index === false) { | ||
$this->pageData['active_apps'][] = [ | ||
'name' => $app, | ||
'mem' => $usedMemory, | ||
'count' => 1, | ||
]; | ||
} else { | ||
$this->pageData['active_apps'][$index]['mem'] += $usedMemory; | ||
$this->pageData['active_apps'][$index]['count']++; | ||
} | ||
// If we match a more specific command/app to a process, continue on to the next process | ||
break 2; | ||
} | ||
|
@@ -197,11 +207,11 @@ public function getInventorym(): array | |
} | ||
foreach($result as $gpu) { | ||
$cmd =self::CMD_UTILITY . ES . sprintf(self::INVENTORY_PARM_PCI, $gpu['guid']) ; | ||
$cmdres = $this->stdout = shell_exec($cmd); | ||
$cmdres = $this->stdout = shell_exec($cmd); | ||
$pci = substr($cmdres,14,12); | ||
$gpu['id'] = substr($pci,5) ; | ||
$gpu['vendor'] = 'nvidia' ; | ||
$result2[$pci] = $gpu ; | ||
$result2[$pci] = $gpu ; | ||
} | ||
if (empty($result)) $result2=$this->getPCIInventory() ; | ||
} | ||
|
@@ -263,7 +273,7 @@ private function getProductName (string $name) | |
if (strlen($name) > 20 && str_word_count($name) > 2) { | ||
$words = explode(" ", $name); | ||
if ($words[0] == "GeForce") { | ||
array_shift($words) ; | ||
array_shift($words) ; | ||
$words2 = implode(" ", $words) ; | ||
if (strlen($words2) <= 20) $this->pageData['name'] = $words2; | ||
} else $this->pageData['name'] = sprintf("%0s %1s", $words[0], $words[1]); | ||
|
@@ -360,7 +370,7 @@ public function getStatistics() | |
if (!empty($this->stdout) && strlen($this->stdout) > 0) { | ||
$this->parseStatistics(); | ||
} else { | ||
|
||
$this->pageData['error'][] = Error::get(Error::VENDOR_DATA_NOT_RETURNED); | ||
} | ||
} else { | ||
|
@@ -377,7 +387,7 @@ public function getStatistics() | |
$this->pageData["vfio"] = false ; | ||
$this->pageData["vfiochk"] = $this->checkVFIO("0000:".$this->settings['PCIID']) ; | ||
$this->pageData["vfiochkid"] = "0000:".$this->settings['PCIID'] ; | ||
|
||
} else { | ||
$this->pageData["vfio"] = true ; | ||
$this->pageData["vendor"] = "Nvidia" ; | ||
|
@@ -454,12 +464,7 @@ private function parseStatistics() | |
'uuid' => 'N/A', | ||
]; | ||
|
||
// Set App HW Usage Defaults | ||
foreach (self::SUPPORTED_APPS AS $app => $process) { | ||
$this->pageData[$app . "using"] = false; | ||
$this->pageData[$app . "mem"] = 0; | ||
$this->pageData[$app . "count"] = 0; | ||
} | ||
$this->pageData['active_apps'] = []; | ||
if (isset($data->product_name)) { | ||
$this->getProductName($data->product_name); | ||
} | ||
|
@@ -484,7 +489,6 @@ private function parseStatistics() | |
} | ||
// For some reason, encoder_sessions->session_count is not reliable on my install, better to count processes | ||
if ($this->settings['DISPSESSIONS']) { | ||
$this->pageData['appssupp'] = array_keys(self::SUPPORTED_APPS); | ||
if (isset($data->processes->process_info)) { | ||
$this->pageData['sessions'] = count($data->processes->process_info); | ||
if ($this->pageData['sessions'] > 0) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/php -q | ||
<?php | ||
/* | ||
MIT License | ||
|
||
Copyright (c) 2020-2022 b3rs3rk | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
?> | ||
<?php | ||
$docroot = '/usr/local/emhttp'; | ||
|
||
const ES = ' '; | ||
|
||
require_once "$docroot/webGui/include/publish.php"; | ||
|
||
require_once __DIR__ . '/../lib/Main.php'; | ||
require_once __DIR__ . '/../lib/Nvidia.php'; | ||
require_once __DIR__ . '/../lib/Intel.php'; | ||
require_once __DIR__ . '/../lib/AMD.php'; | ||
require_once __DIR__ . '/../lib/Error.php'; | ||
|
||
use gpustat\lib\AMD; | ||
use gpustat\lib\Main; | ||
use gpustat\lib\Nvidia; | ||
use gpustat\lib\Intel; | ||
use gpustat\lib\Error; | ||
|
||
while (true) { | ||
$gpustat_cfg = Main::getSettings(); | ||
$multi = urldecode($gpustat_cfg["MULTIGPUJSON"]); | ||
$multigpus = json_decode($multi, true); | ||
$data = array() ; | ||
|
||
foreach ($multigpus as $gpu) { | ||
$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; | ||
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)); | ||
|
||
$json = json_encode($data) ; | ||
|
||
publish('gpustat', $json); | ||
|
||
file_put_contents("/tmp/gpujson", "Time = " . date(DATE_RFC2822) . "\n" . $json . "\n") ; | ||
|
||
if ($gpustat_cfg['UIREFRESH'] != '1') { | ||
exit; | ||
} | ||
|
||
sleep(round($gpustat_cfg['UIREFRESHINT'] / 1000)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be started automatically when you go back to the dashboard so not sure if this is needed. There is a file in var/run called nchan.pid which contains the running nchan processes but would need to confirm the correct way to stop a process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it too, but monitor_nchan doesn't restart it if path to gpustat is present in
/var/run/nchan.pid
.I didn't find a proper way to stop a nchan process. The only way to stop a process is by adding
:stop
in .page header to nchan attribut, but it's only for a single run. Process killed after 30 seconds.I made change to remove process path in nchan.pid and stop process itself if refresh set to No. Dashboard will restart it every time if necessary.
Removed code from GPUStatSettings.page and updated here:
gpustat-unraid/src/gpustat/usr/local/emhttp/plugins/gpustat/nchan/gpustat
Lines 106 to 110 in 563471b