Commit d0a14556 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

hinfo: Gather and print group statistics


Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent f35ea63a
......@@ -58,7 +58,48 @@ options =
, oShowHelp
]
-- | Gather and print split instances
-- | Node group statistics.
calcGroupInfo :: Group.Group
-> Node.List
-> Instance.List
-> (String, (Int, Int), (Int, Int), Bool)
calcGroupInfo g nl il =
let nl_size = Container.size nl
il_size = Container.size il
(bad_nodes, bad_instances) = Cluster.computeBadItems nl il
bn_size = length bad_nodes
bi_size = length bad_instances
n1h = bn_size == 0
in (Group.name g, (nl_size, il_size), (bn_size, bi_size), n1h)
-- | Helper to format one group row result.
groupRowFormatHelper :: (String, (Int, Int), (Int, Int), Bool) -> [String]
groupRowFormatHelper (gname, (nl_size, il_size), (bn_size, bi_size), n1h) =
[ gname
, printf "%d" nl_size
, printf "%d" il_size
, printf "%d" bn_size
, printf "%d" bi_size
, show n1h ]
-- | Print node group information.
showGroupInfo :: Int -> Group.List -> Node.List -> Instance.List -> IO ()
showGroupInfo verbose gl nl il = do
let cgrs = map (\(gdx, (gnl, gil)) ->
calcGroupInfo (Container.find gdx gl) gnl gil) $
Cluster.splitCluster nl il
cn1h = all (\(_, _, _, n1h) -> n1h) cgrs
grs = map groupRowFormatHelper cgrs
header = ["Group", "Nodes", "Instances", "Bad_Nodes", "Bad_Instances",
"N+1"]
when (verbose > 1) $
printf "Node group information:\n%s"
(printTable " " header grs [False, True, True, True, True, False])
printf "Cluster is N+1 %s\n" $ if cn1h then "happy" else "unhappy"
-- | Gather and print split instances.
splitInstancesInfo :: Int -> Node.List -> Instance.List -> IO ()
splitInstancesInfo verbose nl il = do
let split_insts = Cluster.findSplitInstances nl il
......@@ -70,7 +111,7 @@ splitInstancesInfo verbose nl il = do
putStrLn "Found instances belonging to multiple node groups:"
mapM_ (\i -> hPutStrLn stderr $ " " ++ Instance.name i) split_insts
-- | Print common (interesting) information
-- | Print common (interesting) information.
commonInfo :: Int -> Group.List -> Node.List -> Instance.List -> IO ()
commonInfo verbose gl nl il = do
when (Container.null il && verbose > 1) $ do
......@@ -112,6 +153,8 @@ main opts args = do
splitInstancesInfo verbose nlf ilf
showGroupInfo verbose gl nlf ilf
maybePrintInsts showinsts "Instances" (Cluster.printInsts nlf ilf)
maybePrintNodes shownodes "Cluster" (Cluster.printNodes nlf)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment