-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathStatistics.php
More file actions
99 lines (82 loc) · 3.99 KB
/
Statistics.php
File metadata and controls
99 lines (82 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Model\Admin;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Utils;
class Statistics
{
public function serverLoad()
{
if (@file_exists('/proc/loadavg') && is_readable('/proc/loadavg')) {
// We use @ just in case
$fh = @fopen('/proc/loadavg', 'r');
$loadAverages = @fread($fh, 64);
@fclose($fh);
if (($fh = @fopen('/proc/loadavg', 'r'))) {
$loadAverages = fread($fh, 64);
fclose($fh);
} else {
$loadAverages = '';
}
$loadAverages = @explode(' ', $loadAverages);
$loadAverages = Hooks::fire('model.admin.model.statistics.get_server_load.load_averages', $loadAverages);
$serverLoad = isset($loadAverages[2]) ? $loadAverages[0].' '.$loadAverages[1].' '.$loadAverages[2] : __('Not available');
} elseif (!in_array(PHP_OS, ['WINNT', 'WIN32']) && preg_match('%averages?: ([0-9\.]+),?\s+([0-9\.]+),?\s+([0-9\.]+)%i', @exec('uptime'), $loadAverages)) {
$serverLoad = $loadAverages[1].' '.$loadAverages[2].' '.$loadAverages[3];
} else {
$serverLoad = __('Not available');
}
$serverLoad = Hooks::fire('model.admin.model.statistics.get_server_load.server_load', $serverLoad);
return $serverLoad;
}
public function numOnline()
{
$numOnline = DB::table('online')->where('idle', 0)
->count('user_id');
$numOnline = Hooks::fire('model.admin.model.statistics.get_num_online.num_online', $numOnline);
return $numOnline;
}
public function totalSize()
{
$total = [];
if (ForumEnv::get('DB_TYPE') == 'mysql' || ForumEnv::get('DB_TYPE') == 'mysqli' || ForumEnv::get('DB_TYPE') == 'mysql_innodb' || ForumEnv::get('DB_TYPE') == 'mysqli_innodb') {
// Calculate total db size/row count
$result = DB::table('users')->rawQuery('SHOW TABLE STATUS LIKE \''.ForumEnv::get('DB_PREFIX').'%\'')->findMany();
$result = Hooks::fire('model.admin.model.statistics.get_total_size.raw_data', $result);
$total['size'] = $total['records'] = 0;
foreach ($result as $status) {
$total['records'] += $status['Rows'];
$total['size'] += $status['Data_length'] + $status['Index_length'];
}
$total['size'] = Utils::fileSize($total['size']);
}
$total = Hooks::fire('model.admin.model.statistics.get_total_size.total', $total);
return $total;
}
public function phpAccelerator()
{
if (function_exists('mmcache')) {
$phpAccelerator = '<a href="http://'.__('Turck MMCache link').'">'.__('Turck MMCache').'</a>';
} elseif (isset($_pHPA)) {
$phpAccelerator = '<a href="http://'.__('ionCube PHP Accelerator link').'">'.__('ionCube PHP Accelerator').'</a>';
} elseif (ini_get('apc.enabled')) {
$phpAccelerator ='<a href="http://'.__('Alternative PHP Cache (APC) link').'">'.__('Alternative PHP Cache (APC)').'</a>';
} elseif (ini_get('zend_optimizer.optimization_level')) {
$phpAccelerator = '<a href="http://'.__('Zend Optimizer link').'">'.__('Zend Optimizer').'</a>';
} elseif (ini_get('eaccelerator.enable')) {
$phpAccelerator = '<a href="http://'.__('eAccelerator link').'">'.__('eAccelerator').'</a>';
} elseif (ini_get('xcache.cacher')) {
$phpAccelerator = '<a href="http://'.__('XCache link').'">'.__('XCache').'</a>';
} else {
$phpAccelerator = __('NA');
}
$phpAccelerator = Hooks::fire('model.admin.model.statistics.get_php_accelerator', $phpAccelerator);
return $phpAccelerator;
}
}