1
Fork 0

add metrics
All checks were successful
/ deploy (push) Successful in 6s

This commit is contained in:
toufic ar 2026-02-05 22:19:32 +02:00
parent 7f29a1f315
commit b0786a03a9
Signed by: toufic ar
SSH key fingerprint: SHA256:/NaO5I1nG3gYKzrzSiTYIdRyaIYxDWfr1U+d+yfJ/4k
2 changed files with 75 additions and 1 deletions

41
metrics.php Normal file
View file

@ -0,0 +1,41 @@
<?php
header('Content-Type: application/json; charset=utf-8');
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
http_response_code(405);
header('Allow: GET');
echo json_encode(['error' => 'method not allowed']);
exit;
}
function get_snowflake_connections()
{
$metric = 'tor_snowflake_proxy_connections_total';
$body = file_get_contents(
'http://127.0.0.1:9999/internal/metrics',
false
);
if (!$body) {
return 0;
}
$conns = 0;
foreach (preg_split('/\r\n|\n|\r/', $body) as $line) {
$line = trim($line);
if (!$line || $line[0] === '#')
continue;
if (preg_match(
'/^'
. preg_quote($metric, '/')
. '(?:\{[^}]*\})?\s+([0-9]+(?:\.[0-9]+)?)$/', $line, $m
)) {
$conns = $m[1];
break;
}
}
return $conns;
}
$snowflake_connections = get_snowflake_connections();
echo json_encode(['snowflake_connections' => $snowflake_connections]);