report collect errors. just because

This commit is contained in:
davidnewhall2 2020-02-02 00:28:56 -08:00
parent 88e98b0ab5
commit 3f00f963df
2 changed files with 9 additions and 7 deletions

View File

@ -70,9 +70,9 @@ func (u *InfluxUnifi) PollController() {
log.Printf("[INFO] Everything checks out! Poller started, InfluxDB interval: %v", interval) log.Printf("[INFO] Everything checks out! Poller started, InfluxDB interval: %v", interval)
for u.LastCheck = range ticker.C { for u.LastCheck = range ticker.C {
metrics, ok, err := u.Collector.Metrics() metrics, ok, collectErr := u.Collector.Metrics()
if err != nil { if collectErr != nil {
u.Collector.LogErrorf("%v", err) u.Collector.LogErrorf("metric fetch for InfluxDB failed: %v", collectErr)
if !ok { if !ok {
continue continue
@ -86,6 +86,7 @@ func (u *InfluxUnifi) PollController() {
continue continue
} }
report.error(collectErr)
u.LogInfluxReport(report) u.LogInfluxReport(report)
} }
} }
@ -177,12 +178,11 @@ func (u *InfluxUnifi) ReportMetrics(m *poller.Metrics) (*Report, error) {
func (u *InfluxUnifi) collect(r report, ch chan *metric) { func (u *InfluxUnifi) collect(r report, ch chan *metric) {
for m := range ch { for m := range ch {
pt, err := influx.NewPoint(m.Table, m.Tags, m.Fields, r.metrics().TS) pt, err := influx.NewPoint(m.Table, m.Tags, m.Fields, r.metrics().TS)
if err != nil { if err == nil {
r.error(err)
} else {
r.batch(m, pt) r.batch(m, pt)
} }
r.error(err)
r.done() r.done()
} }
} }

View File

@ -54,7 +54,9 @@ func (r *Report) send(m *metric) {
/* The following methods are not thread safe. */ /* The following methods are not thread safe. */
func (r *Report) error(err error) { func (r *Report) error(err error) {
r.Errors = append(r.Errors, err) if err != nil {
r.Errors = append(r.Errors, err)
}
} }
func (r *Report) batch(m *metric, p *influx.Point) { func (r *Report) batch(m *metric, p *influx.Point) {