summaryrefslogblamecommitdiffstats
path: root/modules-available/statistics/pages/hints.inc.php
blob: 5092157cf07dcb25c048a471d41db6d9c560f5db (plain) (tree)
1
2
3
4
5
6
7
8






                                             
                                                



                                         




                                                           
                                          
                                             
                                            

         



                                                                   
                                                              

                                                                


                                                                       




                                                               
                                                                                                           












                                                                                                                      

                                 


                                                                            



                                                             
                                                           

                                                                 


                                                                       

                                                     






                                                    

                                                                                       


                                                                                                                           


                                                                                 



                                                                 
                                                            
         

                                   
                                                          




                                                                       
                                                                                    
                                                                   
                                               




                                                                                         
                                                          




                                                                       
                                                                                      

                                                                   

                                                                                                       
                                               




                                                                                         

                                                 





                                                       






















                                                                                     
 
<?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::showSlowNics($locs);
		self::showUnusedSpace($locs);
		self::showMemorySlow($locs);
	}

	/**
	 * Machines that have less than 8GB of RAM. Highlight those
	 * that still have free memory slots.
	 */
	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->addLocalColumn('Memory Installed Capacity')->addCondition('<', 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;
			}
		}
		if (empty($list))
			return;
		Render::addTemplate('hints-ram-upgrade', ['list' => $list]);
	}

	/**
	 * Show machines where RAM modules are running slower
	 * than their design speed.
	 */
	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');
		$col = $q->addGlobalColumn('Speed');
		$col->addCondition('>', $q->addLocalColumn('Configured Memory Speed'));
		$list = $q->query(['machineuuid', 'Size', 'Manufacturer', 'Speed', 'Configured Memory Speed'])->fetchAll();
		if (empty($list))
			return;
		Render::addTemplate('hints-ram-underclocked', ['list' => $list]);
	}

	/**
	 * Show machines that have unpartitioned space available,
	 * and no ID44 or ID45.
	 */
	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->addLocalColumn('unused')->addCondition('>', 2000000000); // 2 GB
		$q->addMachineWhere('id44mb', '<', 20000); // 20 GB
		foreach ($q->query() 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->addLocalColumn('unused')->addCondition('>', 50000000000); // 50 GB
		$q->addMachineWhere('id44mb', '>', 20000); // 20 GB
		$q->addMachineWhere('id45mb', '<', 20000); // 20 GB
		// Only suggest SSD based systems, caching on spinning rust is usually slower than GBit
		$q->addGlobalColumn('rotation_rate')->addCondition('=', 0);
		foreach ($q->query() 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;
		}
		if (empty($id44) && empty($id45))
			return;
		Render::addTemplate('hints-hdd-grow', [
			'id44' => $id44,
			'id45' => $id45,
		]);
	}

	private static function showSlowNics(array $locs)
	{
		$list = [];
		$q = new HardwareQuery(HardwareInfo::MAINBOARD);
		if (!empty($locs)) {
			$q->addMachineWhere('locationid', 'IN', $locs);
		}
		$q->addMachineColumn('clientip');
		$q->addMachineColumn('hostname');
		$q->addLocalColumn('nic-speed')->addCondition('<', 1000);
		$q->addLocalColumn('nic-duplex');
		foreach ($q->query() as $row) {
			if ($row['nic-speed'] == 0) {
				$row['nic-speed'] = '???';
			}
			$list[] = $row;
		}
		if (empty($list))
			return;
		ArrayUtil::sortByColumn($list, 'nic-speed', SORT_ASC | SORT_NUMERIC);
		Render::addTemplate('hints-nic-speed', ['list' => $list]);
	}

}