diff --git a/component/component.go b/component/component.go index 5485ee9..8bb58fd 100644 --- a/component/component.go +++ b/component/component.go @@ -9,22 +9,22 @@ import ( type Component struct { ui.Drawable *data.Consumer - Type config.ComponentType - Title string - Location config.Location - Size config.Size - RefreshRateMs int + Type config.ComponentType + Title string + Location config.Location + Size config.Size + RateMs int } func NewComponent(dbl ui.Drawable, cmr *data.Consumer, cfg config.ComponentConfig) *Component { return &Component{ - Drawable: dbl, - Consumer: cmr, - Type: cfg.Type, - Title: cfg.Title, - Location: cfg.GetLocation(), - Size: cfg.GetSize(), - RefreshRateMs: *cfg.RefreshRateMs, + Drawable: dbl, + Consumer: cmr, + Type: cfg.Type, + Title: cfg.Title, + Location: cfg.GetLocation(), + Size: cfg.GetSize(), + RateMs: *cfg.RateMs, } } diff --git a/component/runchart/runchart.go b/component/runchart/runchart.go index 29077c7..95cbb51 100644 --- a/component/runchart/runchart.go +++ b/component/runchart/runchart.go @@ -85,7 +85,7 @@ func NewRunChart(c config.RunChartConfig, palette console.Palette) *RunChart { Block: component.NewBlock(c.Title, true, palette), Consumer: data.NewConsumer(), lines: []TimeLine{}, - timescale: calculateTimescale(*c.RefreshRateMs), + timescale: calculateTimescale(*c.RateMs), mutex: &sync.Mutex{}, scale: *c.Scale, mode: ModeDefault, @@ -367,9 +367,9 @@ func getMidRangeTime(r TimeRange) time.Time { } // time duration between grid lines -func calculateTimescale(refreshRateMs int) time.Duration { +func calculateTimescale(rateMs int) time.Duration { - multiplier := refreshRateMs * xAxisGridWidth / 2 + multiplier := rateMs * xAxisGridWidth / 2 timescale := time.Duration(time.Millisecond * time.Duration(multiplier)).Round(time.Second) if timescale.Seconds() == 0 { diff --git a/config.yml b/config.yml index e9c1c7c..0496030 100644 --- a/config.yml +++ b/config.yml @@ -32,7 +32,7 @@ runcharts: sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" barcharts: - title: EVENTS BY STATUS - refresh-rate-ms: 1000 + rate-ms: 1000 position: [[0, 17], [27, 12]] scale: 0 items: diff --git a/config/component.go b/config/component.go index 5105069..e7ce2e5 100644 --- a/config/component.go +++ b/config/component.go @@ -17,11 +17,11 @@ const ( ) type ComponentConfig struct { - Title string `yaml:"title"` - RefreshRateMs *int `yaml:"refresh-rate-ms,omitempty"` - Position [][]int `yaml:"position,flow"` - Triggers []TriggerConfig `yaml:"triggers,omitempty"` - Type ComponentType `yaml:",omitempty"` + Title string `yaml:"title"` + RateMs *int `yaml:"rate-ms,omitempty"` + Position [][]int `yaml:"position,flow"` + Triggers []TriggerConfig `yaml:"triggers,omitempty"` + Type ComponentType `yaml:",omitempty"` } func (c *ComponentConfig) GetLocation() Location { diff --git a/config/default.go b/config/default.go index 445daf6..314ecf2 100644 --- a/config/default.go +++ b/config/default.go @@ -5,9 +5,9 @@ import ( ) const ( - defaultRefreshRateMs = 1000 - defaultScale = 1 - defaultTheme = console.ThemeDark + defaultRateMs = 1000 + defaultScale = 1 + defaultTheme = console.ThemeDark ) func (c *Config) setDefaults() { @@ -28,9 +28,9 @@ func (c *Config) setDefaultValues() { setDefaultTriggersValues(chart.Triggers) chart.ComponentConfig.Type = TypeRunChart - if chart.RefreshRateMs == nil { - r := defaultRefreshRateMs - chart.RefreshRateMs = &r + if chart.RateMs == nil { + r := defaultRateMs + chart.RateMs = &r } if chart.Scale == nil { p := defaultScale @@ -49,9 +49,9 @@ func (c *Config) setDefaultValues() { line.ComponentConfig.Type = TypeSparkLine line.Item.Label = &line.Title - if line.RefreshRateMs == nil { - r := defaultRefreshRateMs - line.RefreshRateMs = &r + if line.RateMs == nil { + r := defaultRateMs + line.RateMs = &r } if line.Scale == nil { p := defaultScale @@ -65,9 +65,9 @@ func (c *Config) setDefaultValues() { setDefaultTriggersValues(chart.Triggers) chart.ComponentConfig.Type = TypeBarChart - if chart.RefreshRateMs == nil { - r := defaultRefreshRateMs - chart.RefreshRateMs = &r + if chart.RateMs == nil { + r := defaultRateMs + chart.RateMs = &r } if chart.Scale == nil { p := defaultScale @@ -81,9 +81,9 @@ func (c *Config) setDefaultValues() { setDefaultTriggersValues(g.Triggers) g.ComponentConfig.Type = TypeGauge - if g.RefreshRateMs == nil { - r := defaultRefreshRateMs - g.RefreshRateMs = &r + if g.RateMs == nil { + r := defaultRateMs + g.RateMs = &r } if g.Scale == nil { p := defaultScale @@ -106,9 +106,9 @@ func (c *Config) setDefaultValues() { setDefaultTriggersValues(box.Triggers) box.ComponentConfig.Type = TypeAsciiBox - if box.RefreshRateMs == nil { - r := defaultRefreshRateMs - box.RefreshRateMs = &r + if box.RateMs == nil { + r := defaultRateMs + box.RateMs = &r } if box.Label == nil { label := string(i) diff --git a/data/item.go b/data/item.go index 1fce214..2957da5 100644 --- a/data/item.go +++ b/data/item.go @@ -18,7 +18,7 @@ type Item struct { InitScript *string TransformScript *string Color *ui.Color - RefreshRateMs int + RateMs int InteractiveShell *InteractiveShell } @@ -29,7 +29,7 @@ type InteractiveShell struct { Cmd *exec.Cmd } -func NewItems(cfgs []config.Item, refreshRateMs int) []*Item { +func NewItems(cfgs []config.Item, rateMs int) []*Item { items := make([]*Item, 0) @@ -40,7 +40,7 @@ func NewItems(cfgs []config.Item, refreshRateMs int) []*Item { InitScript: i.InitScript, TransformScript: i.TransformScript, Color: i.Color, - RefreshRateMs: refreshRateMs, + RateMs: rateMs, } items = append(items, item) } @@ -136,7 +136,7 @@ func (i *Item) executeInteractiveShellCmd(variables []string) (string, error) { timeout := make(chan bool, 1) go func() { - time.Sleep(time.Duration(i.RefreshRateMs)) + time.Sleep(time.Duration(i.RateMs)) timeout <- true }() diff --git a/event/handler.go b/event/handler.go index 2af02cb..6f672b7 100644 --- a/event/handler.go +++ b/event/handler.go @@ -84,15 +84,15 @@ func (h *Handler) handleExit() { func calcMinRenderRate(layout *layout.Layout) time.Duration { - minRefreshRateMs := layout.Components[0].RefreshRateMs + minRateMs := layout.Components[0].RateMs for _, c := range layout.Components { - if c.RefreshRateMs < minRefreshRateMs { - minRefreshRateMs = c.RefreshRateMs + if c.RateMs < minRateMs { + minRateMs = c.RateMs } } renderRate := time.Duration( - int(float64(minRefreshRateMs)*refreshRateToRenderRateRatio)) * time.Millisecond + int(float64(minRateMs)*refreshRateToRenderRateRatio)) * time.Millisecond if renderRate < console.MinRenderInterval { return console.MinRenderInterval diff --git a/main.go b/main.go index dea56b0..7f75951 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ type Starter struct { func (s *Starter) start(drawable ui.Drawable, consumer *data.Consumer, componentConfig config.ComponentConfig, itemsConfig []config.Item, triggersConfig []config.TriggerConfig) { cpt := component.NewComponent(drawable, consumer, componentConfig) triggers := data.NewTriggers(triggersConfig, consumer, s.opt, s.player) - data.NewSampler(consumer, data.NewItems(itemsConfig, *componentConfig.RefreshRateMs), triggers, s.opt, *componentConfig.RefreshRateMs) + data.NewSampler(consumer, data.NewItems(itemsConfig, *componentConfig.RateMs), triggers, s.opt, *componentConfig.RateMs) s.lout.AddComponent(cpt) }