Updates latest data page functionality
parent
a288d311c0
commit
779d3e0bf6
|
@ -576,6 +576,74 @@ class Agent {
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the previous record for a specific metric
|
||||||
|
*
|
||||||
|
* @param int $host_id The host ID
|
||||||
|
* @param string $agent_type The type of agent (e.g., 'jvb', 'jicofo')
|
||||||
|
* @param string $metric_type The type of metric to retrieve
|
||||||
|
* @param string $current_timestamp Current record's timestamp to get data before this
|
||||||
|
* @return array|null Previous record data or null if not found
|
||||||
|
*/
|
||||||
|
public function getPreviousRecord($host_id, $agent_type, $metric_type, $current_timestamp) {
|
||||||
|
$sql = 'SELECT
|
||||||
|
jac.timestamp,
|
||||||
|
jac.response_content
|
||||||
|
FROM
|
||||||
|
jilo_agent_checks jac
|
||||||
|
JOIN
|
||||||
|
jilo_agents ja ON jac.agent_id = ja.id
|
||||||
|
JOIN
|
||||||
|
jilo_agent_types jat ON ja.agent_type_id = jat.id
|
||||||
|
JOIN
|
||||||
|
hosts h ON ja.host_id = h.id
|
||||||
|
WHERE
|
||||||
|
h.id = :host_id
|
||||||
|
AND jat.description = :agent_type
|
||||||
|
AND jac.status_code = 200
|
||||||
|
AND jac.timestamp < :current_timestamp
|
||||||
|
ORDER BY
|
||||||
|
jac.timestamp DESC
|
||||||
|
LIMIT 1';
|
||||||
|
|
||||||
|
$query = $this->db->prepare($sql);
|
||||||
|
$query->execute([
|
||||||
|
':host_id' => $host_id,
|
||||||
|
':agent_type' => $agent_type,
|
||||||
|
':current_timestamp' => $current_timestamp
|
||||||
|
]);
|
||||||
|
|
||||||
|
$result = $query->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$json_data = json_decode($result['response_content'], true);
|
||||||
|
if (json_last_error() === JSON_ERROR_NONE) {
|
||||||
|
$api_data = [];
|
||||||
|
if ($agent_type === 'jvb') {
|
||||||
|
$api_data = $json_data['jvb_api_data'] ?? [];
|
||||||
|
} elseif ($agent_type === 'jicofo') {
|
||||||
|
$api_data = $json_data['jicofo_api_data'] ?? [];
|
||||||
|
} elseif ($agent_type === 'jigasi') {
|
||||||
|
$api_data = $json_data['jigasi_api_data'] ?? [];
|
||||||
|
} elseif ($agent_type === 'prosody') {
|
||||||
|
$api_data = $json_data['prosody_api_data'] ?? [];
|
||||||
|
} elseif ($agent_type === 'nginx') {
|
||||||
|
$api_data = $json_data['nginx_api_data'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $this->getNestedValue($api_data, $metric_type);
|
||||||
|
if ($value !== null) {
|
||||||
|
return [
|
||||||
|
'value' => $value,
|
||||||
|
'timestamp' => $result['timestamp']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -10,9 +10,11 @@ $agent = $_REQUEST['agent'] ?? '';
|
||||||
require '../app/classes/settings.php';
|
require '../app/classes/settings.php';
|
||||||
require '../app/classes/agent.php';
|
require '../app/classes/agent.php';
|
||||||
require '../app/classes/conference.php';
|
require '../app/classes/conference.php';
|
||||||
|
require '../app/classes/host.php';
|
||||||
|
|
||||||
$settingsObject = new Settings();
|
$settingsObject = new Settings();
|
||||||
$agentObject = new Agent($dbWeb);
|
$agentObject = new Agent($dbWeb);
|
||||||
|
$hostObject = new Host($dbWeb);
|
||||||
|
|
||||||
// connect to Jilo database
|
// connect to Jilo database
|
||||||
$response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id);
|
$response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id);
|
||||||
|
@ -125,7 +127,6 @@ if ($response['db'] === null) {
|
||||||
'jibri_detector.available' => ['label' => 'Jibri idle'],
|
'jibri_detector.available' => ['label' => 'Jibri idle'],
|
||||||
'jibri.live_streaming_active' => ['label' => 'Jibri active streaming'],
|
'jibri.live_streaming_active' => ['label' => 'Jibri active streaming'],
|
||||||
'jibri.recording_active' => ['label' => 'Jibri active recording'],
|
'jibri.recording_active' => ['label' => 'Jibri active recording'],
|
||||||
|
|
||||||
],
|
],
|
||||||
'System stats' => [
|
'System stats' => [
|
||||||
'threads' => ['label' => 'Threads'],
|
'threads' => ['label' => 'Threads'],
|
||||||
|
@ -134,54 +135,74 @@ if ($response['db'] === null) {
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
// Get latest data for all the agents
|
// Get all hosts for this platform
|
||||||
$agents = ['jvb', 'jicofo', 'jibri', 'prosody', 'nginx'];
|
$hosts = $hostObject->getHostDetails($platform_id);
|
||||||
$widget['records'] = [];
|
$hostsData = [];
|
||||||
|
|
||||||
// Initialize records for each agent
|
// For each host, get its agents and their metrics
|
||||||
foreach ($agents as $agent) {
|
foreach ($hosts as $host) {
|
||||||
$record = [
|
$hostData = [
|
||||||
'table_headers' => strtoupper($agent),
|
'id' => $host['id'],
|
||||||
'metrics' => [],
|
'name' => $host['name'] ?: $host['address'],
|
||||||
'timestamp' => null
|
'address' => $host['address'],
|
||||||
|
'agents' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
// Fetch all metrics for this agent
|
// Get agents for this host
|
||||||
foreach ($metrics as $section => $section_metrics) {
|
$hostAgents = $agentObject->getAgentDetails($host['id']);
|
||||||
foreach ($section_metrics as $metric => $metricConfig) {
|
foreach ($hostAgents as $agent) {
|
||||||
$data = $agentObject->getLatestData($platform_id, $agent, $metric);
|
$agentData = [
|
||||||
if ($data !== null) {
|
'id' => $agent['id'],
|
||||||
$record['metrics'][$section][$metric] = [
|
'type' => $agent['agent_description'],
|
||||||
'value' => $data['value'],
|
'name' => strtoupper($agent['agent_description']),
|
||||||
'label' => $metricConfig['label'],
|
'metrics' => [],
|
||||||
'link' => isset($metricConfig['link']) ? $metricConfig['link'] : null
|
'timestamp' => null
|
||||||
];
|
];
|
||||||
// Use the most recent timestamp
|
|
||||||
if ($record['timestamp'] === null || strtotime($data['timestamp']) > strtotime($record['timestamp'])) {
|
// Fetch all metrics for this agent
|
||||||
$record['timestamp'] = $data['timestamp'];
|
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($record['metrics'])) {
|
if (!empty($hostData['agents'])) {
|
||||||
$widget['records'][] = $record;
|
$hostsData[] = $hostData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare the widget
|
// Load the template
|
||||||
$widget['full'] = false;
|
|
||||||
$widget['name'] = 'LatestData';
|
|
||||||
$widget['title'] = 'Latest data from Jilo Agents';
|
|
||||||
$widget['collapsible'] = false;
|
|
||||||
$widget['collapsed'] = false;
|
|
||||||
$widget['filter'] = false;
|
|
||||||
$widget['metrics'] = $metrics; // Pass metrics configuration to template
|
|
||||||
if (!empty($widget['records'])) {
|
|
||||||
$widget['full'] = true;
|
|
||||||
}
|
|
||||||
$widget['pagination'] = false;
|
|
||||||
|
|
||||||
include '../app/templates/latest-data.php';
|
include '../app/templates/latest-data.php';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1,53 +1,111 @@
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="card w-auto bg-light border-light card-body" style="flex-direction: row;"><?= $widget['title'] ?></div>
|
<div class="card w-auto bg-light border-light card-body" style="flex-direction: row;">Latest data from Jilo Agents</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="collapse show" id="collapse<?= htmlspecialchars($widget['name']) ?>">
|
<div class="collapse show">
|
||||||
<div class="mb-5">
|
<div class="mb-5">
|
||||||
<?php if ($widget['full'] === true) { ?>
|
<?php if (!empty($hostsData)) { ?>
|
||||||
<table class="table table-results table-striped table-hover table-bordered">
|
<?php foreach ($hostsData as $host) { ?>
|
||||||
<thead class="thead-dark">
|
<div class="card mb-4">
|
||||||
<tr>
|
<div class="card-header">
|
||||||
<th scope="col">Metric</th>
|
<h5 class="mb-0">
|
||||||
<?php foreach ($widget['records'] as $record) { ?>
|
<i class="fas fa-network-wired me-2"></i>
|
||||||
<th scope="col">
|
<?= htmlspecialchars($host['name']) ?>
|
||||||
<?= htmlspecialchars($record['table_headers']) ?>
|
<small class="text-muted">(<?= htmlspecialchars($host['address']) ?>)</small>
|
||||||
<?php if ($record['timestamp']) { ?>
|
</h5>
|
||||||
<br>
|
</div>
|
||||||
<small class="text-muted">as of <?= date('Y-m-d H:i:s', strtotime($record['timestamp'])) ?></small>
|
<div class="card-body">
|
||||||
<?php } ?>
|
<?php foreach ($host['agents'] as $agent) { ?>
|
||||||
</th>
|
<div class="mb-4">
|
||||||
<?php } ?>
|
<h6 class="border-bottom pb-2">
|
||||||
</tr>
|
<i class="fas fa-robot me-2"></i>
|
||||||
</thead>
|
<?= htmlspecialchars($agent['name']) ?> agent
|
||||||
<tbody>
|
</h6>
|
||||||
<?php foreach ($widget['metrics'] as $section => $section_metrics) { ?>
|
<table class="table table-results table-striped table-hover table-bordered">
|
||||||
<tr class="table-secondary">
|
<thead class="align-top">
|
||||||
<th colspan="<?= count($widget['records']) + 1 ?>"><?= htmlspecialchars($section) ?></th>
|
<tr>
|
||||||
</tr>
|
<th>Metric</th>
|
||||||
<?php foreach ($section_metrics as $metric => $metricConfig) { ?>
|
<th>
|
||||||
<tr>
|
Latest value
|
||||||
<td><?= htmlspecialchars($metricConfig['label']) ?></td>
|
<br>
|
||||||
<?php foreach ($widget['records'] as $record) { ?>
|
<small class="text-muted">
|
||||||
<td>
|
<?= date('d M Y H:i:s', strtotime($agent['timestamp'])) ?>
|
||||||
<?php if (isset($record['metrics'][$section][$metric])) {
|
</small>
|
||||||
$metric_data = $record['metrics'][$section][$metric];
|
</th>
|
||||||
if ($metric_data['link']) { ?>
|
<th>
|
||||||
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=<?= htmlspecialchars($metric_data['link']) ?>&from_time=<?= htmlspecialchars($record['timestamp']) ?>&until_time=<?= htmlspecialchars($record['timestamp']) ?>"><?= htmlspecialchars($metric_data['value']) ?></a>
|
Previous value
|
||||||
<?php } else { ?>
|
<?php
|
||||||
<?= htmlspecialchars($metric_data['value']) ?>
|
// Find first metric with previous data to get timestamp
|
||||||
<?php }
|
$prevTimestamp = null;
|
||||||
} else { ?>
|
foreach ($metrics as $m_section => $m_metrics) {
|
||||||
<span class="text-muted">No data</span>
|
foreach ($m_metrics as $m_metric => $m_config) {
|
||||||
<?php } ?>
|
if (isset($agent['metrics'][$m_section][$m_metric]['previous'])) {
|
||||||
</td>
|
$prevTimestamp = $agent['metrics'][$m_section][$m_metric]['previous']['timestamp'];
|
||||||
<?php } ?>
|
break 2;
|
||||||
</tr>
|
}
|
||||||
<?php } ?>
|
}
|
||||||
<?php } ?>
|
}
|
||||||
</tbody>
|
if ($prevTimestamp) { ?>
|
||||||
</table>
|
<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 { ?>
|
<?php } else { ?>
|
||||||
<div class="alert alert-info m-3" role="alert">
|
<div class="alert alert-info m-3" role="alert">
|
||||||
No data available from any agents. Please check agent configuration and connectivity.
|
No data available from any agents. Please check agent configuration and connectivity.
|
||||||
|
@ -55,4 +113,4 @@
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /widget "<?= htmlspecialchars($widget['name']) ?>" -->
|
<!-- /latest data -->
|
||||||
|
|
Loading…
Reference in New Issue