diff --git a/config.yml b/config.yml index 283dd34..b216e4c 100644 --- a/config.yml +++ b/config.yml @@ -12,11 +12,11 @@ runcharts: scale: 3 items: - label: GOOGLE - value: curl -o /dev/null -s -w '%{time_total}' https://www.google.com + sample: curl -o /dev/null -s -w '%{time_total}' https://www.google.com - label: YAHOO - value: curl -o /dev/null -s -w '%{time_total}' https://search.yahoo.com + sample: curl -o /dev/null -s -w '%{time_total}' https://search.yahoo.com - label: BING - value: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com + sample: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com - title: MONGO COLLECTIONS COUNT position: [[53, 0], [27, 8]] legend: @@ -25,9 +25,11 @@ runcharts: scale: 0 items: - label: ACTIVE - value: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'ACTIVE'}).itcount()" + init: mongo --quiet --host=localhost blog + sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" + transform: $sample | grep cpu - label: INACTIVE - value: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" + sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" barcharts: - title: EVENTS BY STATUS refresh-rate-ms: 1000 @@ -35,34 +37,40 @@ barcharts: scale: 0 items: - label: NEW - value: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'ACTIVE'}).itcount()" + sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'ACTIVE'}).itcount()" - label: TRIGGERED - value: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" + sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" - label: IN_PROCESS - value: echo 0 + sample: echo 0 - label: FAILED - value: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'ACTIVE'}).itcount()" + sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'ACTIVE'}).itcount()" - label: FINISHED - value: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" + sample: mongo --quiet --host=localhost blog --eval "db.getCollection('posts').find({status:'INACTIVE'}).itcount()" gauges: - title: YEAR PROGRESS position: [[53, 8], [27, 2]] - values: - cur: date +%j - max: echo 365 - min: echo 0 + cur: + sample: date +%j + max: + sample: echo 365 + min: + sample: echo 0 - title: DAY PROGRESS position: [[53, 10], [27, 2]] - values: - cur: date +%H - max: echo 24 - min: echo 0 + cur: + sample: date +%H + max: + sample: echo 24 + min: + sample: echo 0 - title: HOUR PROGRESS position: [[53, 12], [27, 2]] - values: - cur: date +%M - max: echo 60 - min: echo 0 + cur: + sample: date +%M + max: + sample: echo 60 + min: + sample: echo 0 - title: MINUTE PROGRESS position: [[53, 14], [27, 2]] triggers: @@ -71,24 +79,26 @@ gauges: actions: sound: true script: say -v samantha `date +%I:%M%p` - values: - cur: date +%S - max: echo 60 - min: echo 0 + cur: + sample: date +%S + max: + sample: echo 60 + min: + sample: echo 0 asciiboxes: - title: LOCAL TIME position: [[53, 17], [27, 5]] - value: date +%r + sample: date +%r - title: UTC TIME position: [[53, 22], [27, 7]] - value: env TZ=UTC date +%r + sample: env TZ=UTC date +%r font: 3d sparklines: - title: CPU usage position: [[27, 22], [25, 7]] scale: 0 - value: ps -A -o %cpu | awk '{s+=$1} END {print s}' + sample: ps -A -o %cpu | awk '{s+=$1} END {print s}' - title: Memory pages free position: [[27, 17], [25, 5]] scale: 0 - value: memory_pressure | grep 'Pages free' | awk '{print $3}' + sample: memory_pressure | grep 'Pages free' | awk '{print $3}' diff --git a/config/component.go b/config/component.go index 21001d9..5105069 100644 --- a/config/component.go +++ b/config/component.go @@ -47,10 +47,11 @@ type ActionsConfig struct { type GaugeConfig struct { ComponentConfig `yaml:",inline"` - Scale *int `yaml:"scale,omitempty"` - Color *ui.Color `yaml:"color,omitempty"` - Values map[string]string `yaml:"values"` - Items []Item `yaml:",omitempty"` + Scale *int `yaml:"scale,omitempty"` + Color *ui.Color `yaml:"color,omitempty"` + Cur Item `yaml:"cur"` + Max Item `yaml:"max"` + Min Item `yaml:"min"` } type SparkLineConfig struct { @@ -85,9 +86,11 @@ type LegendConfig struct { } type Item struct { - Label *string `yaml:"label,omitempty"` - Script string `yaml:"value"` - Color *ui.Color `yaml:"color,omitempty"` + Label *string `yaml:"label,omitempty"` + Color *ui.Color `yaml:"color,omitempty"` + InitScript *string `yaml:"init,omitempty"` + SampleScript *string `yaml:"sample"` + TransformScript *string `yaml:"transform,omitempty"` } type Location struct { diff --git a/config/default.go b/config/default.go index e912458..445daf6 100644 --- a/config/default.go +++ b/config/default.go @@ -89,12 +89,15 @@ func (c *Config) setDefaultValues() { p := defaultScale g.Scale = &p } - var items []Item - for label, script := range g.Values { - l := label - items = append(items, Item{Label: &l, Script: script}) - } - g.Items = items + + cur := "cur" + max := "max" + min := "min" + + g.Cur.Label = &cur + g.Max.Label = &max + g.Min.Label = &min + c.Gauges[i] = g } diff --git a/data/item.go b/data/item.go index 6f3a58e..2e71f61 100644 --- a/data/item.go +++ b/data/item.go @@ -9,9 +9,11 @@ import ( ) type Item struct { - Label string - Script string - Color *ui.Color + Label string + SampleScript string + InitScript *string + TransformScript *string + Color *ui.Color } func NewItems(cfgs []config.Item) []Item { @@ -19,7 +21,12 @@ func NewItems(cfgs []config.Item) []Item { items := make([]Item, 0) for _, i := range cfgs { - item := Item{Label: *i.Label, Script: i.Script, Color: i.Color} + item := Item{ + Label: *i.Label, + SampleScript: *i.SampleScript, + InitScript: i.InitScript, + TransformScript: i.TransformScript, + Color: i.Color} items = append(items, item) } @@ -28,7 +35,7 @@ func NewItems(cfgs []config.Item) []Item { func (i *Item) nextValue(variables []string) (value string, err error) { - cmd := exec.Command("sh", "-c", i.Script) + cmd := exec.Command("sh", "-c", i.SampleScript) cmd.Env = os.Environ() for _, variable := range variables { diff --git a/main.go b/main.go index 37781b9..a106487 100644 --- a/main.go +++ b/main.go @@ -68,7 +68,7 @@ func main() { for _, c := range cfg.Gauges { cpt := gauge.NewGauge(c, palette) - starter.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers) + starter.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Cur, c.Min, c.Max}, c.Triggers) } handler := event.NewHandler(lout, opt)