diff --git a/go.mod b/go.mod index 192a216d..bd07c498 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.19.0 - github.com/prometheus/common v0.48.0 + github.com/prometheus/common v0.53.0 github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c github.com/stretchr/testify v1.9.0 golang.org/x/crypto v0.22.0 @@ -42,7 +42,7 @@ require ( github.com/BurntSushi/toml v1.3.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/influxdata/influxdb-client-go/v2 v2.13.0 - github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/client_model v0.6.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect golang.org/x/sys v0.19.0 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index 125ab01b..38e6f039 100644 --- a/go.sum +++ b/go.sum @@ -43,10 +43,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= -github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= -github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= -github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= +github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= +github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= +github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+aLCE= +github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= diff --git a/pkg/promunifi/collector.go b/pkg/promunifi/collector.go index 1b8c80f0..36fb1972 100644 --- a/pkg/promunifi/collector.go +++ b/pkg/promunifi/collector.go @@ -3,6 +3,7 @@ package promunifi import ( "fmt" + "github.com/prometheus/client_golang/prometheus/collectors" "net" "net/http" "reflect" @@ -121,15 +122,15 @@ func (u *promUnifi) DebugOutput() (bool, error) { if u == nil { return true, nil } - + if !u.Enabled() { return true, nil } - + if u.HTTPListen == "" { return false, fmt.Errorf("invalid listen string") } - + // check the port parts := strings.Split(u.HTTPListen, ":") if len(parts) != 2 { @@ -140,9 +141,9 @@ func (u *promUnifi) DebugOutput() (bool, error) { if err != nil { return false, err } - + _ = ln.Close() - + return true, nil } @@ -150,11 +151,11 @@ func (u *promUnifi) Enabled() bool { if u == nil { return false } - + if u.Config == nil { return false } - + return !u.Disable } @@ -167,7 +168,7 @@ func (u *promUnifi) Run(c poller.Collect) error { return nil } - + u.Logf("Prometheus is enabled") u.Namespace = strings.Trim(strings.ReplaceAll(u.Namespace, "-", "_"), "_") @@ -198,7 +199,7 @@ func (u *promUnifi) Run(c poller.Collect) error { promver.Branch = version.Branch webserver.UpdateOutput(&webserver.Output{Name: PluginName, Config: u.Config}) - prometheus.MustRegister(promver.NewCollector(u.Namespace)) + prometheus.MustRegister(collectors.NewBuildInfoCollector()) prometheus.MustRegister(u) mux.Handle("/metrics", promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}, @@ -209,11 +210,11 @@ func (u *promUnifi) Run(c poller.Collect) error { switch u.SSLKeyPath == "" && u.SSLCrtPath == "" { case true: u.Logf("Prometheus exported at http://%s/ - namespace: %s", u.HTTPListen, u.Namespace) - + return http.ListenAndServe(u.HTTPListen, mux) default: u.Logf("Prometheus exported at https://%s/ - namespace: %s", u.HTTPListen, u.Namespace) - + return http.ListenAndServeTLS(u.HTTPListen, u.SSLCrtPath, u.SSLKeyPath, mux) } }