diff --git a/cmd/gqgmcd/index.html b/cmd/gqgmcd/index.html new file mode 100644 index 0000000000000000000000000000000000000000..ddda571a3494f3a15868d778c2c497f8bba2af4b --- /dev/null +++ b/cmd/gqgmcd/index.html @@ -0,0 +1,16 @@ + + + + + Geiger Counter + + + + + diff --git a/cmd/gqgmcd/main.go b/cmd/gqgmcd/main.go index e7887ec5b12af5398dc76203b731df19204022fc..c8fa807b16219a64792963eeec82d12a2486adf6 100644 --- a/cmd/gqgmcd/main.go +++ b/cmd/gqgmcd/main.go @@ -9,22 +9,44 @@ package main import ( "flag" - "fmt" + "html/template" "log" "net/http" "github.com/prometheus/client_golang/prometheus/promhttp" + "gitlab.com/lyda/gqgmc/devices/geiger" ) var addr = flag.String("listen-address", ":8080", "Address for HTTP requests.") +var device = flag.String("device", "/dev/gqgmc", "Device for Geiger Counter.") +var model = flag.String("model", "gqgmc", "Model of Geiger Counter.") -func metricsHandler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Some metrics.") +type indexPage struct { + Model string + Version string + Serial string + Volts int16 + CPM uint16 +} + +var gc geiger.Counter +var indexPg indexPage + +func indexHandler(w http.ResponseWriter, r *http.Request) { + indexPg.CPM, _ = gc.GetCPM() + t, _ := template.ParseFiles("index.html") + t.Execute(w, indexPg) } func main() { flag.Parse() - http.HandleFunc("/", metricsHandler) + + gc, _ = geiger.New(geiger.Config{Model: *model, Device: *device}) + indexPg.Model = gc.Model() + indexPg.Version = gc.Version() + indexPg.Serial, _ = gc.SerialNum() + indexPg.Volts, _ = gc.Volts() + http.HandleFunc("/", indexHandler) http.Handle("/metrics", promhttp.Handler()) log.Fatal(http.ListenAndServe(*addr, nil)) }