in pkg/model/cluster.go [117:164]
func (c *Cluster) Stats() Stats {
c.mu.RLock()
defer c.mu.RUnlock()
st := Stats{
AllocatableResources: v1.ResourceList{},
UsedResources: v1.ResourceList{},
PercentUsedResoruces: map[v1.ResourceName]float64{},
PodsByPhase: map[v1.PodPhase]int{},
}
for _, p := range c.pods {
// skip pods bound to non-visible nodes
if n, ok := c.nodes[p.NodeName()]; ok && !n.Visible() {
continue
}
st.TotalPods++
st.PodsByPhase[p.Phase()]++
if p.NodeName() != "" {
st.BoundPodCount++
}
}
for _, n := range c.nodes {
if !n.Visible() {
continue
}
// only add the price if it's not NaN which is used to indicate an unknown
// price
if n.Price == n.Price {
st.TotalPrice += n.Price
}
st.NumNodes++
st.Nodes = append(st.Nodes, n)
addResources(st.AllocatableResources, n.Allocatable())
addResources(st.UsedResources, n.Used())
}
sort.Slice(st.Nodes, func(a, b int) bool {
aCreated := st.Nodes[a].Created()
bCreated := st.Nodes[b].Created()
if aCreated == bCreated {
return st.Nodes[a].Name() < st.Nodes[b].Name()
}
return st.Nodes[a].Created().Before(st.Nodes[b].Created())
})
return st
}