Compare commits
2 Commits
b52abb69c7
...
f06c804c24
Author | SHA1 | Date | |
---|---|---|---|
f06c804c24 | |||
f7f3cb9704 |
21
index.php
21
index.php
@ -1,6 +1,17 @@
|
||||
<?php
|
||||
header('Content-Type: text/plain; version=0.0.4');
|
||||
$config = getenv('CONFIG_FILE');
|
||||
$phpbin = getenv('PHP_BINARY');
|
||||
$output = shell_exec('CONFIG_FILE="' . $config . '" ' . $phpbin . ' ' . $_SERVER['DOCUMENT_ROOT'] . 'script.php');
|
||||
echo $output;
|
||||
|
||||
if($_SERVER["REQUEST_URI"] == '/metrics') {
|
||||
header('Content-Type: text/plain; version=0.0.4');
|
||||
$config = getenv('CONFIG_FILE');
|
||||
$phpbin = getenv('PHP_BINARY');
|
||||
$output = shell_exec('CONFIG_FILE="' . $config . '" ' . $phpbin . ' ' . $_SERVER['DOCUMENT_ROOT'] . 'script.php');
|
||||
echo $output;
|
||||
} else {
|
||||
require_once('vendor/autoload.php');
|
||||
http_response_code(404);
|
||||
$loader = new \Twig\Loader\FilesystemLoader('templates');
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
'cache' => 'twig_cache',
|
||||
]);
|
||||
echo $twig->render('404.twig', ['path' => $_SERVER["REQUEST_URI"]]);
|
||||
}
|
29
script.php
29
script.php
@ -14,9 +14,7 @@ if(file_exists($cacheFile)) {
|
||||
} else {
|
||||
$oldconfig = [];
|
||||
}
|
||||
|
||||
if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
|
||||
foreach ($config as $key => &$metric) {
|
||||
foreach ($config as $key => &$metric) {
|
||||
if (!isset($metric['submetrics'])) {
|
||||
$metric['submetrics'] = [$metric];
|
||||
}
|
||||
@ -90,13 +88,13 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($pids as $pid) {
|
||||
}
|
||||
foreach ($pids as $pid) {
|
||||
pcntl_waitpid($pid, $none);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($config as $key => &$metric) {
|
||||
foreach ($config as $key => &$metric) {
|
||||
foreach ($metric['submetrics'] as $subkey => &$submetric) {
|
||||
$submetric['value'] = file_get_contents('/tmp/.metrics.' . $key . '.' . $subkey);
|
||||
if (!empty($oldconfig) && !isset($submetric['value']) && (isset($submetric['fallback']) && !empty($submetric['fallback']))) {
|
||||
@ -116,17 +114,16 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
|
||||
}
|
||||
unlink('/tmp/.metrics.' . $key . '.' . $subkey);
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($cacheFile, json_encode($config, JSON_PRETTY_PRINT));
|
||||
|
||||
$loader = new \Twig\Loader\FilesystemLoader('templates');
|
||||
$twig = new \Twig\Environment($loader, [
|
||||
'cache' => 'twig_cache',
|
||||
]);
|
||||
echo $twig->render('metrics.twig', ['config' => $config]);
|
||||
}
|
||||
|
||||
file_put_contents($cacheFile, json_encode($config, JSON_PRETTY_PRINT));
|
||||
|
||||
$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;
|
||||
|
12
templates/404.twig
Normal file
12
templates/404.twig
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>Page Title</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<style>
|
||||
</style>
|
||||
<body>
|
||||
<h1>404 Uri {{ path }} not found</h1>
|
||||
<p><a href="/metrics">/metrics</a></p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user