diff --git a/Glances/Glances.php b/Glances/Glances.php index 3dd5c1b201..e963ba71ac 100644 --- a/Glances/Glances.php +++ b/Glances/Glances.php @@ -2,6 +2,105 @@ namespace App\SupportedApps\Glances; -class Glances extends \App\SupportedApps +class Glances extends \App\SupportedApps implements \App\EnhancedApps { + public $config; + + public function __construct() + { + } + + public function test() + { + $test = parent::appTest($this->url("status")); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $details = []; + + if (isset($this->config->availablestats) && is_array($this->config->availablestats)) { + $details = ["visiblestats" => []]; + foreach ($this->config->availablestats as $stat) { + $newstat = new \stdClass(); + $availableStats = self::getAvailableStats(); + + if (isset($availableStats[$stat])) { + $newstat->title = $availableStats[$stat]; + + // Fetch CpuTotal + if ($stat === "CpuTotal") { + $Response = parent::execute($this->url("cpu/total")); + $result = json_decode($Response->getBody()); + if (isset($result->total)) { + $newstat->value = $result->total; + } else { + $newstat->value = null; // or some default value + } + } + + // Fetch MemTotal + if ($stat === "MemTotal") { + $Response = parent::execute($this->url("mem/total")); + $result = json_decode($Response->getBody()); + if (isset($result->total)) { + $newstat->value = $this->convertBytesToGigabytes($result->total); + } else { + $newstat->value = null; // or some default value + } + } + + // Fetch MemAvail + if ($stat === "MemAvail") { + $Response = parent::execute($this->url("mem/available")); + $result = json_decode($Response->getBody()); + if (isset($result->available)) { + $newstat->value = $this->convertBytesToGigabytes($result->available); + } else { + $newstat->value = null; // or some default value + } + } + + // Fetch MemAvail + if ($stat === "MemUsage") { + $Response = parent::execute($this->url("mem/used")); + $result = json_decode($Response->getBody()); + if (isset($result->used)) { + $newstat->value = $this->convertBytesToGigabytes($result->used); + } else { + $newstat->value = null; // or some default value + } + } + + $details["visiblestats"][] = $newstat; + } + } + } + + return parent::getLiveStats($status, $details); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . "api/4/" . $endpoint; + return $api_url; + } + + public static function getAvailableStats() + { + return [ + "CpuTotal" => "CpuTotal", + "MemTotal" => "MemTotal", + "MemAvail" => "MemAvail", + "MemUsage" => "MemUsage", + ]; + } + + private function convertBytesToGigabytes($bytes) + { + $gigabytes = $bytes / (1024 ** 3); // Converts bytes to gigabytes + return round($gigabytes, 2) . ' GB'; // Rounds to 4 significant digits + } } diff --git a/Glances/app.json b/Glances/app.json index b5916532a1..ac87d08170 100644 --- a/Glances/app.json +++ b/Glances/app.json @@ -4,7 +4,7 @@ "website": "https://nicolargo.github.io/glances", "license": "GNU Lesser General Public License v3.0 only", "description": "Glances is a cross-platform monitoring tool which aims to present a large amount of monitoring information through a curses or Web based interface.", - "enhanced": false, + "enhanced": true, "tile_background": "dark", "icon": "glances.png" } diff --git a/Glances/config.blade.php b/Glances/config.blade.php new file mode 100644 index 0000000000..e6d527bf2e --- /dev/null +++ b/Glances/config.blade.php @@ -0,0 +1,14 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
+
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! Form::select('config[availablestats][]', App\SupportedApps\Glances\Glances::getAvailableStats(), isset($item) ? $item->getConfig()->availablestats ?? null : null, ['multiple' => 'multiple']) !!} +
+
+ +
+
diff --git a/Glances/livestats.blade.php b/Glances/livestats.blade.php new file mode 100644 index 0000000000..cb9431aef3 --- /dev/null +++ b/Glances/livestats.blade.php @@ -0,0 +1,8 @@ +