Revision 92eacdd8 htools/Ganeti/HTools/Program/Hcheck.hs
b/htools/Ganeti/HTools/Program/Hcheck.hs | ||
---|---|---|
113 | 113 |
|
114 | 114 |
-- | Data showed per cluster. |
115 | 115 |
clusterData :: [(String, String)] |
116 |
clusterData = commonData ++ [("NEED_REBALANCE", "Cluster is not healthy")] |
|
116 |
clusterData = commonData ++ |
|
117 |
[ ("NEED_REBALANCE", "Cluster is not healthy") |
|
118 |
, ("CAN_REBALANCE", "Possible to run rebalance") |
|
119 |
] |
|
120 |
|
|
117 | 121 |
|
118 | 122 |
-- | Format a list of key, value as a shell fragment. |
119 | 123 |
printKeysHTC :: [(String, String)] -> IO () |
120 | 124 |
printKeysHTC = printKeys htcPrefix |
121 | 125 |
|
126 |
-- | Prepare string from boolean value. |
|
127 |
printBool :: Bool -- ^ Whether the result should be machine readable |
|
128 |
-> Bool -- ^ Value to be converted to string |
|
129 |
-> String |
|
130 |
printBool True True = "1" |
|
131 |
printBool True False = "0" |
|
132 |
printBool False b = show b |
|
133 |
|
|
122 | 134 |
-- | Print all the statistics on a group level. |
123 | 135 |
printGroupStats :: Int -> Bool -> Phase -> Gdx -> [Int] -> Double -> IO () |
124 | 136 |
printGroupStats _ True phase gidx stats score = do |
... | ... | |
140 | 152 |
(zip groupData printstats) |
141 | 153 |
|
142 | 154 |
-- | Print all the statistics on a cluster (global) level. |
143 |
printClusterStats :: Int -> Bool -> Phase -> [Int] -> IO (Bool) |
|
144 |
printClusterStats _ True phase stats = do |
|
145 |
let needrebal = sum stats |
|
146 |
printstats = map (printf "%d") $ stats ++ [needrebal]
|
|
147 |
:: [String]
|
|
155 |
printClusterStats :: Int -> Bool -> Phase -> [Int] -> Bool -> IO (Bool)
|
|
156 |
printClusterStats _ True phase stats canrebal = do
|
|
157 |
let needrebal = sum stats > 0
|
|
158 |
printstats = map (printf "%d") stats ++
|
|
159 |
map (printBool True) [needrebal, canrebal]
|
|
148 | 160 |
printkeys = map (printf "%s_%s_%s" |
149 | 161 |
(phasePrefix phase) |
150 | 162 |
(levelPrefix ClusterLvl)) |
151 | 163 |
(map fst clusterData) :: [String] |
152 | 164 |
printKeysHTC (zip printkeys printstats) |
153 |
return $ needrebal > 0
|
|
165 |
return needrebal
|
|
154 | 166 |
|
155 |
printClusterStats verbose False phase stats = do |
|
156 |
let needrebal = sum stats |
|
157 |
printstats = map (printf "%d") stats :: [String] |
|
167 |
printClusterStats verbose False phase stats canrebal = do |
|
168 |
let needrebal = sum stats > 0 |
|
169 |
printstats = map (printf "%d") stats ++ |
|
170 |
map (printBool False) [needrebal, canrebal] |
|
158 | 171 |
unless (verbose == 0) $ do |
159 | 172 |
printf "\nCluster statistics %s\n" (phaseDescription phase) :: IO () |
160 | 173 |
mapM_ (\(a,b) -> printf " %s: %s\n" (snd a) b :: IO ()) |
161 |
(zip clusterData (printstats ++ [show (needrebal>0)]))
|
|
162 |
return $ needrebal > 0
|
|
174 |
(zip clusterData printstats)
|
|
175 |
return needrebal
|
|
163 | 176 |
|
164 | 177 |
{- | Check group for N+1 hapiness, conflicts of primaries on nodes and |
165 | 178 |
instances residing on offline nodes. |
... | ... | |
233 | 246 |
|
234 | 247 |
groupsstats <- mapM (perGroupChecks verbose machineread Initial) splitcluster |
235 | 248 |
let clusterstats = map sum (transpose groupsstats) :: [Int] |
236 |
needrebalance <- printClusterStats verbose machineread Initial clusterstats |
|
249 |
canrebalance = length splitinstances == 0 |
|
250 |
needrebalance <- printClusterStats verbose machineread Initial clusterstats canrebalance |
|
237 | 251 |
|
238 | 252 |
when nosimulation $ do |
239 | 253 |
unless (verbose == 0 || machineread) $ |
... | ... | |
256 | 270 |
newgroupstats <- mapM (perGroupChecks verbose machineread Rebalanced) |
257 | 271 |
rebalancedcluster |
258 | 272 |
let newclusterstats = map sum (transpose newgroupstats) :: [Int] |
259 |
_ <- printClusterStats verbose machineread Rebalanced newclusterstats |
|
273 |
_ <- printClusterStats verbose machineread Rebalanced newclusterstats canrebalance
|
|
260 | 274 |
|
261 | 275 |
printFinalHTC machineread |
Also available in: Unified diff