Example #1
0
File: server.go Project: rzh/montu
func (w *ServerWidget) Init() {
	// something
	w.server = gen.MonitorServer(w.addr)

	w.data = make([][]int, SPARKLINE_COUNT, SPARKLINE_COUNT)
	w.spl = make([]termui.Sparkline, SPARKLINE_COUNT, SPARKLINE_COUNT)

	for i := 0; i < SPARKLINE_COUNT; i++ {
		w.data[i] = make([]int, 60, 60)
	}

	w.spl[0] = makeSparkline(" Ops/s", w.data[0], termui.ColorGreen)
	w.spl[1] = makeSparkline(" % CPU", w.data[1], termui.ColorRed)
	w.spl[2] = makeSparkline(" % DISK_dbs", w.data[2], termui.ColorMagenta)
	w.spl[3] = makeSparkline(" % DISK_journal", w.data[3], termui.ColorCyan)

	// group
	spls1 := termui.NewSparklines()
	spls1.Height = 10
	spls1.Width = 20
	spls1.Y = 3
	spls1.Border.Label = "> " + w.title + " <"

	w.bc = spls1

	go func() {
		for {
			stat := w.server.GetStats()

			w.data[0] = append(w.data[0][1:len(w.data[0])], stat.OPS)               // OPS
			w.data[1] = append(w.data[1][1:len(w.data[1])], stat.P_CPU)             // CPU
			w.data[2] = append(w.data[2][1:len(w.data[2])], stat.P_DISK_dbs)        // DISK_dbs
			w.data[3] = append(w.data[3][1:len(w.data[3])], stat.P_DISK_journal)    // DISK_journal
			w.data[4] = append(w.data[4][1:len(w.data[4])], int(rand.Int63n(90))+5) // NET

			// set max/min to 100, FIXME
			w.data[0][0] = 100
			w.data[1][0] = 100
			w.data[2][0] = 100
			w.data[3][0] = 100
			w.data[4][0] = 100

			for i := 0; i < SPARKLINE_COUNT; i++ {
				w.spl[i].Data = w.data[i]
			}

			w.bc.Lines = w.spl
			time.Sleep(1 * time.Second)
		}
	}()
}
Example #2
0
File: dash.go Project: rzh/montu
func (w *DashWidget) Init() {
	w.server = gen.MonitorServer("ms")
	w.p1 = gen.MonitorServer("p1")

	par3 := termui.NewPar("")
	par3.Height = 17
	par3.Width = 137
	par3.Y = 9
	par3.Border.Label = "> Stats Dashboard: <"

	par3.Text = ""

	w.bc = par3

	go func() {
		for {
			// TODO: refresh data here via channel or something
			stats := w.server.GetStats()
			stats_p1 := w.p1.GetStats()

			/*
				w.bc.Text += fmt.Sprintf("  CPU        : %5d%%", stats.P_CPU)              ; w.bc.Text += fmt.Sprintf("  |   CPU        : %5d%%\n", stats_p1.P_CPU)
				w.bc.Text += fmt.Sprintf("  MEM        : %5d%%", stats.P_MEM)              ; w.bc.Text += fmt.Sprintf("  |   MEM        : %5d%%\n", stats_p1.P_MEM)
				w.bc.Text += fmt.Sprintf("  DSK(dbs)   : %5d%%", stats.P_DISK_dbs)         ; w.bc.Text += fmt.Sprintf("  |   DSK(dbs)   : %5d%%\n", stats_p1.P_DISK_dbs)
				w.bc.Text += fmt.Sprintf("  DSK(jnl)   : %5d%%", stats.P_DISK_journal)     ; w.bc.Text += fmt.Sprintf("  |   DSK(jnl)   : %5d%%\n", stats_p1.P_DISK_journal)
				w.bc.Text += fmt.Sprintf("  OPS        : %5d ", stats.OPS)                 ; w.bc.Text += fmt.Sprintf("  |   OPS        : %5d\n", stats_p1.OPS)
				w.bc.Text += fmt.Sprintf("   - insert  : %5d ", stats.OPS_insert)          ; w.bc.Text += fmt.Sprintf("  |    - insert  : %5d\n", stats_p1.OPS_insert)
				w.bc.Text += fmt.Sprintf("   - query   : %5d ", stats.OPS_query)           ; w.bc.Text += fmt.Sprintf("  |    - query   : %5d\n", stats_p1.OPS_query)
				w.bc.Text += fmt.Sprintf("   - update  : %5d ", stats.OPS_update)          ; w.bc.Text += fmt.Sprintf("  |    - update  : %5d\n", stats_p1.OPS_update)
				w.bc.Text += fmt.Sprintf("   - getmore : %5d ", stats.OPS_getmore)         ; w.bc.Text += fmt.Sprintf("  |    - getmore : %5d\n", stats_p1.OPS_getmore)
				w.bc.Text += fmt.Sprintf("   - delete  : %5d ", stats.OPS_delete)          ; w.bc.Text += fmt.Sprintf("  |    - delete  : %5d\n", stats_p1.OPS_delete)
				w.bc.Text += fmt.Sprintf("   - command : %5d ", stats.OPS_command)         ; w.bc.Text += fmt.Sprintf("  |    - command : %5d\n", stats_p1.OPS_command)
			*/
			w.bc.Text = "\nmongos:                |   Shard_1_primary:\n-----------------------|-----------------------\n"

			w.bc.Text += fmt.Sprintf("  CPU        : %5d%%", stats.P_CPU)
			w.bc.Text += fmt.Sprintf("  |   CPU        : %5d%%\n", stats_p1.P_CPU)
			w.bc.Text += fmt.Sprintf("  MEM        : %5d%%", stats.P_MEM)
			w.bc.Text += fmt.Sprintf("  |   MEM        : %5d%%\n", stats_p1.P_MEM)
			w.bc.Text += fmt.Sprintf("  DSK(dbs)   : %5d%%", stats.P_DISK_dbs)
			w.bc.Text += fmt.Sprintf("  |   DSK(dbs)   : %5d%%\n", stats_p1.P_DISK_dbs)
			w.bc.Text += fmt.Sprintf("  DSK(jnl)   : %5d%%", stats.P_DISK_journal)
			w.bc.Text += fmt.Sprintf("  |   DSK(jnl)   : %5d%%\n", stats_p1.P_DISK_journal)
			w.bc.Text += fmt.Sprintf("  OPS        : %5d ", stats.OPS)
			w.bc.Text += fmt.Sprintf("  |   OPS        : %5d\n", stats_p1.OPS)
			w.bc.Text += fmt.Sprintf("   - insert  : %5d ", stats.OPS_insert)
			w.bc.Text += fmt.Sprintf("  |    - insert  : %5d\n", stats_p1.OPS_insert)
			w.bc.Text += fmt.Sprintf("   - query   : %5d ", stats.OPS_query)
			w.bc.Text += fmt.Sprintf("  |    - query   : %5d\n", stats_p1.OPS_query)
			w.bc.Text += fmt.Sprintf("   - update  : %5d ", stats.OPS_update)
			w.bc.Text += fmt.Sprintf("  |    - update  : %5d\n", stats_p1.OPS_update)
			w.bc.Text += fmt.Sprintf("   - getmore : %5d ", stats.OPS_getmore)
			w.bc.Text += fmt.Sprintf("  |    - getmore : %5d\n", stats_p1.OPS_getmore)
			w.bc.Text += fmt.Sprintf("   - delete  : %5d ", stats.OPS_delete)
			w.bc.Text += fmt.Sprintf("  |    - delete  : %5d\n", stats_p1.OPS_delete)
			w.bc.Text += fmt.Sprintf("   - command : %5d ", stats.OPS_command)
			w.bc.Text += fmt.Sprintf("  |    - command : %5d\n", stats_p1.OPS_command)

			time.Sleep(1 * time.Second)
		}
	}()
}
Example #3
0
File: rps.go Project: rzh/montu
func (w *RPSWidget) Init() {
	w.server = gen.MonitorServer(w.addr)

	bc := termui.NewBarChart()
	data := []int{3, 2, 5, 3, 9, 5, 3, 2, 5, 8, 3, 2, 4, 5, 3, 2, 5, 7, 5, 3, 2, 6, 7, 4, 6, 3, 6, 7, 8, 3, 6, 4, 5, 3, 2, 4, 6, 4, 8, 5, 9, 4, 3, 6, 5, 3, 6}
	bclabels := []string{"INS", "QRY", "UPD", "DEL", "GTM", "", "CPU", "MEM", "DSK"}
	bc.Border.Label = "> " + w.title + " <"
	bc.Border.FgColor = termui.ColorCyan
	bc.Data = data
	bc.Width = 30
	bc.Height = 10
	bc.SetMax(100)
	bc.DataLabels = bclabels
	//	bc.BgColor = termui.ColorBlack
	bc.TextColor = termui.ColorYellow
	bc.BarColor = termui.ColorRed
	bc.NumColor = termui.ColorRed

	w.bc = bc

	go func() {
		for {
			// TODO: refresh data here via channel or something
			var data []int
			stats := w.server.GetStats()

			for i := 0; i < len(bclabels); i++ {
				if bclabels[i] != "" {
					switch bclabels[i] {

					case "CPU":
						c := stats.P_CPU
						if stats.OPS > 100 && c > 10 {
							c = int(float64(stats.OPS) * (float64(c) / 100.0))
						}
						data = append(data, c)
					case "MEM":
						c := stats.P_MEM
						if stats.OPS > 100 {
							c = int(float64(stats.OPS) * (float64(c) / 100.0))
						}
						data = append(data, c)
					case "INS":
						data = append(data, stats.OPS_insert)
					case "QRY":
						data = append(data, stats.OPS_query)
					case "UPD":
						data = append(data, stats.OPS_update)
					case "GTM":
						data = append(data, stats.OPS_getmore)
					case "DEL":
						data = append(data, stats.OPS_delete)
					case "DSK":
						c := (stats.P_DISK_dbs + stats.P_DISK_journal) / 2
						if stats.OPS > 100 {
							c = int(float64(stats.OPS) * (float64(c) / 100.0))
						}
						data = append(data, c)
					default:
						data = append(data, rand.Intn(100))
					}
				} else {
					data = append(data, 0)
				}
			}

			w.bc.Data = data
			time.Sleep(1 * time.Second)
		}
	}()
}