github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/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, numOff, numOK uint 23 m.mutex.RLock() 24 for _, hypervisor := range m.hypervisors { 25 switch hypervisor.probeStatus { 26 case probeStatusConnected: 27 numConnected++ 28 switch hypervisor.healthStatus { 29 case "", "healthy": 30 numOK++ 31 } 32 case probeStatusOff: 33 numOff++ 34 } 35 } 36 numVMs := uint(len(m.vms)) 37 m.mutex.RUnlock() 38 writeCountLinksHT(writer, "Number of hypervisors known", 39 "listHypervisors?state=", numMachines) 40 writeCountLinksHT(writer, "Number of hypervisors powered off", 41 "listHypervisors?state=off", numOff) 42 writeCountLinksHT(writer, "Number of hypervisors connected", 43 "listHypervisors?state=connected", numConnected) 44 writeCountLinksHT(writer, "Number of hypervisors OK", 45 "listHypervisors?state=OK", numOK) 46 writeCountLinksHTJ(writer, "Number of VMs known", 47 "listVMs?", numVMs) 48 fmt.Fprintln(writer, `Hypervisor <a href="listLocations">locations</a><br>`) 49 } 50 51 func writeCountLinksHT(writer io.Writer, text, path string, count uint) { 52 if count < 1 { 53 return 54 } 55 fmt.Fprintf(writer, 56 "%s: <a href=\"%s\">%d</a> (<a href=\"%s&output=text\">text</a>)<br>\n", 57 text, path, count, path) 58 } 59 60 func writeCountLinksHTJ(writer io.Writer, text, path string, count uint) { 61 if count < 1 { 62 return 63 } 64 fmt.Fprintf(writer, 65 "%s: <a href=\"%s\">%d</a> (<a href=\"%s&output=text\">text</a>, <a href=\"%s&output=json\">JSON</a>)<br>\n", 66 text, path, count, path, path) 67 }