dont need that anymore
This commit is contained in:
parent
d129665792
commit
c3bbddbacf
|
|
@ -8,6 +8,22 @@ import (
|
||||||
client "github.com/influxdata/influxdb1-client/v2"
|
client "github.com/influxdata/influxdb1-client/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CollectAndProcess collects measurements and then reports them to InfluxDB
|
||||||
|
// Can be called once or in a ticker loop. This function and all the ones below
|
||||||
|
// handle their own logging. An error is returned so the calling function may
|
||||||
|
// determine if there was a read or write error and act on it. This is currently
|
||||||
|
// called in two places in this library. One returns an error, one does not.
|
||||||
|
func (u *UnifiPoller) CollectAndProcess() error {
|
||||||
|
metrics, err := u.CollectMetrics()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
u.AugmentMetrics(metrics)
|
||||||
|
err = u.ReportMetrics(metrics)
|
||||||
|
u.LogError(err, "processing metrics")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// ReportMetrics batches all the metrics and writes them to InfluxDB.
|
// ReportMetrics batches all the metrics and writes them to InfluxDB.
|
||||||
// This creates an InfluxDB writer, and returns an error if the write fails.
|
// This creates an InfluxDB writer, and returns an error if the write fails.
|
||||||
func (u *UnifiPoller) ReportMetrics(metrics *metrics.Metrics) error {
|
func (u *UnifiPoller) ReportMetrics(metrics *metrics.Metrics) error {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func (u *UnifiPoller) Run() (err error) {
|
||||||
u.Logf("Logging Measurements to InfluxDB at %s as user %s one time (lambda mode)",
|
u.Logf("Logging Measurements to InfluxDB at %s as user %s one time (lambda mode)",
|
||||||
u.Config.InfluxURL, u.Config.InfluxUser)
|
u.Config.InfluxURL, u.Config.InfluxUser)
|
||||||
u.LastCheck = time.Now()
|
u.LastCheck = time.Now()
|
||||||
return u.CollectAndProcess(u.ReportMetrics)
|
return u.CollectAndProcess()
|
||||||
|
|
||||||
case "prometheus", "exporter":
|
case "prometheus", "exporter":
|
||||||
u.Logf("Exporting Measurements at https://%s/metrics for Prometheus", u.Config.HTTPListen)
|
u.Logf("Exporting Measurements at https://%s/metrics for Prometheus", u.Config.HTTPListen)
|
||||||
|
|
@ -115,7 +115,7 @@ func (u *UnifiPoller) Run() (err error) {
|
||||||
|
|
||||||
u.Logf("Logging Measurements to InfluxDB at %s as user %s", u.Config.InfluxURL, u.Config.InfluxUser)
|
u.Logf("Logging Measurements to InfluxDB at %s as user %s", u.Config.InfluxURL, u.Config.InfluxUser)
|
||||||
u.Config.Mode = "influx poller"
|
u.Config.Mode = "influx poller"
|
||||||
return u.PollController(u.ReportMetrics)
|
return u.PollController()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
// PollController runs forever, polling UniFi
|
// PollController runs forever, polling UniFi
|
||||||
// and pushing to influx OR exporting for prometheus.
|
// and pushing to influx OR exporting for prometheus.
|
||||||
// This is started by Run() after everything checks out.
|
// This is started by Run() after everything checks out.
|
||||||
func (u *UnifiPoller) PollController(process func(*metrics.Metrics) error) error {
|
func (u *UnifiPoller) PollController() error {
|
||||||
interval := u.Config.Interval.Round(time.Second)
|
interval := u.Config.Interval.Round(time.Second)
|
||||||
log.Printf("[INFO] Everything checks out! Poller started in %v mode, interval: %v", u.Config.Mode, interval)
|
log.Printf("[INFO] Everything checks out! Poller started in %v mode, interval: %v", u.Config.Mode, interval)
|
||||||
ticker := time.NewTicker(interval)
|
ticker := time.NewTicker(interval)
|
||||||
|
|
@ -28,7 +28,7 @@ func (u *UnifiPoller) PollController(process func(*metrics.Metrics) error) error
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Only run this if the authentication procedure didn't return error.
|
// Only run this if the authentication procedure didn't return error.
|
||||||
_ = u.CollectAndProcess(process)
|
_ = u.CollectAndProcess()
|
||||||
}
|
}
|
||||||
if u.errorCount > 0 {
|
if u.errorCount > 0 {
|
||||||
return fmt.Errorf("too many errors, stopping poller")
|
return fmt.Errorf("too many errors, stopping poller")
|
||||||
|
|
@ -70,23 +70,6 @@ FIRST:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectAndProcess collects measurements and then passese them into the
|
|
||||||
// provided method. The method is either an http exporter or an influxdb update.
|
|
||||||
// Can be called once or in a ticker loop. This function and all the ones below
|
|
||||||
// handle their own logging. An error is returned so the calling function may
|
|
||||||
// determine if there was a read or write error and act on it. This is currently
|
|
||||||
// called in two places in this library. One returns an error, one does not.
|
|
||||||
func (u *UnifiPoller) CollectAndProcess(process func(*metrics.Metrics) error) error {
|
|
||||||
metrics, err := u.CollectMetrics()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
u.AugmentMetrics(metrics)
|
|
||||||
err = process(metrics)
|
|
||||||
u.LogError(err, "processing metrics")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// CollectMetrics grabs all the measurements from a UniFi controller and returns them.
|
// CollectMetrics grabs all the measurements from a UniFi controller and returns them.
|
||||||
func (u *UnifiPoller) CollectMetrics() (*metrics.Metrics, error) {
|
func (u *UnifiPoller) CollectMetrics() (*metrics.Metrics, error) {
|
||||||
m := &metrics.Metrics{TS: u.LastCheck} // At this point, it's the Current Check.
|
m := &metrics.Metrics{TS: u.LastCheck} // At this point, it's the Current Check.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue