rename some things

This commit is contained in:
davidnewhall2 2019-11-18 02:10:16 -08:00
parent 1798f31dfa
commit 166c4a21f0
1 changed files with 24 additions and 18 deletions

View File

@ -98,7 +98,7 @@ func (u *unifiCollector) Describe(ch chan<- *prometheus.Desc) {
// the current metrics (from another package) then exports them for prometheus. // the current metrics (from another package) then exports them for prometheus.
func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) { func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) {
start := time.Now() start := time.Now()
m, err := u.Config.CollectFn() unifiMetrics, err := u.Config.CollectFn()
if err != nil { if err != nil {
ch <- prometheus.NewInvalidMetric( ch <- prometheus.NewInvalidMetric(
prometheus.NewInvalidDesc(fmt.Errorf("metric fetch failed")), err) prometheus.NewInvalidDesc(fmt.Errorf("metric fetch failed")), err)
@ -106,7 +106,7 @@ func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) {
} }
descs := make(map[*prometheus.Desc]bool) // used as a counter descs := make(map[*prometheus.Desc]bool) // used as a counter
r := &Report{Metrics: m} r := &Report{Metrics: unifiMetrics}
if u.Config.LoggingFn != nil { if u.Config.LoggingFn != nil {
defer func() { defer func() {
r.Elapsed = time.Since(start) r.Elapsed = time.Since(start)
@ -115,50 +115,54 @@ func (u *unifiCollector) Collect(ch chan<- prometheus.Metric) {
}() }()
} }
process := func(m []*metricExports) { export := func(metrics []*metricExports) {
count, errors := u.export(ch, m) count, errors := u.export(ch, metrics)
r.Total += count r.Total += count
r.Errors += errors r.Errors += errors
for _, d := range m { for _, d := range metrics {
descs[d.Desc] = true descs[d.Desc] = true
} }
} }
for _, asset := range m.Clients { for _, asset := range r.Metrics.Clients {
process(u.exportClient(asset)) export(u.exportClient(asset))
} }
for _, asset := range m.Sites { for _, asset := range r.Metrics.Sites {
process(u.exportSite(asset)) export(u.exportSite(asset))
} }
if m.Devices == nil { if r.Metrics.Devices == nil {
return return
} }
for _, asset := range m.Devices.UAPs { for _, asset := range r.Metrics.Devices.UAPs {
process(u.exportUAP(asset)) export(u.exportUAP(asset))
} }
for _, asset := range m.Devices.USGs { for _, asset := range r.Metrics.Devices.USGs {
process(u.exportUSG(asset)) export(u.exportUSG(asset))
} }
for _, asset := range m.Devices.USWs { for _, asset := range r.Metrics.Devices.USWs {
process(u.exportUSW(asset)) export(u.exportUSW(asset))
} }
for _, asset := range m.Devices.UDMs { for _, asset := range r.Metrics.Devices.UDMs {
process(u.exportUDM(asset)) export(u.exportUDM(asset))
} }
} }
func (u *unifiCollector) export(ch chan<- prometheus.Metric, exports []*metricExports) (count, errors int) { func (u *unifiCollector) export(ch chan<- prometheus.Metric, exports []*metricExports) (count, errors int) {
for _, e := range exports { for _, e := range exports {
var val float64 var val float64
switch v := e.Value.(type) { switch v := e.Value.(type) {
case float64: case float64:
val = v val = v
case int64: case int64:
val = float64(v) val = float64(v)
case unifi.FlexInt: case unifi.FlexInt:
val = v.Val val = v.Val
default: default:
errors++ errors++
if u.Config.ReportErrors { if u.Config.ReportErrors {
@ -166,8 +170,10 @@ func (u *unifiCollector) export(ch chan<- prometheus.Metric, exports []*metricEx
} }
continue continue
} }
count++ count++
ch <- prometheus.MustNewConstMetric(e.Desc, e.ValueType, val, e.Labels...) ch <- prometheus.MustNewConstMetric(e.Desc, e.ValueType, val, e.Labels...)
} }
return return
} }