added support for custom alert tone sound

This commit is contained in:
sqshq 2019-02-03 21:17:56 -05:00
parent 2c0f88b6f4
commit 8caa058b42
9 changed files with 338 additions and 20 deletions

235
asset/bindata.go Normal file

File diff suppressed because one or more lines are too long

22
asset/file.go Normal file
View File

@ -0,0 +1,22 @@
package asset
import (
"bytes"
"io"
)
type AssetFile struct {
reader io.Reader
}
func NewAssetFile(data []byte) AssetFile {
return AssetFile{bytes.NewReader(data)}
}
func (self AssetFile) Read(p []byte) (n int, err error) {
return self.reader.Read(p)
}
func (self AssetFile) Close() error {
return nil
}

37
asset/player.go Normal file
View File

@ -0,0 +1,37 @@
package asset
import (
"fmt"
"github.com/hajimehoshi/go-mp3"
"github.com/hajimehoshi/oto"
"io"
"log"
)
func beep() error {
bytes, err := Asset("quindar-tone")
if err != nil {
log.Fatal("Can't find asset file")
}
d, err := mp3.NewDecoder(NewAssetFile(bytes))
if err != nil {
return err
}
defer d.Close()
p, err := oto.NewPlayer(d.SampleRate(), 2, 2, 8192)
if err != nil {
return err
}
defer p.Close()
if _, err := io.Copy(p, d); err != nil {
return err
}
fmt.Print("\a")
return nil
}

View File

@ -1,18 +1,25 @@
theme: dark theme: dark
run-charts: runcharts:
- title: CURL-LATENCY - title: SEARCH ENGINE RESPONSE TIME (sec)
data: items:
- label: GOOGLE - label: GOOGLE
script: curl -o /dev/null -s -w '%{time_total}' http://google.com script: curl -o /dev/null -s -w '%{time_total}' https://www.google.com/
- label: YAHOO - label: YAHOO
script: curl -o /dev/null -s -w '%{time_total}' http://yahoo.com script: curl -o /dev/null -s -w '%{time_total}' https://search.yahoo.com/
- label: YANDEX - label: BING
script: curl -o /dev/null -s -w '%{time_total}' http://yandex.com script: curl -o /dev/null -s -w '%{time_total}' https://www.bing.com/
refresh-rate-ms: 200 # TODO consider remove time-scale-sec property, and adjust it automatically based on refresh-rate-ms refresh-rate-ms: 200
time-scale-sec: 1
decimal-places: 1 decimal-places: 1
alert:
value:
more-than: 0.231
less-than: 0.123
equal: 0.144
indicator:
terminal: true
beep: true
legend: legend:
labels: true enabled: true
details: true details: true
position: position:
x: 0 x: 0
@ -20,8 +27,8 @@ run-charts:
size: size:
x: 15 x: 15
y: 15 y: 15
- title: MONGO-COUNT - title: MONGO COLLECTIONS COUNT
data: items:
- label: POSTS - label: POSTS
script: mongo --quiet --host=localhost blog --eval "db.getCollection('post').find({}).size()" script: mongo --quiet --host=localhost blog --eval "db.getCollection('post').find({}).size()"
position: position:
@ -30,3 +37,15 @@ run-charts:
size: size:
x: 15 x: 15
y: 15 y: 15
barcharts:
none
sparklines:
none
gauges:
none
lists:
none
textboxes:
none
asciiboxes:
none

View File

@ -11,16 +11,15 @@ import (
type Config struct { type Config struct {
Theme console.Theme `yaml:"theme"` Theme console.Theme `yaml:"theme"`
RunCharts []RunChartConfig `yaml:"run-charts"` RunCharts []RunChartConfig `yaml:"runcharts"`
} }
type RunChartConfig struct { type RunChartConfig struct {
Title string `yaml:"title"` Title string `yaml:"title"`
Items []data.Item `yaml:"data"` Items []data.Item `yaml:"items"`
Position Position `yaml:"position"` Position Position `yaml:"position"`
Size Size `yaml:"size"` Size Size `yaml:"size"`
RefreshRateMs int `yaml:"refresh-rate-ms"` RefreshRateMs int `yaml:"refresh-rate-ms"`
TimeScaleSec int `yaml:"time-scale-sec"`
} }
func Load(location string) *Config { func Load(location string) *Config {

View File

@ -6,7 +6,6 @@ import (
const ( const (
defaultRefreshRateMs = 300 defaultRefreshRateMs = 300
defaultTimeScaleSec = 1
defaultTheme = console.ThemeDark defaultTheme = console.ThemeDark
) )
@ -20,9 +19,6 @@ func (self *Config) setDefaultValues() {
if chart.RefreshRateMs == 0 { if chart.RefreshRateMs == 0 {
chart.RefreshRateMs = defaultRefreshRateMs chart.RefreshRateMs = defaultRefreshRateMs
} }
if chart.TimeScaleSec == 0 {
chart.TimeScaleSec = defaultTimeScaleSec
}
self.RunCharts[i] = chart self.RunCharts[i] = chart
} }
} }

2
go.mod
View File

@ -1,6 +1,8 @@
module github.com/sqshq/sampler module github.com/sqshq/sampler
require ( require (
github.com/hajimehoshi/go-mp3 v0.1.1
github.com/hajimehoshi/oto v0.1.1
github.com/mattn/go-runewidth v0.0.4 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/sqshq/termui v0.0.0-20190125032456-731556c09f2c github.com/sqshq/termui v0.0.0-20190125032456-731556c09f2c

8
go.sum
View File

@ -1,4 +1,12 @@
github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f h1:FDM3EtwZLyhW48YRiyqjivNlNZjAObv4xt4NnJaU+NQ=
github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherwasm v0.1.1 h1:R/3+SfgCFStiql6ICfyfke1WtpglfjIvTEBux8R1euc=
github.com/gopherjs/gopherwasm v0.1.1/go.mod h1:kx4n9a+MzHH0BJJhvlsQ65hqLFXDO/m256AsaDPQ+/4=
github.com/hajimehoshi/go-mp3 v0.1.1 h1:Y33fAdTma70fkrxnc9u50Uq0lV6eZ+bkAlssdMmCwUc=
github.com/hajimehoshi/go-mp3 v0.1.1/go.mod h1:4i+c5pDNKDrxl1iu9iG90/+fhP37lio6gNhjCx9WBJw=
github.com/hajimehoshi/oto v0.1.1 h1:EG+WxxeAfde1mI0adhLYvGbKgDCxm7bCTd6g+JIA6vI=
github.com/hajimehoshi/oto v0.1.1/go.mod h1:hUiLWeBQnbDu4pZsAhOnGqMI1ZGibS6e2qhQdfpwz04=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=