config support for init and transform scripts
This commit is contained in:
parent
061d77c76a
commit
800c9b2e3e
70
config.yml
70
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}'
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
17
data/item.go
17
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 {
|
||||
|
|
2
main.go
2
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)
|
||||
|
|
Loading…
Reference in New Issue