-
Notifications
You must be signed in to change notification settings - Fork 7
/
html.go
85 lines (81 loc) · 2.63 KB
/
html.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package manager
import (
"fmt"
"io"
"sort"
"strings"
"github.com/Cloud-Foundations/Dominator/lib/format"
"github.com/Cloud-Foundations/Dominator/lib/meminfo"
)
func (m *Manager) writeHtml(writer io.Writer) {
numRunning, numStopped := m.getNumVMs()
writeCountLinks(writer, "Number of VMs known", "listVMs?state=",
numRunning+numStopped)
writeCountLinks(writer, "Number of VMs running", "listVMs?state=running",
numRunning)
writeCountLinks(writer, "Number of VMs stopped", "listVMs?state=stopped",
numStopped)
fmt.Fprintln(writer, "<br>")
m.mutex.RLock()
memUnallocated := m.getUnallocatedMemoryInMiBWithLock()
numSubnets := len(m.subnets)
numFreeAddresses := len(m.addressPool.Free)
numRegisteredAddresses := len(m.addressPool.Registered)
ownerGroups := make([]string, 0, len(m.ownerGroups))
for group := range m.ownerGroups {
ownerGroups = append(ownerGroups, group)
}
ownerUsers := make([]string, 0, len(m.ownerUsers))
for user := range m.ownerUsers {
ownerUsers = append(ownerUsers, user)
}
m.mutex.RUnlock()
fmt.Fprintf(writer,
"Available addresses: <a href=\"listAvailableAddresses\">%d</a><br>\n",
numFreeAddresses)
fmt.Fprintf(writer,
"Registered addresses: <a href=\"listRegisteredAddresses\">%d</a><br>\n",
numRegisteredAddresses)
fmt.Fprintf(writer, "Available CPU: %g<br>\n",
float64(m.getAvailableMilliCPU())*1e-3)
if memInfo, err := meminfo.GetMemInfo(); err != nil {
fmt.Fprintf(writer, "Error getting available RAM: %s<br>\n", err)
} else {
fmt.Fprintf(writer, "Available RAM: real: %s, unallocated: %s<br>\n",
format.FormatBytes(memInfo.Available),
format.FormatBytes(memUnallocated<<20))
}
sort.Strings(ownerGroups)
sort.Strings(ownerUsers)
if len(ownerGroups) > 0 {
fmt.Fprintf(writer, "Owner groups: %s<br>\n",
strings.Join(ownerGroups, " "))
}
if len(ownerUsers) > 0 {
fmt.Fprintf(writer, "Owner users: %s<br>\n",
strings.Join(ownerUsers, " "))
}
if m.serialNumber != "" {
fmt.Fprintf(writer, "Serial number: \"%s\"<br>\n", m.serialNumber)
}
fmt.Fprintf(writer,
"Number of subnets: <a href=\"listSubnets\">%d</a><br>\n", numSubnets)
fmt.Fprint(writer, "Volume directories:")
for _, dirname := range m.volumeDirectories {
fmt.Fprint(writer, " ", dirname)
if m.volumeInfos[dirname].canTrim {
fmt.Fprint(writer, "(TRIM)")
}
}
fmt.Fprintln(writer, "<br>")
if m.objectCache == nil {
fmt.Fprintln(writer, "No object cache<br>")
} else {
m.objectCache.WriteHtml(writer)
}
}
func writeCountLinks(writer io.Writer, text, path string, count uint) {
fmt.Fprintf(writer,
"%s: <a href=\"%s\">%d</a> (<a href=\"%s&output=text\">text</a>)<br>\n",
text, path, count, path)
}