Makes latest data configurable
parent
5986993e45
commit
d3f65939cd
|
@ -375,6 +375,28 @@ class Agent {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a value from a nested array using dot notation
|
||||||
|
* e.g. "bridge_selector.bridge_count" will get $array['bridge_selector']['bridge_count']
|
||||||
|
*
|
||||||
|
* @param array $array The array to search in
|
||||||
|
* @param string $path The path in dot notation
|
||||||
|
* @return mixed|null The value if found, null otherwise
|
||||||
|
*/
|
||||||
|
private function getNestedValue($array, $path) {
|
||||||
|
$keys = explode('.', $path);
|
||||||
|
$value = $array;
|
||||||
|
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if (!isset($value[$key])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$value = $value[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the latest stored data for a specific platform, agent type, and metric type.
|
* Retrieves the latest stored data for a specific platform, agent type, and metric type.
|
||||||
*
|
*
|
||||||
|
@ -385,22 +407,22 @@ 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) {
|
||||||
$sql = 'SELECT
|
$sql = 'SELECT
|
||||||
jac.timestamp,
|
jac.timestamp,
|
||||||
jac.response_content,
|
jac.response_content,
|
||||||
jac.agent_id,
|
jac.agent_id,
|
||||||
jat.description
|
jat.description
|
||||||
FROM
|
FROM
|
||||||
jilo_agent_checks jac
|
jilo_agent_checks jac
|
||||||
JOIN
|
JOIN
|
||||||
jilo_agents ja ON jac.agent_id = ja.id
|
jilo_agents ja ON jac.agent_id = ja.id
|
||||||
JOIN
|
JOIN
|
||||||
jilo_agent_types jat ON ja.agent_type_id = jat.id
|
jilo_agent_types jat ON ja.agent_type_id = jat.id
|
||||||
WHERE
|
WHERE
|
||||||
ja.platform_id = :platform_id
|
ja.platform_id = :platform_id
|
||||||
AND jat.description = :agent_type
|
AND jat.description = :agent_type
|
||||||
AND jac.status_code = 200
|
AND jac.status_code = 200
|
||||||
ORDER BY
|
ORDER BY
|
||||||
jac.timestamp DESC
|
jac.timestamp DESC
|
||||||
LIMIT 1';
|
LIMIT 1';
|
||||||
|
|
||||||
|
@ -411,32 +433,64 @@ class Agent {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = $query->fetch(PDO::FETCH_ASSOC);
|
$result = $query->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
// Parse the JSON response content
|
// Parse the JSON response content
|
||||||
$data = json_decode($result['response_content'], true);
|
$data = json_decode($result['response_content'], true);
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the specific metric value from the response based on agent type
|
// Extract the specific metric value from the response based on agent type
|
||||||
if ($agent_type === 'jvb') {
|
if ($agent_type === 'jvb') {
|
||||||
if (isset($data['jvb_api_data'][$metric_type])) {
|
$value = $this->getNestedValue($data['jvb_api_data'], $metric_type);
|
||||||
|
if ($value !== null) {
|
||||||
return [
|
return [
|
||||||
'value' => $data['jvb_api_data'][$metric_type],
|
'value' => $value,
|
||||||
'timestamp' => $result['timestamp']
|
'timestamp' => $result['timestamp']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($agent_type === 'jicofo') {
|
} elseif ($agent_type === 'jicofo') {
|
||||||
if (isset($data['jicofo_api_data'][$metric_type])) {
|
$value = $this->getNestedValue($data['jicofo_api_data'], $metric_type);
|
||||||
|
if ($value !== null) {
|
||||||
return [
|
return [
|
||||||
'value' => $data['jicofo_api_data'][$metric_type],
|
'value' => $value,
|
||||||
|
'timestamp' => $result['timestamp']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($agent_type === 'jigasi') {
|
||||||
|
$value = $this->getNestedValue($data['jigasi_api_data'], $metric_type);
|
||||||
|
if ($value !== null) {
|
||||||
|
return [
|
||||||
|
'value' => $value,
|
||||||
|
'timestamp' => $result['timestamp']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($agent_type === 'prosody') {
|
||||||
|
$value = $this->getNestedValue($data['prosody_api_data'], $metric_type);
|
||||||
|
if ($value !== null) {
|
||||||
|
return [
|
||||||
|
'value' => $value,
|
||||||
|
'timestamp' => $result['timestamp']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($agent_type === 'nginx') {
|
||||||
|
$value = $this->getNestedValue($data['nginx_api_data'], $metric_type);
|
||||||
|
if ($value !== null) {
|
||||||
|
return [
|
||||||
|
'value' => $value,
|
||||||
'timestamp' => $result['timestamp']
|
'timestamp' => $result['timestamp']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,34 +64,59 @@ switch ($item) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'latest':
|
case 'latest':
|
||||||
// Get latest data for both JVB and Jicofo agents
|
// Define metrics to display
|
||||||
$latestJvbConferences = $agentObject->getLatestData($platform_id, 'jvb', 'conferences');
|
$metrics = [
|
||||||
$latestJvbParticipants = $agentObject->getLatestData($platform_id, 'jvb', 'participants');
|
'Basic stats' => [
|
||||||
$latestJicofoConferences = $agentObject->getLatestData($platform_id, 'jicofo', 'conferences');
|
'conferences' => ['label' => 'Current conferences', 'link' => 'conferences'],
|
||||||
$latestJicofoParticipants = $agentObject->getLatestData($platform_id, 'jicofo', 'participants');
|
'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']
|
||||||
|
],
|
||||||
|
'System stats' => [
|
||||||
|
'threads' => ['label' => 'Threads'],
|
||||||
|
'jibri_detector.count' => ['label' => 'Jibri count'],
|
||||||
|
'stress_level' => ['label' => 'Stress level']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
$widget['records'] = array();
|
// Get latest data for all the agents
|
||||||
|
$agents = ['jvb', 'jicofo', 'jibri', 'prosody', 'nginx'];
|
||||||
|
$widget['records'] = [];
|
||||||
|
|
||||||
// Format data for JVB metrics
|
// Initialize records for each agent
|
||||||
if ($latestJvbConferences !== null || $latestJvbParticipants !== null) {
|
foreach ($agents as $agent) {
|
||||||
$widget['records'][] = [
|
$record = [
|
||||||
'table_headers' => 'JVB',
|
'table_headers' => strtoupper($agent),
|
||||||
'conferences' => $latestJvbConferences ? $latestJvbConferences['value'] : null,
|
'metrics' => [],
|
||||||
'participants' => $latestJvbParticipants ? $latestJvbParticipants['value'] : null,
|
'timestamp' => null
|
||||||
'from_time' => $latestJvbConferences ? $latestJvbConferences['timestamp'] : ($latestJvbParticipants ? $latestJvbParticipants['timestamp'] : null),
|
|
||||||
'until_time' => $latestJvbConferences ? $latestJvbConferences['timestamp'] : ($latestJvbParticipants ? $latestJvbParticipants['timestamp'] : null)
|
|
||||||
];
|
];
|
||||||
}
|
|
||||||
|
|
||||||
// Format data for Jicofo metrics
|
// Fetch all metrics for this agent
|
||||||
if ($latestJicofoConferences !== null || $latestJicofoParticipants !== null) {
|
foreach ($metrics as $section => $section_metrics) {
|
||||||
$widget['records'][] = [
|
foreach ($section_metrics as $metric => $config) {
|
||||||
'table_headers' => 'Jicofo',
|
$data = $agentObject->getLatestData($platform_id, $agent, $metric);
|
||||||
'conferences' => $latestJicofoConferences ? $latestJicofoConferences['value'] : null,
|
if ($data !== null) {
|
||||||
'participants' => $latestJicofoParticipants ? $latestJicofoParticipants['value'] : null,
|
$record['metrics'][$section][$metric] = [
|
||||||
'from_time' => $latestJicofoConferences ? $latestJicofoConferences['timestamp'] : ($latestJicofoParticipants ? $latestJicofoParticipants['timestamp'] : null),
|
'value' => $data['value'],
|
||||||
'until_time' => $latestJicofoConferences ? $latestJicofoConferences['timestamp'] : ($latestJicofoParticipants ? $latestJicofoParticipants['timestamp'] : null)
|
'label' => $config['label'],
|
||||||
];
|
'link' => isset($config['link']) ? $config['link'] : null
|
||||||
|
];
|
||||||
|
// Use the most recent timestamp
|
||||||
|
if ($record['timestamp'] === null || strtotime($data['timestamp']) > strtotime($record['timestamp'])) {
|
||||||
|
$record['timestamp'] = $data['timestamp'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($record['metrics'])) {
|
||||||
|
$widget['records'][] = $record;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare the widget
|
// prepare the widget
|
||||||
|
@ -101,6 +126,7 @@ switch ($item) {
|
||||||
$widget['collapsible'] = false;
|
$widget['collapsible'] = false;
|
||||||
$widget['collapsed'] = false;
|
$widget['collapsed'] = false;
|
||||||
$widget['filter'] = false;
|
$widget['filter'] = false;
|
||||||
|
$widget['metrics'] = $metrics; // Pass metrics configuration to template
|
||||||
if (!empty($widget['records'])) {
|
if (!empty($widget['records'])) {
|
||||||
$widget['full'] = true;
|
$widget['full'] = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,47 +11,41 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Metric</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']) ?>
|
||||||
|
<?php if ($record['timestamp']) { ?>
|
||||||
|
<br>
|
||||||
|
<small class="text-muted">as of <?= date('Y-m-d H:i:s', strtotime($record['timestamp'])) ?></small>
|
||||||
|
<?php } ?>
|
||||||
|
</th>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<?php foreach ($widget['metrics'] as $section => $section_metrics) { ?>
|
||||||
|
<tr class="table-secondary">
|
||||||
|
<th colspan="<?= count($widget['records']) + 1 ?>"><?= htmlspecialchars($section) ?></th>
|
||||||
|
</tr>
|
||||||
|
<?php foreach ($section_metrics as $metric => $config) { ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Conferences</td>
|
<td><?= htmlspecialchars($config['label']) ?></td>
|
||||||
<?php foreach ($widget['records'] as $record) { ?>
|
<?php foreach ($widget['records'] as $record) { ?>
|
||||||
<td>
|
<td>
|
||||||
<?php if (isset($record['conferences'])) { ?>
|
<?php if (isset($record['metrics'][$section][$metric])) {
|
||||||
<?php if ($record['conferences'] !== null) { ?>
|
$metric_data = $record['metrics'][$section][$metric];
|
||||||
<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>
|
if ($metric_data['link']) { ?>
|
||||||
<br>
|
<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>
|
||||||
<small class="text-muted"><?= date('Y-m-d H:i:s', strtotime($record['from_time'])) ?></small>
|
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<span class="text-muted">0</span>
|
<?= htmlspecialchars($metric_data['value']) ?>
|
||||||
<?php } ?>
|
<?php }
|
||||||
<?php } else { ?>
|
} else { ?>
|
||||||
<span class="text-muted">No data</span>
|
<span class="text-muted">No data</span>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<?php } ?>
|
||||||
<td>Participants</td>
|
|
||||||
<?php foreach ($widget['records'] as $record) { ?>
|
|
||||||
<td>
|
|
||||||
<?php if (isset($record['participants'])) { ?>
|
|
||||||
<?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>
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tr>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
|
|
Loading…
Reference in New Issue