diff --git a/cmds/modules/zui/main.go b/cmds/modules/zui/main.go index 61aae0e59..ba08b706d 100644 --- a/cmds/modules/zui/main.go +++ b/cmds/modules/zui/main.go @@ -27,7 +27,7 @@ func (f *signalFlag) Signal() { atomic.SwapInt32((*int32)(f), 1) } -//Signaled checks if flag was raised, and lowers the flag +// Signaled checks if flag was raised, and lowers the flag func (f *signalFlag) Signaled() bool { return atomic.SwapInt32((*int32)(f), 0) == 1 } @@ -73,10 +73,10 @@ func action(ctx *cli.Context) error { netgrid.Title = "Network" netgrid.SetRect(0, 7, width, 14) - provision := ui.NewGrid() - provision.Title = "Provision" - provision.SetRect(0, 14, width, 20) - provision.Border = false + resources := ui.NewGrid() + resources.Title = "Provision" + resources.SetRect(0, 14, width, 22) + resources.Border = false var flag signalFlag @@ -88,12 +88,12 @@ func action(ctx *cli.Context) error { log.Error().Err(err).Msg("failed to start net renderer") } - if err := provisionRender(client, provision, &flag); err != nil { - log.Error().Err(err).Msg("failed to start net renderer") + if err := resourcesRender(client, resources, &flag); err != nil { + log.Error().Err(err).Msg("failed to start resources renderer") } render := func() { - ui.Render(header, netgrid, provision) + ui.Render(header, netgrid, resources) } render() diff --git a/cmds/modules/zui/prov.go b/cmds/modules/zui/prov.go index 0017c521d..dedd9d97b 100644 --- a/cmds/modules/zui/prov.go +++ b/cmds/modules/zui/prov.go @@ -8,64 +8,97 @@ import ( "github.com/gizak/termui/v3/widgets" "github.com/pkg/errors" "github.com/threefoldtech/zbus" + "github.com/threefoldtech/zos/pkg/gridtypes" "github.com/threefoldtech/zos/pkg/stubs" ) const ( gig = 1024 * 1024 * 1024.0 + mb = 1024 * 1024.0 ) -func provisionRender(client zbus.Client, grid *ui.Grid, render *signalFlag) error { +func resourcesRender(client zbus.Client, grid *ui.Grid, render *signalFlag) error { prov := widgets.NewTable() - prov.Title = "System Used Capacity" - prov.RowSeparator = false - - prov.Rows = [][]string{ - {"CPU Usage", "", "Memory Usage", ""}, - {"CRU Reserved", "", "MRU Reserved", ""}, - {"SSD Reserved", "", "HDD Reserved", ""}, - {"IPv4 Reserved", ""}, - } + usage := widgets.NewTable() grid.Set( ui.NewRow(1.0, - ui.NewCol(1, prov), + ui.NewCol(.6, prov), + ui.NewCol(.4, usage), ), ) - ctx := context.Background() + if err := provRender(client, render, prov); err != nil { + return errors.Wrap(err, "failed to render system provisioned resources") + } + + if err := usageRender(client, render, usage); err != nil { + return errors.Wrap(err, "failed to render system resources usage") + } + + return nil +} + +func provRender(client zbus.Client, render *signalFlag, prov *widgets.Table) error { + prov.Title = "System Resources" + prov.RowSeparator = false + + prov.Rows = [][]string{ + {"", "Total", "Reserved"}, + {"CRU", "", ""}, + {"Memory", "", ""}, + {"SSD", "", ""}, + {"HDD", "", ""}, + {"IPv4", "", ""}, + } monitor := stubs.NewStatisticsStub(client) - counters, err := monitor.ReservedStream(ctx) + + total := monitor.Total(context.Background()) + assignTotalResources(prov, total) + render.Signal() + + reserved, err := monitor.ReservedStream(context.Background()) if err != nil { return errors.Wrap(err, "failed to start net monitor stream") } go func() { - for counter := range counters { + for counter := range reserved { rows := prov.Rows - rows[1][1] = fmt.Sprint(counter.CRU) - rows[1][3] = fmt.Sprintf("%0.00f GB", float64(counter.MRU)/gig) - rows[2][1] = fmt.Sprintf("%0.00f GB", float64(counter.SRU)/gig) - rows[2][3] = fmt.Sprintf("%0.00f GB", float64(counter.HRU)/gig) - rows[3][1] = fmt.Sprint(counter.IPV4U) + rows[1][2] = fmt.Sprint(counter.CRU) + rows[2][2] = fmt.Sprintf("%0.00f GB", float64(counter.MRU)/gig) + rows[3][2] = fmt.Sprintf("%0.00f GB", float64(counter.SRU)/gig) + rows[4][2] = fmt.Sprintf("%0.00f GB", float64(counter.HRU)/gig) + rows[5][2] = fmt.Sprint(counter.IPV4U) render.Signal() } }() + return nil +} + +func usageRender(client zbus.Client, render *signalFlag, usage *widgets.Table) error { + usage.Title = "Usage" + usage.RowSeparator = false + usage.FillRow = true + + usage.Rows = [][]string{ + {"CPU", ""}, + {"Memory", ""}, + } + sysMonitor := stubs.NewSystemMonitorStub(client) - stream, err := sysMonitor.CPU(context.Background()) + cpuStream, err := sysMonitor.CPU(context.Background()) if err != nil { return errors.Wrap(err, "failed to start cpu monitor stream") } go func() { - for point := range stream { - prov.Mutex.Lock() - prov.Rows[0][1] = fmt.Sprintf("%0.00f%%", point.Percent) + for point := range cpuStream { + usage.Rows[0][1] = fmt.Sprintf("%0.00f%%", point.Percent) render.Signal() - prov.Mutex.Unlock() } }() @@ -76,10 +109,19 @@ func provisionRender(client zbus.Client, grid *ui.Grid, render *signalFlag) erro go func() { for point := range memStream { - prov.Rows[0][3] = fmt.Sprintf("%0.00f%%", point.UsedPercent) + usage.Rows[1][1] = fmt.Sprintf("%0.00f MB", float64(point.Used/mb)) render.Signal() } }() return nil } + +func assignTotalResources(prov *widgets.Table, total gridtypes.Capacity) { + rows := prov.Rows + rows[1][1] = fmt.Sprint(total.CRU) + rows[2][1] = fmt.Sprintf("%0.00f GB", float64(total.MRU)/gig) + rows[3][1] = fmt.Sprintf("%0.00f GB", float64(total.SRU)/gig) + rows[4][1] = fmt.Sprintf("%0.00f GB", float64(total.HRU)/gig) + rows[5][1] = fmt.Sprint(total.IPV4U) +} diff --git a/qemu/Makefile b/qemu/Makefile index 62c3266d7..a7f951146 100644 --- a/qemu/Makefile +++ b/qemu/Makefile @@ -8,7 +8,7 @@ zinit: kernel: @echo "Download 0-OS kernel" - wget https://bootstrap.grid.tf/kernel/zero-os-development-zos-v3-generic-7e587e499a.efi + wget https://bootstrap.grid.tf/kernel/zero-os-development-zos-v3-generic-0ad6c11534.efi start: bash vm.sh -n node1 -c "runmode=dev farmer_id=$(FARMERID)"