sampler-fork/main.go

78 lines
2.5 KiB
Go
Raw Normal View History

2019-01-28 23:09:52 +00:00
package main
import (
2019-02-24 04:49:09 +00:00
"github.com/sqshq/sampler/component"
"github.com/sqshq/sampler/component/asciibox"
"github.com/sqshq/sampler/component/barchart"
2019-02-26 04:36:23 +00:00
"github.com/sqshq/sampler/component/gauge"
2019-03-08 04:04:46 +00:00
"github.com/sqshq/sampler/component/layout"
2019-02-24 04:49:09 +00:00
"github.com/sqshq/sampler/component/runchart"
2019-02-02 14:45:53 +00:00
"github.com/sqshq/sampler/config"
"github.com/sqshq/sampler/console"
"github.com/sqshq/sampler/data"
"github.com/sqshq/sampler/event"
2019-03-08 04:04:46 +00:00
"github.com/sqshq/sampler/trigger"
2019-01-28 23:09:52 +00:00
ui "github.com/sqshq/termui"
)
func main() {
2019-02-25 00:08:36 +00:00
cfg, flg := config.Load()
csl := console.Console{}
csl.Init()
defer csl.Close()
2019-01-28 23:09:52 +00:00
2019-02-11 02:51:55 +00:00
width, height := ui.TerminalDimensions()
2019-03-08 04:04:46 +00:00
lout := layout.NewLayout(width, height, component.NewStatusLine(flg.ConfigFileName), component.NewMenu())
2019-01-30 00:21:57 +00:00
for _, c := range cfg.RunCharts {
2019-01-28 23:09:52 +00:00
2019-02-15 04:34:45 +00:00
legend := runchart.Legend{Enabled: c.Legend.Enabled, Details: c.Legend.Details}
2019-03-08 04:04:46 +00:00
chart := runchart.NewRunChart(c, legend)
lout.AddComponent(config.TypeRunChart, chart, c.Title, c.Position, c.Size, *c.RefreshRateMs)
triggers := trigger.NewTriggers(c.Triggers)
2019-01-28 23:09:52 +00:00
2019-03-08 04:04:46 +00:00
for _, i := range c.Items {
item := data.Item{Label: *i.Label, Script: i.Script, Color: *i.Color}
chart.AddLine(item.Label, item.Color)
data.NewSampler(chart.Consumer, item, triggers, *c.RefreshRateMs)
2019-01-28 23:09:52 +00:00
}
2019-01-31 00:02:38 +00:00
}
2019-02-17 23:00:00 +00:00
for _, a := range cfg.AsciiBoxes {
2019-03-08 04:04:46 +00:00
box := asciibox.NewAsciiBox(a)
item := data.Item{Label: *a.Label, Script: a.Script, Color: *a.Color}
triggers := trigger.NewTriggers(a.Triggers)
lout.AddComponent(config.TypeAsciiBox, box, a.Title, a.Position, a.Size, *a.RefreshRateMs)
data.NewSampler(box.Consumer, item, triggers, *a.RefreshRateMs)
2019-02-17 23:00:00 +00:00
}
2019-02-26 04:36:23 +00:00
for _, b := range cfg.BarCharts {
2019-02-19 04:07:32 +00:00
2019-02-26 04:36:23 +00:00
chart := barchart.NewBarChart(b.Title, *b.Scale)
2019-03-08 04:04:46 +00:00
triggers := trigger.NewTriggers(b.Triggers)
lout.AddComponent(config.TypeBarChart, chart, b.Title, b.Position, b.Size, *b.RefreshRateMs)
2019-02-19 04:07:32 +00:00
2019-03-08 04:04:46 +00:00
for _, i := range b.Items {
item := data.Item{Label: *i.Label, Script: i.Script, Color: *i.Color}
chart.AddBar(*i.Label, *i.Color)
data.NewSampler(chart.Consumer, item, triggers, *b.RefreshRateMs)
2019-02-26 04:36:23 +00:00
}
}
for _, gc := range cfg.Gauges {
g := gauge.NewGauge(gc.Title, *gc.Scale, *gc.Color)
2019-03-08 04:04:46 +00:00
triggers := trigger.NewTriggers(gc.Triggers)
lout.AddComponent(config.TypeGauge, g, gc.Title, gc.Position, gc.Size, *gc.RefreshRateMs)
2019-02-26 04:36:23 +00:00
2019-03-08 04:04:46 +00:00
for _, i := range gc.Items {
item := data.Item{Label: *i.Label, Script: i.Script}
data.NewSampler(g.Consumer, item, triggers, *gc.RefreshRateMs)
2019-02-19 04:07:32 +00:00
}
}
2019-03-08 04:04:46 +00:00
handler := event.NewHandler(lout)
handler.HandleEvents()
2019-01-28 23:09:52 +00:00
}