PHP Classes

File: web/api/storage_stats.php

Recommend this page to a friend!
  Packages of Free Ment   Fractal Zip   web/api/storage_stats.php   Download  
File: web/api/storage_stats.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Fractal Zip
Compress files into archives of fractal zip format
Author: By
Last change:
Date: 11 days ago
Size: 1,522 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

header('Content-Type: application/json; charset=UTF-8');

$base = dirname(__DIR__, 2);
require_once
$base . '/storage/StorageIndex.php';
require_once
$base . '/storage/CompactionCalculus.php';

$index = new StorageIndex();
$index->load();

$files = $index->getFiles();
$containers = $index->getContainers();

$totalRaw = 0;
$looseRaw = 0;
$containerBackedRaw = 0;
foreach (
$files as $f) {
   
$totalRaw += $f['raw_bytes'];
    if (
$f['storage'] === 'loose') {
       
$looseRaw += $f['raw_bytes'];
    } else {
       
$containerBackedRaw += $f['raw_bytes'];
    }
}

$containerDisk = 0;
foreach (
$containers as $c) {
   
$containerDisk += $c['byte_size'];
}

$calc = new CompactionCalculus(
   
weightBytes: 1.0,
   
weightLatency: 0.0012,
   
minLooseBytes: 256,
   
minScoreToCompact: 100.0
);
$fileRows = array_map(static function (array $f) {
    return [
       
'logical_path' => $f['logical_path'],
       
'raw_bytes' => $f['raw_bytes'],
       
'storage' => $f['storage'],
    ];
},
$files);
$suggestions = $calc->suggestClusters($fileRows, 8);

echo
json_encode([
   
'files_root' => $index->getFilesRoot(),
   
'index_path' => $index->getIndexPath(),
   
'totals' => [
       
'logical_files' => count($files),
       
'containers' => count($containers),
       
'raw_bytes_all' => $totalRaw,
       
'raw_bytes_loose' => $looseRaw,
       
'raw_bytes_in_containers' => $containerBackedRaw,
       
'container_disk_bytes' => $containerDisk,
    ],
   
'containers' => $containers,
   
'files' => $files,
   
'compaction_suggestions' => $suggestions,
],
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);