Skip to content

Commit

Permalink
Add some value of Monit system overview
Browse files Browse the repository at this point in the history
  • Loading branch information
GOUKI9999 committed Aug 7, 2024
1 parent ea813fd commit 3ca6855
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
38 changes: 27 additions & 11 deletions Monit/Monit.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ public function test()
public function livestats()
{
$status = 'inactive';
$data = [
'running_services' => 'N/A',
'failed_services' => 'N/A',
'load' => 'N/A',
'cpu' => 'N/A',
'memory' => 'N/A',
'swap' => 'N/A'
];

$data = [];
$response = $this->executeCurl($this->url('/_status?format=xml'));

if ($response['httpcode'] == 200) {
Expand All @@ -47,6 +39,10 @@ public function livestats()

$running_services = 0;
$failed_services = 0;
$load = 'N/A';
$cpu = 'N/A';
$memory = 'N/A';
$swap = 'N/A';

if (isset($data['service'])) {
if (isset($data['service'][0])) {
Expand All @@ -66,9 +62,29 @@ public function livestats()
}
}

foreach ($data['service'] as $service) {
if (isset($service['system'])) {
$load = $service['system']['load']['avg05'] ?? 'N/A';
$cpu = isset($service['system']['cpu']['user']) ? $service['system']['cpu']['user'] . '%' : 'N/A';
$memory = isset($service['system']['memory']['percent']) ? $service['system']['memory']['percent'] . '%' : 'N/A';
$swap = isset($service['system']['swap']['percent']) ? $service['system']['swap']['percent'] . '%' : 'N/A';
break;
}
}

$status = 'active';
$data['running_services'] = $running_services;
$data['failed_services'] = $failed_services;
$data = [
'running_services' => $running_services,
'failed_services' => $failed_services,
'load' => $load,
'cpu' => $cpu,
'memory' => $memory,
'swap' => $swap
];
} else {
$data = [
'error' => 'Failed to connect to Monit. HTTP Status: ' . $response['httpcode']
];
}

$visiblestats = [];
Expand Down
38 changes: 1 addition & 37 deletions Monit/config.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,4 @@
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>

<script>
document.getElementById('test_config').addEventListener('click', function() {
var username = document.querySelector('[data-config="username"]').value;
var password = document.querySelector('[data-config="password"]').value;
var url = document.getElementById('override_url').value;
console.log('Username:', username);
console.log('Password:', password);
console.log('URL:', url);
if (!username || !password || !url) {
alert('URL, Username, and Password are required');
return;
}
fetch(url, {
method: 'GET',
headers: {
'Authorization': 'Basic ' + btoa(username + ':' + password),
'Content-Type': 'application/json',
},
})
.then(response => {
if (response.status === 200) {
alert('Successfully communicated with the API');
} else {
alert('Failed: Invalid credentials');
}
})
.catch(error => {
alert('Error testing Monit configuration');
console.error('Error:', error);
});
});
</script>
</div>

0 comments on commit 3ca6855

Please sign in to comment.