improved sampler to perform first tick immediately
This commit is contained in:
parent
18c2085fd9
commit
cb7a41694d
27
config.yml
27
config.yml
|
@ -27,6 +27,33 @@ runcharts:
|
||||||
size:
|
size:
|
||||||
x: 15
|
x: 15
|
||||||
y: 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
|
- title: MONGO COLLECTIONS COUNT
|
||||||
items:
|
items:
|
||||||
- label: POSTS
|
- label: POSTS
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (config *Config) setDefaultColors() {
|
||||||
for i, chart := range config.RunCharts {
|
for i, chart := range config.RunCharts {
|
||||||
for j, item := range chart.Items {
|
for j, item := range chart.Items {
|
||||||
if item.Color == 0 {
|
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
|
chart.Items[j] = item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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"
|
Title = "sampler"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,15 @@ const (
|
||||||
|
|
||||||
type Palette struct {
|
type Palette struct {
|
||||||
Colors []ui.Color
|
Colors []ui.Color
|
||||||
|
// TODO Menu colors, like Dark, Medium, Light etc
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPalette(theme Theme) Palette {
|
func GetPalette(theme Theme) Palette {
|
||||||
switch theme {
|
switch theme {
|
||||||
case ThemeDark:
|
case ThemeDark:
|
||||||
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
|
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
|
||||||
case ThemeLight:
|
case ThemeLight:
|
||||||
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
|
return Palette{Colors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorOlive, ColorDeepSkyBlue, ColorDeepPink}}
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("Following theme is not supported: %v", theme))
|
panic(fmt.Sprintf("Following theme is not supported: %v", theme))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,12 @@ type Sampler struct {
|
||||||
|
|
||||||
func NewSampler(consumer Consumer, item Item, rateMs int) Sampler {
|
func NewSampler(consumer Consumer, item Item, rateMs int) Sampler {
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Duration(rateMs * int(time.Millisecond)))
|
|
||||||
sampler := Sampler{consumer, item}
|
sampler := Sampler{consumer, item}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for t := time.Tick(time.Duration(rateMs * int(time.Millisecond))); ; <-t {
|
||||||
select {
|
|
||||||
case <-ticker.C:
|
|
||||||
sampler.sample()
|
sampler.sample()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return sampler
|
return sampler
|
||||||
|
|
Loading…
Reference in New Issue