cosmostat has working drive health dashboard
This commit is contained in:
141
files/archive/index.php
Normal file
141
files/archive/index.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
# load API settings, this requires a simple yaml file
|
||||
$raw_api_settings = file('/app/cosmostat_settings.yaml', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
$api_settings = [];
|
||||
foreach ($raw_api_settings as $line) {
|
||||
if ($line[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
$pos = strpos($line, ':');
|
||||
if ($pos === false) {
|
||||
continue;
|
||||
}
|
||||
$key = trim(substr($line, 0, $pos));
|
||||
$value = trim(substr($line, $pos + 1));
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
}
|
||||
$api_settings[$key] = $value;
|
||||
}
|
||||
$api_bind_ip = trim($api_settings['api_bind_ip'], "\"'") ?? null;
|
||||
$customApiPort = trim($api_settings['custom_api_port'], "\"'") ?? null;
|
||||
# load API data
|
||||
$apiUrl = 'http://'.$api_bind_ip.':'.$customApiPort.'/php_summary';
|
||||
echo "<!-- apiUrl - ".$apiUrl." -->";
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'timeout' => 5, // seconds
|
||||
'header' => "User-Agent: PHP/" . PHP_VERSION . "\r\n"
|
||||
]
|
||||
]);
|
||||
$json = @file_get_contents($apiUrl, false, $context);
|
||||
if ($json === false) {
|
||||
die('<p style="color:red;">Could not fetch data from the API.</p>');
|
||||
}
|
||||
$data = json_decode($json, true);
|
||||
if ($data === null) {
|
||||
die('<p style="color:red;">Malformed JSON returned from the API.</p>');
|
||||
}
|
||||
function h(string $s): string
|
||||
{
|
||||
return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Cosmostat - <?php echo $_SERVER['SERVER_NAME'] ?></title>
|
||||
|
||||
<link rel="stylesheet" href="src/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<!-- Main content -->
|
||||
<div class="main">
|
||||
|
||||
<!-- Header Card -->
|
||||
<div class="card">
|
||||
<h2>Matt-Cloud Cosmostat Dashboard</h2>
|
||||
This dashboard shows the local Matt-Cloud system stats.<p>
|
||||
<div class="help-link" id="helpToggle">API</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>
|
||||
This will return the entire JSON descriptor variable.<br>
|
||||
The endpoint agent uses this descriptor to build out its local System Object.<br>
|
||||
The agent then reports back to the Cosmostat Server with all the data found in the descriptor.<br>
|
||||
Full Source Code can be found at its <a target="_blank" rel="noopener noreferrer" href=https://gitea.matt-cloud.com/matt/cosmoserver>Gitea</a> page.
|
||||
</div> <!-- / Header Card -->
|
||||
|
||||
<div class="card">
|
||||
<div id="host_components" class="column">
|
||||
|
||||
<!-- PHP to render static components -->
|
||||
<!-- summary card -->
|
||||
<div class="card">
|
||||
<?php if (isset($data[0]['system_properties'])): ?><h2>System Properties</h2>
|
||||
<table><tr>
|
||||
<td>
|
||||
<ul class="system-list">
|
||||
<?php foreach ($data[0]['system_properties'] 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 (isset($data[0]['system_components'])): ?><h2>Components</h2>
|
||||
<!-- component bucket -->
|
||||
<div class="components">
|
||||
<?php foreach ($data[0]['system_components'] 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>
|
||||
|
||||
<!-- matt-cloud redis script -->
|
||||
<script src="src/redis.js"></script>
|
||||
|
||||
<!-- Toggle the help text when the link is clicked -->
|
||||
<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