🎉 Initial version
This commit is contained in:
42
main.go
Normal file
42
main.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"minie4.de/tplinkswitchexporter/PrometheusCollector"
|
||||
"minie4.de/tplinkswitchexporter/TPLinkClient"
|
||||
)
|
||||
|
||||
func main() {
|
||||
godotenv.Load()
|
||||
|
||||
var (
|
||||
switchMac = os.Getenv("TPLINK_MAC")
|
||||
port = 9717
|
||||
)
|
||||
if switchMac == "" {
|
||||
log.Fatal("Env variable 'TPLINK_MAC' not set!")
|
||||
}
|
||||
|
||||
log.Println("Initializing TP-Link Exporter")
|
||||
log.Printf("Switch MAC: '%s'", switchMac)
|
||||
|
||||
// Create TPLink Client
|
||||
client := TPLinkClient.NewClient(switchMac)
|
||||
|
||||
// Create and register Prometheus Collector
|
||||
collector := PrometheusCollector.NewPrometheusCollector(&client)
|
||||
prometheus.MustRegister(collector)
|
||||
|
||||
// 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))
|
||||
|
||||
}
|
Reference in New Issue
Block a user