コード例 #1
0
ファイル: topbroker.go プロジェクト: chendx79/gafka
func (this *TopBroker) drawDashboard() {
	termui.Init()
	width := termui.TermWidth()
	height := termui.TermHeight()
	termui.Close()
	maxWidth := width - 23

	var totalMaxQps, totalMaxBrokerQps float64
	for {
		time.Sleep(this.interval)

		this.startAll()
		this.collectAll()

		datas, maxQps, totalQps := this.showAndResetCounters()
		if maxQps < 1 {
			// draw empty lines
			for _, data := range datas {
				this.Ui.Output(fmt.Sprintf("%20s", data.host))
			}

			continue
		}

		if maxQps > totalMaxBrokerQps {
			totalMaxBrokerQps = maxQps
		}
		if totalQps > totalMaxQps {
			totalMaxQps = totalQps
		}

		refreshScreen()

		for idx, data := range datas {
			if idx >= height-2 {
				break
			}

			if data.qps < 0 {
				panic("negative qps")
			}

			this.renderQpsRow(data.host, data.qps, maxQps, maxWidth)
		}

		this.Ui.Output(fmt.Sprintf("%20s brokers:%d total:%s cum max[broker:%.1f total:%.1f]",
			"-SUMMARY-",
			len(datas), color.Green("%.1f", totalQps), totalMaxBrokerQps, totalMaxQps))
	}

}
コード例 #2
0
ファイル: dashboard.go プロジェクト: itnihao/zb
func drawDashboard() {
	hosts = HostsOfGroup(group)
	data = make([][]float64, len(hosts))

	// title
	titlePanel := ui.NewPar(fmt.Sprintf("%s: %s / %v", group, itemName, tick*dataSize))
	titlePanel.Height = titleHeight
	titlePanel.PaddingLeft = 1
	titlePanel.HasBorder = false
	titlePanel.TextFgColor = ui.ColorCyan

	// charts
	charts := make([]*ui.LineChart, 0)
	for i := 0; i < len(data); i++ {
		chart := ui.NewLineChart()
		chart.Border.Label = hosts[i].Name
		chart.Data = fetchData(i, dataSize)
		chart.Height = panelHeight
		chart.PaddingTop = chartPaddingTop
		chart.AxesColor = axesColor
		chart.LineColor = lineColor

		charts = append(charts, chart)
	}

	draw := func(size int) {
		if size > 0 {
			for i := 0; i < len(data); i++ {
				charts[i].Data = fetchData(i, size)
			}
		}

		ui.Render(ui.Body)
	}

	err := ui.Init()
	must(err)
	defer ui.Close()

	ui.UseTheme(uiTheme)

	// auto layout
	rows := make([]*ui.Row, 1)
	rows[0] = ui.NewRow(ui.NewCol(panelSpan*panelsPerRow, panelOffset, titlePanel))
	for i := 0; i < len(hosts); i += panelsPerRow {
		if i+1 == len(hosts) {
			// the last single panel
			rows = append(rows,
				ui.NewRow(ui.NewCol(panelSpan, panelOffset, charts[i])))
		} else {
			rows = append(rows,
				ui.NewRow(ui.NewCol(panelSpan, panelOffset, charts[i]),
					ui.NewCol(panelSpan, panelOffset, charts[i+1])))
		}

	}
	ui.Body.AddRows(rows...)
	ui.Body.Align()

	// draw the history data
	draw(0)

	evt := make(chan tm.Event)
	go func() {
		for {
			evt <- tm.PollEvent()
		}
	}()

	for {
		select {
		case e := <-evt:
			if e.Type == tm.EventKey && e.Ch == 'q' {
				return
			}
			if e.Type == tm.EventResize {
				ui.Body.Width = ui.TermWidth()
				ui.Body.Align()
			}

		case <-time.After(tick):
			draw(1)
		}
	}
}
コード例 #3
0
ファイル: top.go プロジェクト: funkygao/gafka
func (this *Top) drawDashboard() {
	err := termui.Init()
	swallow(err)
	defer termui.Close()

	termui.UseTheme("helloworld")

	maxRound := termui.TermWidth() / 2
	refreshProducerData := func(round int) []float64 {
		this.showAndResetCounters()
		if round%maxRound == (maxRound - 5) {
			this.mu.Lock()
			tailLen := len(this.totalMps) - 2
			tail := this.totalMps[tailLen:]
			this.totalMps = make([]float64, 2, 1000)
			copy(this.totalMps, tail)
			this.mu.Unlock()
		}
		return this.totalMps
	}

	refreshConsumerData := func(round int) []float64 {
		if round%maxRound == (maxRound - 5) {
			this.mu.Lock()
			tailLen := len(this.totalConsumerMps) - 2
			tail := this.totalConsumerMps[tailLen:]
			this.totalConsumerMps = make([]float64, 2, 1000)
			copy(this.totalConsumerMps, tail)
			this.mu.Unlock()
		}
		return this.totalConsumerMps
	}

	producerChart := termui.NewLineChart()
	producerChart.Mode = "dot"
	producerChart.Border.Label = fmt.Sprintf("producer mps totals: %s %s %s",
		this.zone, this.clusterPattern, this.topicPattern)
	producerChart.Data = refreshProducerData(0)
	producerChart.Width = termui.TermWidth() / 2
	producerChart.Height = termui.TermHeight()
	producerChart.X = 0
	producerChart.Y = 0
	producerChart.AxesColor = termui.ColorWhite
	producerChart.LineColor = termui.ColorGreen | termui.AttrBold

	consumerChart := termui.NewLineChart()
	consumerChart.Mode = "dot"
	consumerChart.Border.Label = fmt.Sprintf("consumer mps totals: %s %s %s",
		this.zone, this.clusterPattern, this.topicPattern)
	consumerChart.Data = refreshConsumerData(0)
	consumerChart.Width = termui.TermWidth() / 2
	consumerChart.Height = termui.TermHeight()
	consumerChart.X = termui.TermWidth() / 2
	consumerChart.Y = 0
	consumerChart.AxesColor = termui.ColorWhite
	consumerChart.LineColor = termui.ColorRed | termui.AttrBold

	evt := make(chan termbox.Event)
	go func() {
		for {
			evt <- termbox.PollEvent()
		}
	}()

	termui.Render(producerChart, consumerChart)
	tick := time.NewTicker(this.topInterval)
	defer tick.Stop()
	rounds := 0
	for {
		select {
		case e := <-evt:
			if e.Type == termbox.EventKey && e.Ch == 'q' {
				return
			}

		case <-tick.C:
			// refresh data, and skip the first 2 rounds
			rounds++
			if rounds > 1 {
				producerChart.Data = refreshProducerData(rounds)
				consumerChart.Data = refreshConsumerData(rounds)
				termui.Render(producerChart, consumerChart)
			}

		}
	}
}