Adds simple status checks for nginx and JVB

main
Yasen Pramatarov 2024-09-01 16:29:59 +03:00
parent 4e8de4b728
commit 8c97bd2873
3 changed files with 59 additions and 16 deletions

31
functions.php 100644
View File

@ -0,0 +1,31 @@
<?php
// get nginx data
function getNginxStatus() {
$status = trim(shell_exec('systemctl is-active nginx'));
return ($status === 'active') ? 'running' : 'not running';
}
function getNginxConnections() {
$connections = shell_exec("netstat -an | grep ':80' | wc -l");
return intval(trim($connections));
}
// get JVB data
function getJVBStatus() {
$status = trim(shell_exec('systemctl is-active jitsi-videobridge'));
return ($status === 'active') ? 'running' : 'not running';
}
function getProsodyStatus() {
$status = trim(shell_exec('systemctl is-active prosody'));
return ($status === 'active') ? 'running' : 'not running';
}
function getJicofoStatus() {
$status = trim(shell_exec('systemctl is-active jicofo'));
return ($status === 'active') ? 'running' : 'not running';
}
?>

28
index.php 100644
View File

@ -0,0 +1,28 @@
<?php
include 'functions.php';
// the response is in JSON
header('Content-Type: application/json');
// nginx status
if ($_SERVER['REQUEST_URI'] === '/nginx') {
$data = [
'nginx_status' => getNginxStatus(),
'nginx_connections' => getNginxConnections(),
];
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
// jvb status
} elseif ($_SERVER['REQUEST_URI'] === '/jvb') {
$data = [
'jvb_status' => getJVBStatus(),
];
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
// default response - error
} else {
echo json_encode(['error' => 'Endpoint not found']) . "\n";
}
?>

View File

@ -1,16 +0,0 @@
<?php
// nginx status
if ($_SERVER['REQUEST_URI'] === '/nginx/status') {
echo json_encode(['nginx' => shell_exec('/etc/init.d/nginx status')]);
// jvb status
} elseif ($_SERVER['REQUEST_URI'] === '/jvb/status') {
echo json_encode(['jvb' => shell_exec('/etc/init.d/jitsi-videobridge status')]);
// default response - error
} else {
echo json_encode(['error' => 'Endpoint not found']);
}
?>