2018-09-05 03:08:48 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-09-06 01:06:16 +02:00
|
|
|
"errors"
|
|
|
|
"flag"
|
2018-09-05 03:08:48 +02:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
|
|
|
|
"github.com/trazfr/freebox-exporter/log"
|
|
|
|
)
|
|
|
|
|
2018-09-06 01:06:16 +02:00
|
|
|
func usage(err error) {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, "Error:", err)
|
|
|
|
}
|
|
|
|
fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "[options] <configfile>")
|
|
|
|
fmt.Fprintln(os.Stderr)
|
|
|
|
fmt.Fprintln(os.Stderr, "Options:")
|
|
|
|
flag.PrintDefaults()
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:08:48 +02:00
|
|
|
func main() {
|
2018-09-06 01:06:16 +02:00
|
|
|
debugPtr := flag.Bool("debug", false, "enable the debug mode")
|
2021-02-26 22:33:39 +01:00
|
|
|
listHostsPtr := flag.Bool("listHosts", false, "list the hosts connected to wifi and ethernet")
|
2021-02-26 08:15:12 +01:00
|
|
|
listenPtr := flag.String("listen", ":9091", "listen to address")
|
2018-09-06 01:06:16 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
args := flag.Args()
|
|
|
|
if len(args) < 1 {
|
|
|
|
usage(errors.New("configfile not defined"))
|
|
|
|
} else if len(args) > 1 {
|
2021-02-26 08:15:12 +01:00
|
|
|
usage(errors.New("too many arguments"))
|
2018-09-05 03:08:48 +02:00
|
|
|
}
|
2018-09-06 01:06:16 +02:00
|
|
|
if *debugPtr {
|
2018-09-05 03:08:48 +02:00
|
|
|
log.Init(os.Stdout, os.Stdout, os.Stdout, os.Stderr)
|
2018-09-06 01:06:16 +02:00
|
|
|
} else {
|
|
|
|
log.Init(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr)
|
2018-09-05 03:08:48 +02:00
|
|
|
}
|
2021-02-26 22:33:39 +01:00
|
|
|
collector := NewCollector(args[0], *listHostsPtr, *debugPtr)
|
2021-02-26 08:15:12 +01:00
|
|
|
defer collector.Close()
|
2018-09-05 03:08:48 +02:00
|
|
|
|
2021-02-26 08:15:12 +01:00
|
|
|
prometheus.MustRegister(collector)
|
2018-09-05 03:08:48 +02:00
|
|
|
|
|
|
|
http.Handle("/metrics", promhttp.Handler())
|
2021-02-26 08:15:12 +01:00
|
|
|
log.Error.Println(http.ListenAndServe(*listenPtr, nil))
|
2018-09-05 03:08:48 +02:00
|
|
|
}
|