Adds latest data metrics page
parent
da4a35d506
commit
5986993e45
|
@ -385,8 +385,59 @@ class Agent {
|
||||||
* @return mixed The latest stored data.
|
* @return mixed The latest stored data.
|
||||||
*/
|
*/
|
||||||
public function getLatestData($platform_id, $agent_type, $metric_type) {
|
public function getLatestData($platform_id, $agent_type, $metric_type) {
|
||||||
// TODO
|
$sql = 'SELECT
|
||||||
// retrieves data already stored in db from another function (or the jilo-server to-be)
|
jac.timestamp,
|
||||||
|
jac.response_content,
|
||||||
|
jac.agent_id,
|
||||||
|
jat.description
|
||||||
|
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
|
||||||
|
WHERE
|
||||||
|
ja.platform_id = :platform_id
|
||||||
|
AND jat.description = :agent_type
|
||||||
|
AND jac.status_code = 200
|
||||||
|
ORDER BY
|
||||||
|
jac.timestamp DESC
|
||||||
|
LIMIT 1';
|
||||||
|
|
||||||
|
$query = $this->db->prepare($sql);
|
||||||
|
$query->execute([
|
||||||
|
':platform_id' => $platform_id,
|
||||||
|
':agent_type' => $agent_type
|
||||||
|
]);
|
||||||
|
|
||||||
|
$result = $query->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
// Parse the JSON response content
|
||||||
|
$data = json_decode($result['response_content'], true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the specific metric value from the response based on agent type
|
||||||
|
if ($agent_type === 'jvb') {
|
||||||
|
if (isset($data['jvb_api_data'][$metric_type])) {
|
||||||
|
return [
|
||||||
|
'value' => $data['jvb_api_data'][$metric_type],
|
||||||
|
'timestamp' => $result['timestamp']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} elseif ($agent_type === 'jicofo') {
|
||||||
|
if (isset($data['jicofo_api_data'][$metric_type])) {
|
||||||
|
return [
|
||||||
|
'value' => $data['jicofo_api_data'][$metric_type],
|
||||||
|
'timestamp' => $result['timestamp']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ switch ($item) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'latest':
|
case 'latest':
|
||||||
|
// Get latest data for both JVB and Jicofo agents
|
||||||
$latestJvbConferences = $agentObject->getLatestData($platform_id, 'jvb', 'conferences');
|
$latestJvbConferences = $agentObject->getLatestData($platform_id, 'jvb', 'conferences');
|
||||||
$latestJvbParticipants = $agentObject->getLatestData($platform_id, 'jvb', 'participants');
|
$latestJvbParticipants = $agentObject->getLatestData($platform_id, 'jvb', 'participants');
|
||||||
$latestJicofoConferences = $agentObject->getLatestData($platform_id, 'jicofo', 'conferences');
|
$latestJicofoConferences = $agentObject->getLatestData($platform_id, 'jicofo', 'conferences');
|
||||||
|
@ -71,6 +72,28 @@ switch ($item) {
|
||||||
|
|
||||||
$widget['records'] = array();
|
$widget['records'] = array();
|
||||||
|
|
||||||
|
// Format data for JVB metrics
|
||||||
|
if ($latestJvbConferences !== null || $latestJvbParticipants !== null) {
|
||||||
|
$widget['records'][] = [
|
||||||
|
'table_headers' => 'JVB',
|
||||||
|
'conferences' => $latestJvbConferences ? $latestJvbConferences['value'] : null,
|
||||||
|
'participants' => $latestJvbParticipants ? $latestJvbParticipants['value'] : null,
|
||||||
|
'from_time' => $latestJvbConferences ? $latestJvbConferences['timestamp'] : ($latestJvbParticipants ? $latestJvbParticipants['timestamp'] : null),
|
||||||
|
'until_time' => $latestJvbConferences ? $latestJvbConferences['timestamp'] : ($latestJvbParticipants ? $latestJvbParticipants['timestamp'] : null)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format data for Jicofo metrics
|
||||||
|
if ($latestJicofoConferences !== null || $latestJicofoParticipants !== null) {
|
||||||
|
$widget['records'][] = [
|
||||||
|
'table_headers' => 'Jicofo',
|
||||||
|
'conferences' => $latestJicofoConferences ? $latestJicofoConferences['value'] : null,
|
||||||
|
'participants' => $latestJicofoParticipants ? $latestJicofoParticipants['value'] : null,
|
||||||
|
'from_time' => $latestJicofoConferences ? $latestJicofoConferences['timestamp'] : ($latestJicofoParticipants ? $latestJicofoParticipants['timestamp'] : null),
|
||||||
|
'until_time' => $latestJicofoConferences ? $latestJicofoConferences['timestamp'] : ($latestJicofoParticipants ? $latestJicofoParticipants['timestamp'] : null)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
// prepare the widget
|
// prepare the widget
|
||||||
$widget['full'] = false;
|
$widget['full'] = false;
|
||||||
$widget['name'] = 'LatestData';
|
$widget['name'] = 'LatestData';
|
||||||
|
@ -78,10 +101,10 @@ switch ($item) {
|
||||||
$widget['collapsible'] = false;
|
$widget['collapsible'] = false;
|
||||||
$widget['collapsed'] = false;
|
$widget['collapsed'] = false;
|
||||||
$widget['filter'] = false;
|
$widget['filter'] = false;
|
||||||
if (!empty($latestJvbConferences) && !empty($latestJvbParticipants) && !empty($latestJicofoConferences) && !empty($latestJicofoParticipants)) {
|
if (!empty($widget['records'])) {
|
||||||
$widget['full'] = true;
|
$widget['full'] = true;
|
||||||
}
|
}
|
||||||
$widget['pagination'] = true;
|
$widget['pagination'] = false;
|
||||||
|
|
||||||
include '../app/templates/latest-data.php';
|
include '../app/templates/latest-data.php';
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
|
|
||||||
<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;"><?= $widget['title'] ?></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="collapse show" id="collapse<?= htmlspecialchars($widget['name']) ?>">
|
<div class="collapse show" id="collapse<?= htmlspecialchars($widget['name']) ?>">
|
||||||
<div class="mb-5">
|
<div class="mb-5">
|
||||||
<hr /><p class="m-3">NB: This functionality is still under development. The data is just an example.</p><hr /><!-- FIXME remove when implemented -->
|
|
||||||
<?php if ($widget['full'] === true) { ?>
|
<?php if ($widget['full'] === true) { ?>
|
||||||
<table class="table table-results table-striped table-hover table-bordered">
|
<table class="table table-results table-striped table-hover table-bordered">
|
||||||
<thead class="thead-dark">
|
<thead class="thead-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col"></th>
|
<th scope="col">Metric</th>
|
||||||
<?php foreach ($widget['records'] as $record) { ?>
|
<?php foreach ($widget['records'] as $record) { ?>
|
||||||
<th scope="col"><?= htmlspecialchars($record['table_headers']) ?></th>
|
<th scope="col"><?= htmlspecialchars($record['table_headers']) ?></th>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
@ -18,27 +17,47 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>conferences</td>
|
<td>Conferences</td>
|
||||||
<?php foreach ($widget['records'] as $record) { ?>
|
<?php foreach ($widget['records'] as $record) { ?>
|
||||||
<td><?php if (!empty($record['conferences'])) { ?>
|
<td>
|
||||||
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=conferences&from_time=<?= htmlspecialchars($record['from_time']) ?>&until_time=<?= htmlspecialchars($record['until_time']) ?>"><?= htmlspecialchars($record['conferences']) ?></a> <?php } else { ?>
|
<?php if (isset($record['conferences'])) { ?>
|
||||||
0<?php } ?>
|
<?php if ($record['conferences'] !== null) { ?>
|
||||||
|
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=conferences&from_time=<?= htmlspecialchars($record['from_time']) ?>&until_time=<?= htmlspecialchars($record['until_time']) ?>"><?= htmlspecialchars($record['conferences']) ?></a>
|
||||||
|
<br>
|
||||||
|
<small class="text-muted"><?= date('Y-m-d H:i:s', strtotime($record['from_time'])) ?></small>
|
||||||
|
<?php } else { ?>
|
||||||
|
<span class="text-muted">0</span>
|
||||||
|
<?php } ?>
|
||||||
|
<?php } else { ?>
|
||||||
|
<span class="text-muted">No data</span>
|
||||||
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>participants</td>
|
<td>Participants</td>
|
||||||
<?php foreach ($widget['records'] as $record) { ?>
|
<?php foreach ($widget['records'] as $record) { ?>
|
||||||
<td><?php if (!empty($record['participants'])) { ?>
|
<td>
|
||||||
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=participants&from_time=<?= htmlspecialchars($record['from_time']) ?>&until_time=<?= htmlspecialchars($record['until_time']) ?>"><?= htmlspecialchars($record['participants']) ?></a> <?php } else { ?>
|
<?php if (isset($record['participants'])) { ?>
|
||||||
0<?php } ?>
|
<?php if ($record['participants'] !== null) { ?>
|
||||||
|
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=participants&from_time=<?= htmlspecialchars($record['from_time']) ?>&until_time=<?= htmlspecialchars($record['until_time']) ?>"><?= htmlspecialchars($record['participants']) ?></a>
|
||||||
|
<br>
|
||||||
|
<small class="text-muted"><?= date('Y-m-d H:i:s', strtotime($record['from_time'])) ?></small>
|
||||||
|
<?php } else { ?>
|
||||||
|
<span class="text-muted">0</span>
|
||||||
|
<?php } ?>
|
||||||
|
<?php } else { ?>
|
||||||
|
<span class="text-muted">No data</span>
|
||||||
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<p class="m-3">No records found.</p>
|
<div class="alert alert-info m-3" role="alert">
|
||||||
|
No data available from any agents. Please check agent configuration and connectivity.
|
||||||
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue