diff --git a/.env.sample b/.env.sample index db10692..e9b156e 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,9 @@ # Enter the MAC Address of the TP-Link switch # you want to monitor here -TPLINK_MAC=ff:ff:ff:ff:ff:ff \ No newline at end of file +TPLINK_MAC=ff:ff:ff:ff:ff:ff + +# The port to bind the Prometheus HTTP server on +# (default: 9717) + +LISTEN_PORT=9717 \ No newline at end of file diff --git a/main.go b/main.go index 79fd5f9..cbbcc6e 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( "log" "net/http" "os" - "strconv" "github.com/joho/godotenv" "github.com/prometheus/client_golang/prometheus" @@ -18,8 +17,11 @@ func main() { var ( switchMac = os.Getenv("TPLINK_MAC") - port = 9717 + port = os.Getenv("LISTEN_PORT") ) + if port == "" { + port = "9717" + } if switchMac == "" { log.Fatal("Env variable 'TPLINK_MAC' not set!") } @@ -36,7 +38,7 @@ func main() { // Start Web-Server http.Handle("/metrics", promhttp.Handler()) - log.Printf("Listening on http://0.0.0.0:%d", port) - log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), nil)) + log.Printf("Listening on http://0.0.0.0:%s", port) + log.Fatal(http.ListenAndServe(":"+port, nil)) }