Add display of more stats in hspace
authorIustin Pop <iustin@google.com>
Thu, 2 Jul 2009 10:33:06 +0000 (12:33 +0200)
committerIustin Pop <iustin@google.com>
Thu, 2 Jul 2009 10:33:06 +0000 (12:33 +0200)
This patch changes Cluster.totalResources to compute more details about
the cluster status, and enhances hspace to display more of these.

Ganeti/HTools/Cluster.hs
hbal.hs
hn1.hs
hspace.hs

index dfeb7cc..d3aec7c 100644 (file)
@@ -144,12 +144,18 @@ computeBadItems nl il =
     (bad_nodes, bad_instances)
 
 -- | Compute the total free disk and memory in the cluster.
-totalResources :: Node.List -> (Int, Int)
+totalResources :: Node.List -> (Int, Int, Int, Int, Int)
 totalResources nl =
     foldl'
-    (\ (mem, dsk) node -> (mem + (Node.f_mem node),
-                           dsk + (Node.f_dsk node)))
-    (0, 0) (Container.elems nl)
+    (\ (mem, dsk, amem, mmem, mdsk) node ->
+         let inc_amem = (Node.f_mem node) - (Node.r_mem node)
+         in (mem + (Node.f_mem node),
+             dsk + (Node.f_dsk node),
+             amem + (if inc_amem > 0 then inc_amem else 0),
+             max mmem inc_amem,
+             max mdsk (Node.f_dsk node)
+            )
+    ) (0, 0, 0, 0, 0) (Container.elems nl)
 
 -- | Compute the mem and disk covariance.
 compDetailedCV :: Node.List -> (Double, Double, Double, Double, Double, Double)
diff --git a/hbal.hs b/hbal.hs
index 8eb6ee0..65fca79 100644 (file)
--- a/hbal.hs
+++ b/hbal.hs
@@ -317,8 +317,8 @@ main = do
 
   when (optShowNodes opts) $
        do
-         let (orig_mem, orig_disk) = Cluster.totalResources nl
-             (final_mem, final_disk) = Cluster.totalResources fin_nl
+         let (orig_mem, orig_disk, _, _, _) = Cluster.totalResources nl
+             (final_mem, final_disk, _, _, _) = Cluster.totalResources fin_nl
          putStrLn ""
          putStrLn "Final cluster status:"
          putStrLn $ Cluster.printNodes fin_nl
diff --git a/hn1.hs b/hn1.hs
index d8bcf44..0549ddc 100644 (file)
--- a/hn1.hs
+++ b/hn1.hs
@@ -228,8 +228,8 @@ main = do
 
   when (optShowNodes opts) $
        do
-         let (orig_mem, orig_disk) = Cluster.totalResources nl
-             (final_mem, final_disk) = Cluster.totalResources ns
+         let (orig_mem, orig_disk,  _, _, _) = Cluster.totalResources nl
+             (final_mem, final_disk, _, _, _) = Cluster.totalResources ns
          putStrLn ""
          putStrLn "Final cluster status:"
          putStrLn $ Cluster.printNodes ns
index ef95c67..aef5c00 100644 (file)
--- a/hspace.hs
+++ b/hspace.hs
@@ -243,7 +243,8 @@ main = do
          putStrLn $ Cluster.printNodes nl
 
   let ini_cv = Cluster.compCV nl
-      (orig_mem, orig_disk) = Cluster.totalResources nl
+      (ini_mem, ini_disk, ini_amem, ini_mmem, ini_mdsk) =
+          Cluster.totalResources nl
 
   (if verbose > 2 then
        printf "Initial coefficients: overall %.8f, %s\n"
@@ -251,8 +252,9 @@ main = do
    else
        printf "Initial score: %.8f\n" ini_cv)
   printf "Initial instances: %d\n" num_instances
-  printf "Initial free RAM: %d\n" orig_mem
-  printf "Initial free disk: %d\n" orig_disk
+  printf "Initial free RAM: %d\n" ini_mem
+  printf "Initial allocatable RAM: %d\n" ini_amem
+  printf "Initial free disk: %d\n" ini_disk
 
   let nmlen = Container.maxNameLen nl
       newinst = Instance.create "new" (optIMem opts) (optIDsk opts)
@@ -263,12 +265,14 @@ main = do
       fin_instances = num_instances + allocs
       fin_ixes = reverse ixes
       ix_namelen = maximum . map (length . Instance.name) $ fin_ixes
-      (final_mem, final_disk) = Cluster.totalResources fin_nl
+      (fin_mem, fin_disk, fin_amem, fin_mmem, fin_mdsk) =
+          Cluster.totalResources fin_nl
 
   printf "Final score: %.8f\n" (Cluster.compCV fin_nl)
   printf "Final instances: %d\n" (num_instances + allocs)
-  printf "Final free RAM: %d\n" final_mem
-  printf "Final free disk: %d\n" final_disk
+  printf "Final free RAM: %d\n" fin_mem
+  printf "Final allocatable RAM: %d\n" fin_amem
+  printf "Final free disk: %d\n" fin_disk
   printf "Usage: %.5f\n" (((fromIntegral num_instances)::Double) /
                           (fromIntegral fin_instances))
   printf "Allocations: %d\n" allocs
@@ -283,12 +287,6 @@ main = do
 
   when (optShowNodes opts) $
        do
-         let (orig_mem, orig_disk) = Cluster.totalResources nl
-             (final_mem, final_disk) = Cluster.totalResources fin_nl
          putStrLn ""
          putStrLn "Final cluster status:"
          putStrLn $ Cluster.printNodes fin_nl
-         when (verbose > 3) $
-              do
-                printf "Original: mem=%d disk=%d\n" orig_mem orig_disk
-                printf "Final:    mem=%d disk=%d\n" final_mem final_disk