<commit_before><?php

if (!$af->debug()) $af->requirePermission('staff,admin');


$title = 'Server Status';

$af->script($afurl->static.'/js/jquery.tablesorter.min.js');
$af->style($afurl->static.'/css/theme.blue.css');


if (empty($servers)  ||  !is_array($servers)) {
	error500('NO SERVERS SPECIFIED, OR INVALID SERVER FORMAT');
}



////////////////////////////////////////////////////////////
// WEB SERVERS
////////////////////////////////////////////////////////////
$ctx = stream_context_create(['http'=>[
	'timeout'			=> 5,
	'follow_location'	=> false,
]]);

foreach ($servers as &$server) {
	$nstime = microtime(true);

	$json = pudl::jsonDecode(@file_get_contents($server, 0, $ctx));
	if (!empty($json)) {
		$server = [
			'path'		=> $server,
			'delay'		=> sprintf('%0.4f', microtime(true) - $nstime),
			'uptime'	=> str_replace('ago', '', aftime::since($json['boot'], 60*60*24*365*7)),
			'memory'	=> afstring::fromBytes( empty($json['memory']) ? 0 : $json['memory'] ),
		] + $json;
	} else {
		$server = [ 'path' => $server ];
	}
} unset($server);




////////////////////////////////////////////////////////////
// REDIS SERVER
////////////////////////////////////////////////////////////
if ($db->redis() instanceof Redis) {
	$nstime	= microtime(true);
	$redis	= $db->redis()->info();
	$servers[] = [
		'path'			=> 'Redis-01',
		'version'		=> $redis['redis_version'],
		'boot'			=> $af->time() - $redis['uptime_in_seconds'],
		'uptime'		=> aftime::since($af->time() - $redis['uptime_in_seconds'], 60*60*24*365*7),
		'memory'		=> afstring::fromBytes($redis['used_memory']),
		'delay'			=> sprintf('%0.4f', microtime(true) - $nstime),
	];
} else {
	$servers[]			= [
		'path'			=> 'Redis-01',
		'uptime'		=> 'OFFLINE!',
	];
}




////////////////////////////////////////////////////////////<commit_msg>Added "offline" message for unreachable servers<commit_after><?php

if (!$af->debug()) $af->requirePermission('staff,admin');


$title = 'Server Status';

$af->script($afurl->static.'/js/jquery.tablesorter.min.js');
$af->style($afurl->static.'/css/theme.blue.css');


if (empty($servers)  ||  !is_array($servers)) {
	error500('NO SERVERS SPECIFIED, OR INVALID SERVER FORMAT');
}



////////////////////////////////////////////////////////////
// WEB SERVERS
////////////////////////////////////////////////////////////
$ctx = stream_context_create(['http'=>[
	'timeout'			=> 5,
	'follow_location'	=> false,
]]);

foreach ($servers as &$server) {
	$nstime = microtime(true);

	$json = pudl::jsonDecode(@file_get_contents($server, 0, $ctx));
	if (!empty($json)) {
		$server = [
			'path'		=> $server,
			'delay'		=> sprintf('%0.4f', microtime(true) - $nstime),
			'uptime'	=> str_replace('ago', '', aftime::since($json['boot'], 60*60*24*365*7)),
			'memory'	=> afstring::fromBytes( empty($json['memory']) ? 0 : $json['memory'] ),
		] + $json;
	} else {
		$server = [
			'path'		=> $server,
			'uptime'	=> 'offline',
		];
	}
} unset($server);




////////////////////////////////////////////////////////////
// REDIS SERVER
////////////////////////////////////////////////////////////
if ($db->redis() instanceof Redis) {
	$nstime	= microtime(true);
	$redis	= $db->redis()->info();
	$servers[] = [
		'path'			=> 'Redis-01',
		'version'		=> $redis['redis_version'],
		'boot'			=> $af->time() - $redis['uptime_in_seconds'],
		'uptime'		=> aftime::since($af->time() - $redis['uptime_in_seconds'], 60*60*24*365*7),
		'memory'		=> afstring::fromBytes($redis['used_memory']),
		'delay'			=> sprintf('%0.4f', microtime(true) - $nstime),
	];
} else {
	$servers[]			= [
		'path'			=> 'Redis-01',
		'uptime'		=> 'OFFLINE!',
	];
}




////////////////////////////////////////////////////////////
{'fraction_non_alphanumeric': 0.37185385656292286, 'fraction_numerical': 0.018403247631935047, 'mean_word_length': 2.148211243611584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2922580', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1303, 'n_words': 197}