Moves latest data to separate page

main
Yasen Pramatarov 2025-01-28 21:18:20 +02:00
parent 20a39f5c29
commit e50ac96b50
4 changed files with 232 additions and 6 deletions

View File

@ -0,0 +1,109 @@
<?php
require '../app/classes/agent.php';
require '../app/classes/host.php';
$agentObject = new Agent($dbWeb);
$hostObject = new Host($dbWeb);
// Define metrics to display
$metrics = [
'Basic stats' => [
'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';
?>

View File

@ -0,0 +1,117 @@
<!-- latest data -->
<div class="container-fluid mt-2">
<div class="row mb-4">
<div class="col-12 mb-4">
<h2 class="mb-0">Latest data from Jilo Agents</h2>
<small>gathered for platform <?= htmlspecialchars($platform_id) ?> (<?= htmlspecialchars($platformDetails[0]['name']) ?>)</small>
</div>
</div>
<div class="row">
<div class="mb-4">
<?php if (!empty($hostsData)) { ?>
<?php foreach ($hostsData as $host) { ?>
<div class="card mb-4">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-network-wired me-2 text-secondary"></i>
<?= htmlspecialchars($host['name']) ?><small class="text-muted"> (<?= htmlspecialchars($host['address']) ?>)</small>
</h5>
</div>
<div class="card-body">
<?php foreach ($host['agents'] as $agent) { ?>
<div class="mb-4">
<h6 class="border-bottom pb-2">
<i class="fas fa-robot me-2 text-secondary"></i>
<?= htmlspecialchars($agent['name']) ?> agent
</h6>
<table class="table table-results table-striped table-hover table-bordered">
<thead class="align-top">
<tr>
<th>Metric</th>
<th>
Latest value
<br>
<small class="text-muted"><?= date('d M Y H:i:s', strtotime($agent['timestamp'])) ?></small>
</th>
<th>
Previous value
<?php
// Find first metric with previous data to get timestamp
$prevTimestamp = null;
foreach ($metrics as $m_section => $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) { ?>
<br>
<small class="text-muted"><?= date('d M Y H:i:s', strtotime($prevTimestamp)) ?></small>
<?php } ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($metrics as $section => $section_metrics) { ?>
<?php
// Check if this section has any data for this agent
$hasData = false;
foreach ($section_metrics as $metric => $metricConfig) {
if (isset($agent['metrics'][$section][$metric])) {
$hasData = true;
break;
}
}
if (!$hasData) continue;
?>
<tr class="table-secondary">
<th colspan="3"><?= htmlspecialchars($section) ?></th>
</tr>
<?php foreach ($section_metrics as $metric => $metricConfig) { ?>
<?php if (isset($agent['metrics'][$section][$metric])) {
$metric_data = $agent['metrics'][$section][$metric];
?>
<tr>
<td><?= htmlspecialchars($metricConfig['label']) ?></td>
<td>
<?php if ($metric_data['link']) { ?>
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=<?= htmlspecialchars($metric_data['link']) ?>&from_time=<?= htmlspecialchars($metric_data['latest']['timestamp']) ?>&until_time=<?= htmlspecialchars($metric_data['latest']['timestamp']) ?>"><?= htmlspecialchars($metric_data['latest']['value']) ?></a>
<?php } else { ?>
<?= htmlspecialchars($metric_data['latest']['value']) ?>
<?php } ?>
</td>
<td>
<?php if ($metric_data['previous']) { ?>
<?php if ($metric_data['link']) { ?>
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=<?= htmlspecialchars($metric_data['link']) ?>&from_time=<?= htmlspecialchars($metric_data['previous']['timestamp']) ?>&until_time=<?= htmlspecialchars($metric_data['previous']['timestamp']) ?>"><?= htmlspecialchars($metric_data['previous']['value']) ?></a>
<?php } else { ?>
<?= htmlspecialchars($metric_data['previous']['value']) ?>
<?php } ?>
<?php } else { ?>
<span class="text-muted">No previous data</span>
<?php } ?>
</td>
</tr>
<?php } ?>
<?php } ?>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<?php } else { ?>
<div class="alert alert-info m-3" role="alert">
No data available from any agents. Please check agent configuration and connectivity.
</div>
<?php } ?>
</div>
</div>
</div>
<!-- /latest data -->

View File

@ -39,13 +39,13 @@ $timeNow = new DateTime('now', new DateTimeZone($userTimezone));
<li class="list-group-item bg-light" style="border: none;"><p class="text-end mb-0"><small>live data</small></p></li> <li class="list-group-item bg-light" style="border: none;"><p class="text-end mb-0"><small>live data</small></p></li>
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=data&item=graphs"> <a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=graphs">
<li class="list-group-item<?php if ($page === 'data' && $item === 'graphs') echo ' list-group-item-secondary'; else echo ' list-group-item-action'; ?>"> <li class="list-group-item<?php if ($page === 'graphs') echo ' list-group-item-secondary'; else echo ' list-group-item-action'; ?>">
<i class="fas fa-chart-bar" data-toggle="tooltip" data-placement="right" data-offset="30.0" title="combined graphs"></i>combined graphs <i class="fas fa-chart-bar" data-toggle="tooltip" data-placement="right" data-offset="30.0" title="combined graphs"></i>combined graphs
</li> </li>
</a> </a>
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=data&item=latest"> <a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=latest">
<li class="list-group-item<?php if ($page === 'data' && $item === 'latest') echo ' list-group-item-secondary'; else echo ' list-group-item-action'; ?>"> <li class="list-group-item<?php if ($page === 'latest') echo ' list-group-item-secondary'; else echo ' list-group-item-action'; ?>">
<i class="fas fa-list" data-toggle="tooltip" data-placement="right" data-offset="30.0" title="latest data"></i>latest data <i class="fas fa-list" data-toggle="tooltip" data-placement="right" data-offset="30.0" title="latest data"></i>latest data
</li> </li>
</a> </a>

View File

@ -40,9 +40,9 @@ $allowed_urls = [
'participants', 'participants',
'components', 'components',
'data', 'graphs',
'latest', 'latest',
'livejs',
'agents', 'agents',