summaryrefslogtreecommitdiffstats
path: root/termui/gauge.go
blob: 566768644bd565e404f953ff71d2f55ac1cbb240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package termui

import (
	"strconv"
)

// Gauge is a progress bar like widget.
type Gauge struct {
	*Block
	Percent     int
	GaugeColor  Color
	Description string
}

// NewGauge return a new gauge with current theme.
func NewGauge() *Gauge {
	return &Gauge{
		Block:      NewBlock(),
		GaugeColor: Theme.GaugeColor,
	}
}

// Buffer implements Bufferer interface.
func (g *Gauge) Buffer() *Buffer {
	buf := g.Block.Buffer()

	// plot bar
	width := g.Percent * g.X / 100
	for y := 1; y <= g.Y; y++ {
		for x := 1; x <= width; x++ {
			buf.SetCell(x, y, Cell{' ', g.GaugeColor, g.GaugeColor})
		}
	}

	// plot percentage
	s := strconv.Itoa(g.Percent) + "%" + g.Description
	s = MaxString(s, g.X)

	y := (g.Y + 1) / 2
	x := ((g.X - len(s)) + 1) / 2

	for i, char := range s {
		bg := g.Bg
		fg := g.Fg
		if x+i < width {
			fg = g.GaugeColor
			bg = AttrReverse
		}
		buf.SetCell(1+x+i, y, Cell{char, fg, bg})
	}

	return buf
}
t it here, the memory mode of netdata.conf will be used. # Valid modes: # save save on exit, load on start # map like swap (continuously syncing to disks) # ram keep it in RAM, don't touch the disk # none no database at all (use this on headless proxies) default memory mode = ram # Shall we enable health monitoring for the hosts using this API key? # 3 possible values: # yes enable alarms # no do not enable alarms # auto enable alarms, only when the sending netdata is connected # You can also set it per host, below. # The default is the same as to netdata.conf health enabled by default = auto # postpone alarms for a short period after the sender is connected default postpone alarms on connect seconds = 60 # allow or deny multiple connections for the same host? # If you are sure all your netdata have their own machine GUID, # set this to 'allow', since it allows faster reconnects. # When set to 'deny', new connections for a host will not be # accepted until an existing connection is cleared. multiple connections = allow # need to route metrics differently? set these. # the defaults are the ones at the [stream] section #default proxy enabled = yes | no #default proxy destination = IP:PORT IP:PORT ... #default proxy api key = API_KEY # ----------------------------------------------------------------------------- # 3. PER SENDING HOST SETTINGS, ON MASTER NETDATA # THIS IS OPTIONAL - YOU DON'T NEED IT # This section exists to give you finer control of the master settings for each # slave host, when the same API key is used by many netdata slaves / proxies. # # Each netdata has a unique GUID - generated the first time netdata starts. # You can find it at /var/lib/netdata/registry/netdata.public.unique.id # (at the slave). # # The host sending data will have one. If the host is not ephemeral, # you can give settings for each sending host here. [MACHINE_GUID] # enable this host: yes | no # When disabled, the master will not receive metrics for this host. # THIS IS NOT A SECURITY MECHANISM - AN ATTACKER CAN SET ANY OTHER GUID. # Use only the API key for security. enabled = no # A list of simple patterns matching the IPs of the servers that # will be pushing metrics using this MACHINE GUID. # The metrics are received via the API port, so the same IPs # should also be matched at netdata.conf [web].allow connections from # and at stream.conf [API_KEY].allow from allow from = * # The number of entries in the database history = 3600 # The memory mode of the database: save | map | ram | none memory mode = save # Health / alarms control: yes | no | auto health enabled = yes # postpone alarms when the sender connects postpone alarms on connect seconds = 60 # allow or deny multiple connections for the same host? # If you are sure all your netdata have their own machine GUID, # set this to 'allow', since it allows faster reconnects. # When set to 'deny', new connections for a host will not be # accepted until an existing connection is cleared. multiple connections = allow # need to route metrics differently? #proxy enabled = yes | no #proxy destination = IP:PORT IP:PORT ... #proxy api key = API_KEY