From e50ac96b5086e8c1d6281288d3ec13278481cb29 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Tue, 28 Jan 2025 21:18:20 +0200 Subject: [PATCH] Moves latest data to separate page --- app/pages/latest.php | 109 ++++++++++++++++++++++++++++++ app/templates/latest.php | 117 +++++++++++++++++++++++++++++++++ app/templates/page-sidebar.php | 8 +-- public_html/index.php | 4 +- 4 files changed, 232 insertions(+), 6 deletions(-) create mode 100644 app/pages/latest.php create mode 100644 app/templates/latest.php diff --git a/app/pages/latest.php b/app/pages/latest.php new file mode 100644 index 0000000..3ddbf67 --- /dev/null +++ b/app/pages/latest.php @@ -0,0 +1,109 @@ + [ + 'conferences' => ['label' => 'Current conferences', 'link' => 'conferences'], + 'participants' => ['label' => 'Current participants', 'link' => 'participants'], + 'total_conferences_created' => ['label' => 'Total conferences created'], + 'total_participants' => ['label' => 'Total participants'] + ], + 'Bridge stats' => [ + 'bridge_selector.bridge_count' => ['label' => 'Bridge count'], + 'bridge_selector.operational_bridge_count' => ['label' => 'Operational bridges'], + 'bridge_selector.in_shutdown_bridge_count' => ['label' => 'Bridges in shutdown'] + ], + 'Jibri stats' => [ + 'jibri_detector.count' => ['label' => 'Jibri count'], + 'jibri_detector.available' => ['label' => 'Jibri idle'], + 'jibri.live_streaming_active' => ['label' => 'Jibri active streaming'], + 'jibri.recording_active' => ['label' => 'Jibri active recording'], + ], + 'System stats' => [ + 'threads' => ['label' => 'Threads'], + 'stress_level' => ['label' => 'Stress level'], + 'version' => ['label' => 'Version'] + ] +]; + +// Get all hosts for this platform +$hosts = $hostObject->getHostDetails($platform_id); +$hostsData = []; + +// For each host, get its agents and their metrics +foreach ($hosts as $host) { + $hostData = [ + 'id' => $host['id'], + 'name' => $host['name'] ?: $host['address'], + 'address' => $host['address'], + 'agents' => [] + ]; + + // Get agents for this host + $hostAgents = $agentObject->getAgentDetails($host['id']); + foreach ($hostAgents as $agent) { + $agentData = [ + 'id' => $agent['id'], + 'type' => $agent['agent_description'], + 'name' => strtoupper($agent['agent_description']), + 'metrics' => [], + 'timestamp' => null + ]; + + // Fetch all metrics for this agent + foreach ($metrics as $section => $section_metrics) { + foreach ($section_metrics as $metric => $metricConfig) { + // Get latest data + $latestData = $agentObject->getLatestData($host['id'], $agent['agent_description'], $metric); + + if ($latestData !== null) { + // Get the previous record + $previousData = $agentObject->getPreviousRecord( + $host['id'], + $agent['agent_description'], + $metric, + $latestData['timestamp'] + ); + + $agentData['metrics'][$section][$metric] = [ + 'latest' => [ + 'value' => $latestData['value'], + 'timestamp' => $latestData['timestamp'] + ], + 'previous' => $previousData, + 'label' => $metricConfig['label'], + 'link' => isset($metricConfig['link']) ? $metricConfig['link'] : null + ]; + + // Use the most recent timestamp for the agent + if ($agentData['timestamp'] === null || strtotime($latestData['timestamp']) > strtotime($agentData['timestamp'])) { + $agentData['timestamp'] = $latestData['timestamp']; + } + } + } + } + + if (!empty($agentData['metrics'])) { + $hostData['agents'][] = $agentData; + } + } + + if (!empty($hostData['agents'])) { + $hostsData[] = $hostData; + } +} + +// Get any new messages +include '../app/includes/messages.php'; +include '../app/includes/messages-show.php'; + +// Load the template +include '../app/templates/latest.php'; + +?> diff --git a/app/templates/latest.php b/app/templates/latest.php new file mode 100644 index 0000000..a316176 --- /dev/null +++ b/app/templates/latest.php @@ -0,0 +1,117 @@ + + +
+
+
+

Latest data from Jilo Agents

+ gathered for platform () +
+
+ +
+
+ + +
+
+
+ + () +
+
+
+ +
+
+ + agent +
+ + + + + + + + + + $section_metrics) { ?> + $metricConfig) { + if (isset($agent['metrics'][$section][$metric])) { + $hasData = true; + break; + } +} +if (!$hasData) continue; +?> + + + + $metricConfig) { ?> + + + + + + + + + + +
Metric + Latest value +
+ +
+ Previous value + $m_metrics) { + foreach ($m_metrics as $m_metric => $m_config) { + if (isset($agent['metrics'][$m_section][$m_metric]['previous'])) { + $prevTimestamp = $agent['metrics'][$m_section][$m_metric]['previous']['timestamp']; + break 2; + } + } +} +if ($prevTimestamp) { ?> +
+ + +
+ + + + + + + + + + + + + + No previous data + +
+
+ +
+
+ + + + +
+
+
+ diff --git a/app/templates/page-sidebar.php b/app/templates/page-sidebar.php index 207052e..bbe9e63 100644 --- a/app/templates/page-sidebar.php +++ b/app/templates/page-sidebar.php @@ -39,13 +39,13 @@ $timeNow = new DateTime('now', new DateTimeZone($userTimezone));
  • live data

  • - -
  • + +
  • combined graphs
  • - -
  • + +
  • latest data
  • diff --git a/public_html/index.php b/public_html/index.php index 96d6fd2..4f3418c 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -40,9 +40,9 @@ $allowed_urls = [ 'participants', 'components', - 'data', - + 'graphs', 'latest', + 'livejs', 'agents',