]> git.nbdom.net Git - nb.git/commitdiff
host_info_backup
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 13 Oct 2024 23:29:06 +0000 (01:29 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 13 Oct 2024 23:29:06 +0000 (01:29 +0200)
etc/dbq/data.php

index e9ef679b0dd27306312ceea51934d572342e2ca1..34cdb11f4279bd88a345f10969cd88a4215d78cc 100644 (file)
@@ -1,5 +1,17 @@
 <?php
 
+function bytes2h($SizeInBytes) {
+  $i = -1;
+  $byteUnits = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+  do {
+    $SizeInBytes /= 1024;
+    $i++;
+  } while ($SizeInBytes > 1024);
+
+  #return Math.max(SizeInBytes, 0.1).toFixed(1) + byteUnits[i];
+  return floor($SizeInBytes).$byteUnits[$i];
+}
+
 $DBQ['data'] = [
        'tables' => [
                        'host_info_err' => [
@@ -7,6 +19,40 @@ $DBQ['data'] = [
                                                ." OR (key LIKE '%.exit_code' AND val<> '0')"
                                        ,
                        ],
+                       'host_info_backup' => [
+                                       'sql' => preg_replace('/[\t\r\n]/','',"
+                                               SELECT host
+                                                       ,REPLACE(REPLACE(hi.key,'backup_servers.',''),'.dirs','') as server
+                                                       ,'' as time
+                                                       ,'' as files_transfer
+                                                       ,'' as files_total
+                                                       ,'' as bytes_transfer
+                                                       ,'' as bytes_total
+                                                       ,max(updated) as updated
+                                                FROM host_info hi
+                                                WHERE key LIKE 'backup_servers.%.dirs'
+                                                GROUP BY host,server ORDER BY updated DESC, host
+"),
+                                       'row_parse_pre' => function(&$row,$t) {
+
+                                               $sql = "SELECT key,val FROM host_info WHERE host=".$t->db()->quote($row['host'])
+                                                       ." AND key LIKE 'backup_servers.".$row['server'].".%'";
+                                               ;
+                                               $rows = $t->db()->rows($sql,PDO::FETCH_ASSOC);
+                                               foreach($rows as $info) {
+                                                       $info['key'] = preg_replace('/^.*\.([^\.]+)$/','$1',$info['key']);
+                                                       if (preg_match('/^bytes/',$info['key']))
+                                                       #if (preg_match('/(total|transfer)$/',$info['key']))
+                                                               $info['val'] = bytes2h( $info['val'] )
+                                                       ;
+                                                       if (isset($row[ $info['key'] ])) $row[ $info['key'] ] = $info['val'];
+                                               }
+
+                                               foreach ($row as $k=>$v) {
+                                                       if (strpos($k,'updated') !== false) $row[$k] = preg_replace('/\..*$/','',$v);
+                                               }
+                                       },
+                       ],
                        'host_info_git' => [
                                        'sql' => preg_replace('/[\t\r\n]/','',"
                                                SELECT host