improved sampler to perform first tick immediately

This commit is contained in:
sqshq 2019-02-04 22:26:00 -05:00
parent 18c2085fd9
commit cb7a41694d
5 changed files with 34 additions and 10 deletions

View File

@ -27,6 +27,33 @@ runcharts:
size:
x: 15
y: 15
- title: SEARCH ENGINE RESPONSE TIME 2 (sec)
items:
- label: GOOGLE
script: curl -o /dev/null -s -w '%{time_total}' https://www.google.com/
- label: YAHOO
script: curl -o /dev/null -s -w '%{time_total}' https://search.yahoo.com/
- label: BING
script: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com/
refresh-rate-ms: 5000
decimal-places: 3
alert:
value:
more-than: 0.231
less-than: 0.123
equal: 0.144
indicator:
terminal: true
beep: true
legend:
enabled: true
details: true
position:
x: 0
y: 15
size:
x: 15
y: 15
- title: MONGO COLLECTIONS COUNT
items:
- label: POSTS

View File

@ -38,7 +38,7 @@ func (config *Config) setDefaultColors() {
for i, chart := range config.RunCharts {
for j, item := range chart.Items {
if item.Color == 0 {
item.Color = palette.Colors[i+j]
item.Color = palette.Colors[i+j] // TODO handle out of range case
chart.Items[j] = item
}
}

View File

@ -8,7 +8,7 @@ import (
)
const (
RenderRate = 50 * time.Millisecond // TODO not a constant, should be dynamically chosen based on min X scale (per each chart? should be tested). if it is 1 sec, it should be 100 ms, if 2 - 200 ms, if 3 - 300, 4 - 400, 5 - 500 and 500 is max. smth like that.
RenderRate = 25 * time.Millisecond
Title = "sampler"
)

View File

@ -21,14 +21,15 @@ const (
type Palette struct {
Colors []ui.Color
// TODO Menu colors, like Dark, Medium, Light etc
}
func GetPalette(theme Theme) Palette {
switch theme {
case ThemeDark:
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
case ThemeLight:
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
default:
panic(fmt.Sprintf("Following theme is not supported: %v", theme))
}

View File

@ -11,15 +11,11 @@ type Sampler struct {
func NewSampler(consumer Consumer, item Item, rateMs int) Sampler {
ticker := time.NewTicker(time.Duration(rateMs * int(time.Millisecond)))
sampler := Sampler{consumer, item}
go func() {
for {
select {
case <-ticker.C:
sampler.sample()
}
for t := time.Tick(time.Duration(rateMs * int(time.Millisecond))); ; <-t {
sampler.sample()
}
}()