2024-06-03 19:48:39 +02:00
|
|
|
<?php
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
require 'config.php';
|
|
|
|
|
|
|
|
if($_SERVER["REQUEST_URI"] == '/metrics') {
|
|
|
|
foreach ($config as $key => &$c) {
|
|
|
|
if(isset($c['command'])) {
|
|
|
|
$output=null;
|
|
|
|
$retval=null;
|
|
|
|
exec($c['command'], $output, $retval);
|
|
|
|
$output = implode("\n", $output);
|
|
|
|
} elseif(isset($c['httpurl'])) {
|
|
|
|
$client = new GuzzleHttp\Client();
|
2024-06-03 19:48:39 +02:00
|
|
|
|
|
|
|
$options = [];
|
|
|
|
if (isset($c['proxy'])) {
|
|
|
|
$options['proxy'] = $c['proxy'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$res = $client->request('GET', $c['httpurl'], $options);
|
2024-06-03 19:48:39 +02:00
|
|
|
$output = $res->getBody()->getContents();
|
2024-06-03 19:48:39 +02:00
|
|
|
} elseif(isset($c['httpresponsetime'])) {
|
|
|
|
$client = new GuzzleHttp\Client();
|
|
|
|
$output = NULL;
|
2024-06-03 19:48:39 +02:00
|
|
|
|
|
|
|
$options = [
|
|
|
|
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) {
|
|
|
|
$output = $stats->getTransferTime();
|
|
|
|
}
|
|
|
|
];
|
|
|
|
if (isset($c['proxy'])) {
|
|
|
|
$options['proxy'] = $c['proxy'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$res = $client->request('GET', $c['httpresponsetime'], $options);
|
2024-06-03 19:48:39 +02:00
|
|
|
}
|
|
|
|
if(isset($c['jsonelem'])) {
|
|
|
|
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));
|
2024-06-03 19:48:39 +02:00
|
|
|
} else {
|
|
|
|
$c['value'] = $output;
|
2024-06-03 19:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$loader = new \Twig\Loader\FilesystemLoader('templates');
|
|
|
|
$twig = new \Twig\Environment($loader, [
|
|
|
|
'cache' => 'twig_cache',
|
|
|
|
]);
|
|
|
|
echo $twig->render('metrics.twig', ['config' => $config]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getArrayValue($elem, $array) {
|
|
|
|
$elem = explode('.', $elem);
|
|
|
|
$new_array = $array;
|
|
|
|
foreach ($elem as $i) {
|
|
|
|
$new_array = $new_array[$i];
|
|
|
|
}
|
|
|
|
return $new_array;
|
|
|
|
}
|