summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/pages/hints.inc.php
blob: 278c0e265e6ca2b35048d4ce9de598915b6b2bdc (plain) (blame)
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
100
101
102
103
104
105
106
107
108
109
<?php

class SubPage
{

	public static function doPreprocess()
	{
		User::assertPermission('hints');
	}

	public static function doRender()
	{
		$locs = User::getAllowedLocations('hints');
		if (in_array(0, $locs)) {
			$locs = [];
		}
		self::showMemoryUpgrade($locs);
		self::showMemorySlow($locs);
		self::showUnusedSpace($locs);
	}

	private static function showMemoryUpgrade(array $locs)
	{
		$q = new HardwareQuery(HardwareInfo::MAINBOARD);
		if (!empty($locs)) {
			$q->addMachineWhere('locationid', 'IN', $locs);
		}
		$q->addLocalColumn('Memory Slot Occupied');
		$q->addGlobalColumn('Memory Slot Count');
		$q->addGlobalColumn('Memory Maximum Capacity');
		$q->addMachineColumn('clientip');
		$q->addMachineColumn('hostname');
		$q->addWhere(false, 'Memory Installed Capacity', '<', 8 * 1024 * 1024 * 1024);
		$list = [];
		foreach ($q->query() as $row) {
			if (HardwareParser::convertSize($row['Memory Installed Capacity'], 'M', false)
					>= HardwareParser::convertSize($row['Memory Maximum Capacity'], 'M', false)) {
				$row['size_class'] = 'danger';
				$list[] = $row;
			} elseif ($row['Memory Slot Occupied'] < $row['Memory Slot Count']) {
				$row['count_class'] = 'success';
				array_unshift($list, $row);
			} else {
				$list[] = $row;
			}
		}
		Render::addTemplate('hints-ram-upgrade', ['list' => $list]);
	}

	private static function showMemorySlow(array $locs)
	{
		$q = new HardwareQuery(HardwareInfo::RAM_MODULE);
		if (!empty($locs)) {
			$q->addMachineWhere('locationid', 'IN', $locs);
		}
		$q->addLocalColumn('Locator');
		$q->addLocalColumn('Bank Locator');
		$q->addGlobalColumn('Form Factor');
		$q->addGlobalColumn('Type');
		$q->addGlobalColumn('Size');
		$q->addGlobalColumn('Manufacturer');
		$q->addLocalColumn('Serial Number');
		$q->addMachineColumn('clientip');
		$q->addMachineColumn('hostname');
		$q->addCompare(true, 'Speed', '>', false, 'Configured Memory Speed');
		$list = $q->query()->fetchAll();
		Render::addTemplate('hints-ram-underclocked', ['list' => $list]);
	}

	private static function showUnusedSpace(array $locs)
	{
		$id44 = $id45 = [];
		// ID44
		$q = new HardwareQuery(HardwareInfo::HDD);
		if (!empty($locs)) {
			$q->addMachineWhere('locationid', 'IN', $locs);
		}
		$q->addMachineColumn('clientip');
		$q->addMachineColumn('hostname');
		$q->addWhere(false, 'unused', '>', 2000000000); // 2 GB
		$q->addMachineWhere('id44mb', '<', 20000); // 20 GB
		foreach ($q->query()->fetchAll() as $row) {
			$row['unused_s'] = Util::readableFileSize($row['unused']);
			$row['id44mb_s'] = Util::readableFileSize($row['id44mb'], -1, 2);
			$id44[] = $row;
		}
		// ID45
		$q = new HardwareQuery(HardwareInfo::HDD);
		if (!empty($locs)) {
			$q->addMachineWhere('locationid', 'IN', $locs);
		}
		$q->addMachineColumn('clientip');
		$q->addMachineColumn('hostname');
		$q->addWhere(false, 'unused', '>', 25000000000); // 25 GB
		$q->addMachineWhere('id44mb', '>', 20000); // 20 GB
		$q->addMachineWhere('id45mb', '<', 20000); // 20 GB
		foreach ($q->query()->fetchAll() as $row) {
			$row['unused_s'] = Util::readableFileSize($row['unused']);
			$row['id44mb_s'] = Util::readableFileSize($row['id44mb'], -1, 2);
			$row['id45mb_s'] = Util::readableFileSize($row['id45mb'], -1, 2);
			$id45[] = $row;
		}
		Render::addTemplate('hints-hdd-grow', [
			'id44' => $id44,
			'id45' => $id45,
		]);
	}

}