From ad562e597601c427f3621851d5b0abe6dc5fbd6f Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Wed, 25 Dec 2019 00:19:40 -0800 Subject: [PATCH] export buffer, lock cnfg --- Gopkg.toml | 4 ++++ pkg/promunifi/collector.go | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Gopkg.toml b/Gopkg.toml index 044de96a..e3e5352f 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -12,3 +12,7 @@ [[constraint]] name = "golift.io/unifi" branch = "master" + +[[constraint]] + name = "golift.io/cnfg" + branch = "master" diff --git a/pkg/promunifi/collector.go b/pkg/promunifi/collector.go index 61020625..49be737a 100644 --- a/pkg/promunifi/collector.go +++ b/pkg/promunifi/collector.go @@ -18,7 +18,7 @@ import ( const ( // channel buffer, fits at least one batch. - buffer = 50 + defaultBuffer = 50 defaultHTTPListen = "0.0.0.0:9130" // simply fewer letters. counter = prometheus.CounterValue @@ -50,6 +50,9 @@ type Config struct { // will be collected at all. ReportErrors bool `json:"report_errors" toml:"report_errors" xml:"report_errors" yaml:"report_errors"` Disable bool `json:"disable" toml:"disable" xml:"disable" yaml:"disable"` + // Buffer is a channel buffer. + // Default is probably 50. Seems fast there; try 1 to see if CPU usage goes down? + Buffer int `json:"buffer" toml:"buffer" xml:"buffer" yaml:"buffer"` } type metric struct { @@ -105,6 +108,10 @@ func (u *promUnifi) Run(c poller.Collect) error { u.HTTPListen = defaultHTTPListen } + if u.Buffer == 0 { + u.Buffer = defaultBuffer + } + // Later can pass this in from poller by adding a method to the interface. u.Collector = c u.Client = descClient(u.Namespace + "_client_") @@ -200,7 +207,7 @@ func (u *promUnifi) collect(ch chan<- prometheus.Metric, filter *poller.Filter) r := &Report{ Config: u.Config, - ch: make(chan []*metric, buffer), + ch: make(chan []*metric, u.Config.Buffer), Start: time.Now()} defer r.close()