cosmostat working
This commit is contained in:
@ -1,14 +1,11 @@
|
||||
<?php
|
||||
/* -------------------------------------------------------------
|
||||
* Cosmostat Dashboard - updated to support host‑specific view
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
function h(string $s): string
|
||||
{
|
||||
return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/* --------------------- 1. Load API data --------------------- */
|
||||
// Load API data
|
||||
$raw_api_settings = file('/opt/api_settings/cosmostat_settings.yaml',
|
||||
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
@ -42,24 +39,26 @@ if ($clients === null || !is_array($clients)) {
|
||||
die('<p style="color:red;">Malformed JSON returned from the API.</p>');
|
||||
}
|
||||
|
||||
/* --------------------- 2. Resolve selected host ------------- */
|
||||
$selectedHost = $_GET['host'] ?? '';
|
||||
$selectedIdx = null;
|
||||
// hostname get handler
|
||||
$selectedId = $_GET['host'] ?? ''; // the value passed in ?host=
|
||||
$selectedIdx = null;
|
||||
foreach ($clients as $idx => $client) {
|
||||
if (strtolower($client['hostname']) === strtolower($selectedHost)) {
|
||||
if (isset($client['short_id']) && $client['short_id'] === $selectedId) {
|
||||
$selectedIdx = $idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($selectedIdx === null) {
|
||||
// no match - default to the first host (or none)
|
||||
// No match – fall back to the first client (or none)
|
||||
$selectedIdx = 0;
|
||||
$selectedHost = $clients[$selectedIdx]['hostname'] ?? '';
|
||||
$selectedId = $clients[$selectedIdx]['short_id'] ?? '';
|
||||
}
|
||||
$client = $clients[$selectedIdx] ?? null;
|
||||
$properties = $client['client_properties'][0] ?? [];
|
||||
$systemProperties = $properties['system_properties'] ?? [];
|
||||
$systemComponents = $properties['system_components'] ?? [];
|
||||
$selectedHost = $clients[$selectedIdx]['hostname'];
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@ -76,86 +75,82 @@ $systemComponents = $properties['system_components'] ?? [];
|
||||
|
||||
<!-- Sidebar -->
|
||||
<nav class="sidebar">
|
||||
<div class="sidebar">
|
||||
<h3>Endpoints</h3>
|
||||
<!-- The list will be populated by the JavaScript below -->
|
||||
<ol id="endpointList"></ol>
|
||||
</div>
|
||||
<h3>Endpoints</h3>
|
||||
<!-- The list will be populated by JavaScript -->
|
||||
<ol id="endpointList"></ol>
|
||||
</nav>
|
||||
|
||||
<!-- Main content -->
|
||||
<div class="main">
|
||||
|
||||
<!-- Header Card -->
|
||||
<div class="card">
|
||||
<h2>Matt-Cloud Cosmostat Dashboard</h2>
|
||||
<p>This dashboard shows the local Matt-Cloud system stats.</p>
|
||||
<div class="help-link" id="helpToggle">API</div>
|
||||
</div>
|
||||
</div> <!-- / Header Card -->
|
||||
|
||||
<!-- Hidden API Card -->
|
||||
<div id="helpText" class="card">
|
||||
<strong>Component Desriptor</strong>
|
||||
<p>To view the component descriptor, you may <br>
|
||||
<code>curl -s https://<?= h($_SERVER['SERVER_NAME']) ?>/descriptor</code></p>
|
||||
<p>This will return the entire JSON descriptor variable</p>
|
||||
</div>
|
||||
</div> <!-- / Header Card -->
|
||||
|
||||
<!-- summary card -->
|
||||
<div class="card">
|
||||
<div id="host_components" class="column">
|
||||
|
||||
<?php if (!empty($systemProperties)): ?>
|
||||
<h2>System Properties</h2>
|
||||
<div class="system">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<ul class="system-list">
|
||||
<?php foreach ($systemProperties as $prop): ?>
|
||||
<li><?= h($prop['Property']) ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<h2>Live System Metrics</h2>
|
||||
<div id="host_metrics" class="column">Connecting...</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($systemComponents)): ?>
|
||||
<h2>Components</h2>
|
||||
<div class="components">
|
||||
<?php foreach ($systemComponents as $comp): ?>
|
||||
<div class="component">
|
||||
<h3><?= h($comp['component_name']) ?></h3>
|
||||
<ul class="info-list">
|
||||
<?php foreach ($comp['info_strings'] as $info): ?>
|
||||
<li><?= h($info) ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!empty($systemProperties)): ?><h2>System Properties</h2>
|
||||
<table><tr>
|
||||
<td>
|
||||
<ul class="system-list">
|
||||
<?php foreach ($systemProperties as $prop): ?><li><?= h($prop['Property']) ?></li>
|
||||
<?php endforeach; ?></ul>
|
||||
</td><td>
|
||||
<h2>Live System Metrics</h2>
|
||||
<!-- Live content, javascript rendered -->
|
||||
<div id="host_metrics" class="column">
|
||||
Connecting...
|
||||
</div> <!--/live content -->
|
||||
</td>
|
||||
</tr></table>
|
||||
<?php endif; ?><br>
|
||||
<!-- api help toggle -->
|
||||
<div class="componentDetail-link" id="componentDetailToggle">Toggle Component Details</div>
|
||||
</div> <!--/summary card -->
|
||||
<!-- hidden detail card -->
|
||||
<div id="componentDetailText" class="card">
|
||||
<?php if (!empty($systemComponents)): ?><h2>Components</h2>
|
||||
<!-- component bucket -->
|
||||
<div class="components">
|
||||
<?php foreach ($systemComponents as $comp): ?>
|
||||
|
||||
<!-- individual component -->
|
||||
<div class="component">
|
||||
<h3><?= h($comp['component_name']) ?></h3>
|
||||
<ul class="info-list">
|
||||
<?php foreach ($comp['info_strings'] as $info): ?><li><?= h($info) ?></li>
|
||||
<?php endforeach; ?></ul>
|
||||
</div> <!--/individual component -->
|
||||
<?php endforeach; ?></div> <!--/component bucket -->
|
||||
<?php endif; ?></div> <!--/hidden detail card -->
|
||||
</div> <!-- /main -->
|
||||
|
||||
</div> <!-- /wrapper -->
|
||||
|
||||
<!-- Socket.IO client library -->
|
||||
<script src="socket.io/socket.io.js"></script>
|
||||
<!-- system metrics script -->
|
||||
<script src="src/system_metrics.js"></script>
|
||||
<!-- sidebar script -->
|
||||
<script src="src/sidebar.js"></script>
|
||||
<!-- Panel Toggles -->
|
||||
<script>
|
||||
document.getElementById('helpToggle').addEventListener('click', function () {
|
||||
const help = document.getElementById('helpText');
|
||||
help.style.display = help.style.display === 'none' || help.style.display === '' ? 'block' : 'none';
|
||||
});
|
||||
document.getElementById('componentDetailToggle').addEventListener('click', function () {
|
||||
const help = document.getElementById('componentDetailText');
|
||||
help.style.display = help.style.display === 'none' || help.style.display === '' ? 'block' : 'none';
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user