Revision 3c0687b5
b/htools/Ganeti/HTools/Program/Hcheck.hs | ||
---|---|---|
114 | 114 |
levelPrefix GroupLvl = "GROUP" |
115 | 115 |
levelPrefix ClusterLvl = "CLUSTER" |
116 | 116 |
|
117 |
-- | Machine-readable keys to show depending on given level. |
|
118 |
keysData :: Level -> [String] |
|
119 |
keysData GroupLvl = map fst groupData |
|
120 |
keysData ClusterLvl = map fst clusterData |
|
121 |
|
|
117 | 122 |
-- | Description of phases for human readable version. |
118 | 123 |
phaseDescr :: Phase -> String |
119 | 124 |
phaseDescr Initial = "initially" |
120 | 125 |
phaseDescr Rebalanced = "after rebalancing" |
121 | 126 |
|
127 |
-- | Description to show depending on given level. |
|
128 |
descrData :: Level -> [String] |
|
129 |
descrData GroupLvl = map snd groupData |
|
130 |
descrData ClusterLvl = map snd clusterData |
|
131 |
|
|
132 |
-- | Human readable prefix for statistics. |
|
133 |
phaseLevelDescr :: Phase -> Level -> Maybe String -> String |
|
134 |
phaseLevelDescr phase GroupLvl (Just name) = |
|
135 |
printf "Statistics for group %s %s\n" name $ phaseDescr phase |
|
136 |
phaseLevelDescr phase GroupLvl Nothing = |
|
137 |
printf "Statistics for group %s\n" $ phaseDescr phase |
|
138 |
phaseLevelDescr phase ClusterLvl _ = |
|
139 |
printf "Cluster statistics %s\n" $ phaseDescr phase |
|
122 | 140 |
|
123 | 141 |
-- | Format a list of key, value as a shell fragment. |
124 | 142 |
printKeysHTC :: [(String, String)] -> IO () |
... | ... | |
140 | 158 |
printpairs = map extract_vals (Container.elems gl) |
141 | 159 |
printKeysHTC printpairs |
142 | 160 |
|
143 |
-- | Print all the statistics on a group level. |
|
144 |
printGroupStats :: Int -> Bool -> Phase -> Group.Group -> [Int] -> Double -> IO () |
|
145 |
printGroupStats _ True phase grp stats score = do |
|
146 |
let printstats = map (printf "%d") stats ++ [printf "%.8f" score] :: [String] |
|
147 |
printkeys = map (printf "%s_%s_%d_%s" |
|
148 |
(phasePrefix phase) |
|
149 |
(levelPrefix GroupLvl) |
|
150 |
(Group.idx grp)) |
|
151 |
(map fst groupData) :: [String] |
|
152 |
printKeysHTC (zip printkeys printstats) |
|
153 |
|
|
154 |
printGroupStats verbose False phase grp stats score = do |
|
155 |
let printstats = map (printf "%d") stats ++ [printf "%.8f" score] :: [String] |
|
156 |
|
|
161 |
-- | Prepare a single key given a certain level and phase of simulation. |
|
162 |
prepareKey :: Level -> Phase -> Maybe String -> String -> String |
|
163 |
prepareKey level phase Nothing suffix = |
|
164 |
printf "%s_%s_%s" (phasePrefix phase) (levelPrefix level) suffix |
|
165 |
prepareKey level phase (Just idx) suffix = |
|
166 |
printf "%s_%s_%s_%s" (phasePrefix phase) (levelPrefix level) idx suffix |
|
167 |
|
|
168 |
-- | Print all the statistics for given level and phase. |
|
169 |
printStats :: Int -- ^ Verbosity level |
|
170 |
-> Bool -- ^ If the output should be machine readable |
|
171 |
-> Level -- ^ Level on which we are printing |
|
172 |
-> Phase -- ^ Current phase of simulation |
|
173 |
-> [String] -- ^ Values to print |
|
174 |
-> Maybe String -- ^ Additional data for groups |
|
175 |
-> IO () |
|
176 |
printStats _ True level phase values gidx = do |
|
177 |
let keys = map (prepareKey level phase gidx) (keysData level) |
|
178 |
printKeysHTC $ zip keys values |
|
179 |
|
|
180 |
printStats verbose False level phase values name = do |
|
181 |
let prefix = phaseLevelDescr phase level name |
|
182 |
descr = descrData level |
|
157 | 183 |
unless (verbose == 0) $ do |
158 |
printf "\nStatistics for group %s %s\n" |
|
159 |
(Group.name grp) (phaseDescr phase) :: IO () |
|
160 |
mapM_ (\(a,b) -> printf " %s: %s\n" (snd a) b :: IO ()) |
|
161 |
(zip groupData printstats) |
|
184 |
printf "\n%s" prefix :: IO () |
|
185 |
mapM_ (\(a,b) -> printf " %s: %s\n" a b) (zip descr values) |
|
186 |
|
|
187 |
-- | Extract name or idx from group. |
|
188 |
extractGroupData :: Bool -> Group.Group -> String |
|
189 |
extractGroupData True grp = printf "%d" $ Group.idx grp |
|
190 |
extractGroupData False grp = Group.name grp |
|
191 |
|
|
192 |
-- | Prepare values for group. |
|
193 |
prepareGroupValues :: [Int] -> Double -> [String] |
|
194 |
prepareGroupValues stats score = |
|
195 |
map (printf "%d") stats ++ [printf "%.8f" score] |
|
196 |
|
|
197 |
-- | Prepare values for cluster. |
|
198 |
prepareClusterValues :: Bool -> [Int] -> [Bool] -> [String] |
|
199 |
prepareClusterValues machineread stats bstats = |
|
200 |
map (printf "%d") stats ++ map (printBool machineread) bstats |
|
201 |
|
|
202 |
-- | Print all the statistics on a group level. |
|
203 |
printGroupStats :: Int -> Bool -> Phase -> Group.Group -> [Int] -> Double |
|
204 |
-> IO () |
|
205 |
printGroupStats verbose machineread phase grp stats score = do |
|
206 |
let values = prepareGroupValues stats score |
|
207 |
extradata = extractGroupData machineread grp |
|
208 |
printStats verbose machineread GroupLvl phase values (Just extradata) |
|
162 | 209 |
|
163 | 210 |
-- | Print all the statistics on a cluster (global) level. |
164 | 211 |
printClusterStats :: Int -> Bool -> Phase -> [Int] -> Bool -> Bool -> IO () |
165 |
printClusterStats _ True phase stats needrebal canrebal = do |
|
166 |
let printstats = map (printf "%d") stats ++ |
|
167 |
map (printBool True) [needrebal, canrebal] |
|
168 |
printkeys = map (printf "%s_%s_%s" |
|
169 |
(phasePrefix phase) |
|
170 |
(levelPrefix ClusterLvl)) |
|
171 |
(map fst clusterData) :: [String] |
|
172 |
printKeysHTC (zip printkeys printstats) |
|
173 |
|
|
174 |
printClusterStats verbose False phase stats needrebal canrebal = do |
|
175 |
let printstats = map (printf "%d") stats ++ |
|
176 |
map (printBool False) [needrebal, canrebal] |
|
177 |
unless (verbose == 0) $ do |
|
178 |
printf "\nCluster statistics %s\n" (phaseDescr phase) :: IO () |
|
179 |
mapM_ (\(a,b) -> printf " %s: %s\n" (snd a) b :: IO ()) |
|
180 |
(zip clusterData printstats) |
|
212 |
printClusterStats verbose machineread phase stats needhbal canhbal = do |
|
213 |
let values = prepareClusterValues machineread stats [needhbal, canhbal] |
|
214 |
printStats verbose machineread ClusterLvl phase values Nothing |
|
181 | 215 |
|
182 | 216 |
-- | Check if any of cluster metrics is non-zero. |
183 | 217 |
clusterNeedsRebalance :: [Int] -> Bool |
Also available in: Unified diff