Revision 179c0828 htools/Ganeti/HTools/Program/Hspace.hs
b/htools/Ganeti/HTools/Program/Hspace.hs | ||
---|---|---|
48 | 48 |
import Ganeti.HTools.ExtLoader |
49 | 49 |
import Ganeti.HTools.Loader |
50 | 50 |
|
51 |
-- | Options list and functions |
|
51 |
-- | Options list and functions.
|
|
52 | 52 |
options :: [OptType] |
53 | 53 |
options = |
54 | 54 |
[ oPrintNodes |
... | ... | |
110 | 110 |
cpuEff :: Cluster.CStats -> Double |
111 | 111 |
cpuEff = effFn Cluster.csIcpu (fromIntegral . Cluster.csVcpu) |
112 | 112 |
|
113 |
-- | Holds data for converting a 'Cluster.CStats' structure into |
|
114 |
-- detailed statictics. |
|
113 | 115 |
statsData :: [(String, Cluster.CStats -> String)] |
114 | 116 |
statsData = [ ("SCORE", printf "%.8f" . Cluster.csScore) |
115 | 117 |
, ("INST_CNT", printf "%d" . Cluster.csNinst) |
... | ... | |
133 | 135 |
, ("MNODE_DSK_AVAIL", printf "%d" . Cluster.csMdsk) |
134 | 136 |
] |
135 | 137 |
|
138 |
-- | List holding 'RSpec' formatting information. |
|
136 | 139 |
specData :: [(String, RSpec -> String)] |
137 | 140 |
specData = [ ("MEM", printf "%d" . rspecMem) |
138 | 141 |
, ("DSK", printf "%d" . rspecDsk) |
139 | 142 |
, ("CPU", printf "%d" . rspecCpu) |
140 | 143 |
] |
141 | 144 |
|
145 |
-- | List holding 'Cluster.CStats' formatting information. |
|
142 | 146 |
clusterData :: [(String, Cluster.CStats -> String)] |
143 | 147 |
clusterData = [ ("MEM", printf "%.0f" . Cluster.csTmem) |
144 | 148 |
, ("DSK", printf "%.0f" . Cluster.csTdsk) |
... | ... | |
146 | 150 |
, ("VCPU", printf "%d" . Cluster.csVcpu) |
147 | 151 |
] |
148 | 152 |
|
149 |
-- | Function to print stats for a given phase |
|
153 |
-- | Function to print stats for a given phase.
|
|
150 | 154 |
printStats :: Phase -> Cluster.CStats -> [(String, String)] |
151 | 155 |
printStats ph cs = |
152 | 156 |
map (\(s, fn) -> (printf "%s_%s" kind s, fn cs)) statsData |
... | ... | |
211 | 215 |
map (\(spec, cnt) -> printf "%d,%d,%d=%d" (rspecMem spec) |
212 | 216 |
(rspecDsk spec) (rspecCpu spec) cnt) |
213 | 217 |
|
218 |
-- | Formats \"key-metrics\" values. |
|
214 | 219 |
formatRSpec :: Double -> String -> RSpec -> [(String, String)] |
215 | 220 |
formatRSpec m_cpu s r = |
216 | 221 |
[ ("KM_" ++ s ++ "_CPU", show $ rspecCpu r) |
... | ... | |
219 | 224 |
, ("KM_" ++ s ++ "_DSK", show $ rspecDsk r) |
220 | 225 |
] |
221 | 226 |
|
227 |
-- | Shows allocations stats. |
|
222 | 228 |
printAllocationStats :: Double -> Node.List -> Node.List -> IO () |
223 | 229 |
printAllocationStats m_cpu ini_nl fin_nl = do |
224 | 230 |
let ini_stats = Cluster.totalResources ini_nl |
... | ... | |
228 | 234 |
printKeys $ formatRSpec m_cpu "POOL"ralo |
229 | 235 |
printKeys $ formatRSpec m_cpu "UNAV" runa |
230 | 236 |
|
231 |
-- | Ensure a value is quoted if needed |
|
237 |
-- | Ensure a value is quoted if needed.
|
|
232 | 238 |
ensureQuoted :: String -> String |
233 | 239 |
ensureQuoted v = if not (all (\c -> isAlphaNum c || c == '.') v) |
234 | 240 |
then '\'':v ++ "'" |
235 | 241 |
else v |
236 | 242 |
|
237 |
-- | Format a list of key\/values as a shell fragment |
|
243 |
-- | Format a list of key\/values as a shell fragment.
|
|
238 | 244 |
printKeys :: [(String, String)] -> IO () |
239 | 245 |
printKeys = mapM_ (\(k, v) -> |
240 | 246 |
printf "HTS_%s=%s\n" (map toUpper k) (ensureQuoted v)) |
241 | 247 |
|
248 |
-- | Converts instance data to a list of strings. |
|
242 | 249 |
printInstance :: Node.List -> Instance.Instance -> [String] |
243 | 250 |
printInstance nl i = [ Instance.name i |
244 | 251 |
, Container.nameOf nl $ Instance.pNode i |
... | ... | |
250 | 257 |
, show (Instance.vcpus i) |
251 | 258 |
] |
252 | 259 |
|
253 |
-- | Optionally print the allocation map |
|
260 |
-- | Optionally print the allocation map.
|
|
254 | 261 |
printAllocationMap :: Int -> String |
255 | 262 |
-> Node.List -> [Instance.Instance] -> IO () |
256 | 263 |
printAllocationMap verbose msg nl ixes = |
... | ... | |
314 | 321 |
printClusterScores ini_nl fin_nl |
315 | 322 |
printClusterEff (Cluster.totalResources fin_nl) |
316 | 323 |
|
324 |
-- | Displays the initial/final cluster scores. |
|
317 | 325 |
printClusterScores :: Node.List -> Node.List -> IO () |
318 | 326 |
printClusterScores ini_nl fin_nl = do |
319 | 327 |
printf " - initial cluster score: %.8f\n" $ Cluster.compCV ini_nl::IO () |
320 | 328 |
printf " - final cluster score: %.8f\n" $ Cluster.compCV fin_nl |
321 | 329 |
|
330 |
-- | Displays the cluster efficiency. |
|
322 | 331 |
printClusterEff :: Cluster.CStats -> IO () |
323 | 332 |
printClusterEff cs = |
324 | 333 |
mapM_ (\(s, fn) -> |
Also available in: Unified diff