Skip to content
Snippets Groups Projects
Commit 627cd475 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Add a sleep cycle param.

parent f1988a53
Branches
No related tags found
No related merge requests found
Pipeline #
......@@ -23,6 +23,7 @@ var device = flag.String("device", "/dev/gqgmc", "Device for Geiger Counter")
var model = flag.String("model", "gqgmc", "Model of Geiger Counter")
var templateDir = flag.String("template-dir", "templates", "Template directory")
var staticDir = flag.String("static-dir", "static", "Static files directory")
var sleepCycle = flag.Int64("sleep-cycle", 5, "Seconds to sleep per cycle.")
var cfg = flag.String("config", "gqgmc.conf", "Config file")
func main() {
......@@ -39,6 +40,6 @@ func main() {
p.Register()
m := metrics.Register(gc)
go m.Gather()
go m.Gather(c.SleepCycle)
log.Fatal(http.ListenAndServe(c.ListenAddress, nil))
}
......@@ -19,6 +19,7 @@ type Config struct {
Model string `mapstructure:"model"`
TemplateDir string `mapstructure:"template_dir"`
StaticDir string `mapstructure:"static_dir"`
SleepCycle int64 `mapstructure:"sleep_cycle"`
}
func setDefaults() {
......@@ -27,6 +28,7 @@ func setDefaults() {
viper.BindPFlag("model", pflag.Lookup("model"))
viper.BindPFlag("template_dir", pflag.Lookup("template-dir"))
viper.BindPFlag("static_dir", pflag.Lookup("static-dir"))
viper.BindPFlag("sleep_cycle", pflag.Lookup("sleep-cycle"))
}
// ReadConfig reads the client configuration from a file into a Config struct.
......
......@@ -69,7 +69,7 @@ func Register(gc geiger.Counter) *Metrics {
}
// Gather loop to gather metrics
func (m *Metrics) Gather() {
func (m *Metrics) Gather(sleep int64) {
var (
cpm, cps uint16
volts int16
......@@ -97,6 +97,6 @@ func (m *Metrics) Gather() {
m.volts.WithLabelValues(m.gc.Serial()).Observe(float64(volts))
}
m.errs.WithLabelValues(m.gc.Serial()).Set(float64(errCt))
time.Sleep(5 * time.Second)
time.Sleep(time.Duration(sleep) * time.Second)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment