mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Websockets (#7393)
* Initial commit of websockets * Move app_menu to the active_calls websockets * Fix hangup function * Remove connection wait-state on web socket server so events can process * Add timestamp and debug level to console for service debug output * Remove debug exit * Fix typo for ws_client instead of ws_server * Update app_config.php * Fix typo and remove empty function * Remove call to empty function * Fix the menu to point to the correct location * Remove Logging Class * Rename service file * Rename service file * Fix the in progress browser request * Fix browser reload and implement 'active_calls' default values * Add apply_filter function * Create new permission_filter object * In progress active calls now use filter * Add invalid_uuid_exception class * add event_key_filter to honor user permissions * add and_link and or_link for filters * Fix disconnected subscriber and add filters to honor permissions * Add $key and $value for filter * define a service name * catch throwable instead of exception * Add $key and $value for filter and allow returning null * Update permission checks when loading page * Add apply_filter function to honor subscriber permissions * Add create_filter_chain_for function to honor subscriber permissions * Add apply_filter function to honor subscriber permissions * Add apply_filter function to honor subscriber permissions * create interface to allow filterable payload * create interface to define functions required for websocket services * Pass in service class when creating a service token * Allow key/name and return null for filter * Adjust subscriber exceptions to return the ID of the subscriber * Add event filter to filter chain * Add command line options for ip and port for websockets and switch * update service to use is_a syntax * initial commit of base class for websockets system services * initial commit of the system cpu status service * remove extra line feed * fix path on active_calls * initial proof of concept for cpu status updated by websockets * Allow returning null * Use default settings to set the interval for cpu status broadcast * Improve the CPU percent function for Linux systems * Show more debug information * Allow child processes to re-connect to the web socket service * Fix websockets as plural instead of singular * Add class name list-row * Update active_calls.php * Update active_calls.php * Update websocket_client.js * Update app_config.php * Update app_menu.php * Update debian-websockets.service * Update debian-active_calls.service --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
This commit is contained in:
78
app/system/resources/classes/linux_system_information.php
Normal file
78
app/system/resources/classes/linux_system_information.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright 2025 Tim Fry <tim@fusionpbx.com>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of linux_system_information
|
||||
*
|
||||
* @author Tim Fry <tim@fusionpbx.com>
|
||||
*/
|
||||
class linux_system_information extends system_information {
|
||||
|
||||
public function get_cpu_cores(): int {
|
||||
$result = @trim(shell_exec("grep -P '^processor' /proc/cpuinfo"));
|
||||
$cpu_cores = count(explode("\n", $result));
|
||||
return $cpu_cores;
|
||||
}
|
||||
|
||||
//get the CPU details
|
||||
public function get_cpu_percent(): float {
|
||||
$stat1 = file_get_contents('/proc/stat');
|
||||
usleep(500000);
|
||||
$stat2 = file_get_contents('/proc/stat');
|
||||
|
||||
$lines1 = explode("\n", trim($stat1));
|
||||
$lines2 = explode("\n", trim($stat2));
|
||||
|
||||
$percent_cpu = 0;
|
||||
$core_count = 0;
|
||||
|
||||
foreach ($lines1 as $i => $line1) {
|
||||
if (strpos($line1, 'cpu') !== 0 || $line1 === 'cpu') continue;
|
||||
|
||||
$parts1 = preg_split('/\s+/', $line1);
|
||||
$parts2 = preg_split('/\s+/', $lines2[$i]);
|
||||
|
||||
$total1 = array_sum(array_slice($parts1, 1));
|
||||
$total2 = array_sum(array_slice($parts2, 1));
|
||||
|
||||
$idle1 = $parts1[4];
|
||||
$idle2 = $parts2[4];
|
||||
|
||||
$total_delta = $total2 - $total1;
|
||||
$idle_delta = $idle2 - $idle1;
|
||||
|
||||
$cpu_usage = ($total_delta - $idle_delta) / $total_delta * 100;
|
||||
$percent_cpu += $cpu_usage;
|
||||
$core_count++;
|
||||
}
|
||||
|
||||
return round($percent_cpu / $core_count, 2);
|
||||
}
|
||||
|
||||
public function get_uptime() {
|
||||
return shell_exec('uptime');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user