feat: added app to fill a pvc in 1GB increments
This commit is contained in:
		
							parent
							
								
									db9c8d83e6
								
							
						
					
					
						commit
						d7c17ceef9
					
				| @ -1,3 +1,90 @@ | |||||||
| <?php | <?php | ||||||
| print_r("Hello this is from PHP") | 
 | ||||||
|  | ini_set('display_errors', 1); | ||||||
|  | ini_set('display_startup_errors', 1); | ||||||
|  | error_reporting(E_ALL); | ||||||
|  | 
 | ||||||
|  | $host = getenv('MYSQL_HOST') ?: 'localhost'; | ||||||
|  | $db   = 'testfill'; | ||||||
|  | $user = getenv('MYSQL_USER') ?: 'root'; | ||||||
|  | $pass = getenv('MYSQL_PASSWORD') ?: ''; | ||||||
|  | $charset = 'utf8mb4'; | ||||||
|  | 
 | ||||||
|  | // Setup PDO
 | ||||||
|  | $dsn = "mysql:host=$host;charset=$charset"; | ||||||
|  | $options = [ | ||||||
|  |     PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION, | ||||||
|  |     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | ||||||
|  | ]; | ||||||
|  | 
 | ||||||
|  | try { | ||||||
|  |     $pdo = new PDO($dsn, $user, $pass, $options); | ||||||
|  |     $pdo->exec("CREATE DATABASE IF NOT EXISTS `$db`"); | ||||||
|  |     $pdo->exec("USE `$db`"); | ||||||
|  |     $pdo->exec(" | ||||||
|  |         CREATE TABLE IF NOT EXISTS filler ( | ||||||
|  |             id INT AUTO_INCREMENT PRIMARY KEY, | ||||||
|  |             data LONGBLOB | ||||||
|  |         ) | ||||||
|  |     ");
 | ||||||
|  | } catch (\PDOException $e) { | ||||||
|  |     die("Database setup failed: " . $e->getMessage()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // Disk usage (PVC mount path)
 | ||||||
|  | $mountPath = '/var/lib/mysql'; // Change this if PVC is mounted elsewhere
 | ||||||
|  | $freeBytes = disk_free_space($mountPath); | ||||||
|  | $totalBytes = disk_total_space($mountPath); | ||||||
|  | $freeGB = round($freeBytes / (1024 ** 3), 2); | ||||||
|  | $totalGB = round($totalBytes / (1024 ** 3), 2); | ||||||
|  | $usedGB = round(($totalBytes - $freeBytes) / (1024 ** 3), 2); | ||||||
|  | 
 | ||||||
|  | $message = ''; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | if ($_SERVER['REQUEST_METHOD'] === 'POST'&& isset($_POST['fill'])) { | ||||||
|  |      | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     $chunkSize = 1024 * 1024; // 1MB
 | ||||||
|  |     $iterations = 1024;       // 1GB total
 | ||||||
|  |     $data = str_repeat(random_bytes(1024), 1024); // ~1MB binary blob
 | ||||||
|  | 
 | ||||||
|  |     $stmt = $pdo->prepare("INSERT INTO filler (data) VALUES (:data)"); | ||||||
|  | 
 | ||||||
|  |     for ($i = 0; $i < $iterations; $i++) { | ||||||
|  |         $stmt->execute([':data' => $data]); | ||||||
|  |     }  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     clearstatcache(); | ||||||
|  |     $freeBytes = disk_free_space($mountPath); | ||||||
|  |     $freeGB = round($freeBytes / (1024 ** 3), 2); | ||||||
|  |     $usedGB = round(($totalBytes - $freeBytes) / (1024 ** 3), 2); | ||||||
|  | 
 | ||||||
|  |     $message = "<p style='color: green;'>✅ 1GB inserted. Disk usage updated.</p>"; | ||||||
|  | } | ||||||
| ?>
 | ?>
 | ||||||
|  | 
 | ||||||
|  | <!DOCTYPE html> | ||||||
|  | <html> | ||||||
|  | <head> | ||||||
|  |     <title>Volume Filler</title> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  |     <h1>Kubernetes PVC Filler</h1> | ||||||
|  |     <?= $message ?>
 | ||||||
|  |     <ul> | ||||||
|  |         <li>Total PVC Space: <?= $totalGB ?> GB</li>
 | ||||||
|  |         <li>Used PVC Space: <?= $usedGB ?> GB</li>
 | ||||||
|  |         <li>Free PVC Space: <?= $freeGB ?> GB</li>
 | ||||||
|  |     </ul> | ||||||
|  | 
 | ||||||
|  |     <form method="post"> | ||||||
|  |         <button name="fill" value="1" type="submit">Insert 1GB into DB</button> | ||||||
|  |     </form> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user