github.com/Cloud-Foundations/Dominator@v0.3.4/fleetmanager/hypervisors/dashboard.go (about) 1 package hypervisors 2 3 import ( 4 "fmt" 5 "io" 6 ) 7 8 func (m *Manager) writeHtml(writer io.Writer) { 9 t, err := m.getTopology() 10 if err != nil { 11 fmt.Fprintln(writer, err, "<br>") 12 return 13 } 14 if *manageHypervisors { 15 fmt.Fprintln(writer, 16 `Hypervisors <font color="green">are</font> being managed by this instance<br>`) 17 } else { 18 fmt.Fprintln(writer, 19 `<font color="grey">Hypervisors are not being managed by this instance</font><br>`) 20 } 21 numMachines := t.GetNumMachines() 22 var numConnected, numDisabled, numOff, numOK uint 23 m.mutex.RLock() 24 for _, hypervisor := range m.hypervisors { 25 switch hypervisor.probeStatus { 26 case probeStatusConnected: 27 numConnected++ 28 if hypervisor.disabled { 29 numDisabled++ 30 } 31 switch hypervisor.healthStatus { 32 case "", "healthy": 33 numOK++ 34 } 35 case probeStatusOff: 36 numOff++ 37 } 38 } 39 numVMs := uint(len(m.vms)) 40 m.mutex.RUnlock() 41 writeCountLinksHT(writer, "Number of hypervisors known", 42 "listHypervisors", numMachines) 43 writeCountLinksHT(writer, "Number of hypervisors powered off", 44 "listHypervisors?state=off", numOff) 45 writeCountLinksHT(writer, "Number of hypervisors connected", 46 "listHypervisors?state=connected", numConnected) 47 writeCountLinksHT(writer, "Number of hypervisors disabled", 48 "listHypervisors?state=disabled", numDisabled) 49 writeCountLinksHT(writer, "Number of hypervisors OK", 50 "listHypervisors?state=OK", numOK) 51 writeCountLinksHTJ(writer, "Number of VMs known", 52 "listVMs", numVMs) 53 writeLinksHTJ(writer, "VMs by primary owner", 54 "listVMsByPrimaryOwner", numVMs) 55 fmt.Fprintln(writer, `Hypervisor <a href="listLocations">locations</a>`) 56 fmt.Fprintln(writer, ` (<a href="listLocations?output=text">text</a>)<br>`) 57 } 58 59 func writeCountLinksHT(writer io.Writer, text, path string, count uint) { 60 if count < 1 { 61 return 62 } 63 fmt.Fprintf(writer, 64 "%s: <a href=\"%s\">%d</a> (<a href=\"%s&output=text\">text</a>)<br>\n", 65 text, path, count, path) 66 } 67 68 func writeCountLinksHTJ(writer io.Writer, text, path string, count uint) { 69 if count < 1 { 70 return 71 } 72 fmt.Fprintf(writer, 73 "%s: <a href=\"%s\">%d</a> (<a href=\"%s?output=text\">text</a>, <a href=\"%s?output=json\">JSON</a>)<br>\n", 74 text, path, count, path, path) 75 } 76 77 func writeLinksHTJ(writer io.Writer, text, path string, count uint) { 78 if count < 1 { 79 return 80 } 81 fmt.Fprintf(writer, 82 "%s: <a href=\"%s\">HTML</a>, <a href=\"%s?output=text\">text</a>, <a href=\"%s?output=json\">JSON</a><br>\n", 83 text, path, path, path) 84 }