more reusable code
This commit is contained in:
		
							parent
							
								
									50c1a635c6
								
							
						
					
					
						commit
						36e88dcaf4
					
				|  | @ -19,157 +19,152 @@ func (u *InfluxUnifi) batchUAP(r report, s *unifi.UAP) { | ||||||
| 		"serial":    s.Serial, | 		"serial":    s.Serial, | ||||||
| 		"type":      s.Type, | 		"type":      s.Type, | ||||||
| 	} | 	} | ||||||
| 	fields := map[string]interface{}{ | 	fields := Combine(u.processUAPstats(r, s.Stat.Ap), u.batchSysStats(r, s.SysStats, s.SystemStats)) | ||||||
| 		"ip":            s.IP, | 	fields["ip"] = s.IP | ||||||
| 		"bytes":         s.Bytes.Val, | 	fields["bytes"] = s.Bytes.Val | ||||||
| 		"last_seen":     s.LastSeen.Val, | 	fields["last_seen"] = s.LastSeen.Val | ||||||
| 		"rx_bytes":      s.RxBytes.Val, | 	fields["rx_bytes"] = s.RxBytes.Val | ||||||
| 		"tx_bytes":      s.TxBytes.Val, | 	fields["tx_bytes"] = s.TxBytes.Val | ||||||
| 		"uptime":        s.Uptime.Val, | 	fields["uptime"] = s.Uptime.Val | ||||||
| 		"state":         s.State, | 	fields["state"] = s.State | ||||||
| 		"user-num_sta":  int(s.UserNumSta.Val), | 	fields["user-num_sta"] = int(s.UserNumSta.Val) | ||||||
| 		"guest-num_sta": int(s.GuestNumSta.Val), | 	fields["guest-num_sta"] = int(s.GuestNumSta.Val) | ||||||
| 		"num_sta":       s.NumSta.Val, | 	fields["num_sta"] = s.NumSta.Val | ||||||
| 		"loadavg_1":     s.SysStats.Loadavg1.Val, |  | ||||||
| 		"loadavg_5":     s.SysStats.Loadavg5.Val, |  | ||||||
| 		"loadavg_15":    s.SysStats.Loadavg15.Val, |  | ||||||
| 		"mem_buffer":    s.SysStats.MemBuffer.Val, |  | ||||||
| 		"mem_total":     s.SysStats.MemTotal.Val, |  | ||||||
| 		"mem_used":      s.SysStats.MemUsed.Val, |  | ||||||
| 		"cpu":           s.SystemStats.CPU.Val, |  | ||||||
| 		"mem":           s.SystemStats.Mem.Val, |  | ||||||
| 		"system_uptime": s.SystemStats.Uptime.Val, |  | ||||||
| 		// Accumulative Statistics.
 |  | ||||||
| 		"stat_user-rx_packets":  s.Stat.Ap.UserRxPackets.Val, |  | ||||||
| 		"stat_guest-rx_packets": s.Stat.Ap.GuestRxPackets.Val, |  | ||||||
| 		"stat_rx_packets":       s.Stat.Ap.RxPackets.Val, |  | ||||||
| 		"stat_user-rx_bytes":    s.Stat.Ap.UserRxBytes.Val, |  | ||||||
| 		"stat_guest-rx_bytes":   s.Stat.Ap.GuestRxBytes.Val, |  | ||||||
| 		"stat_rx_bytes":         s.Stat.Ap.RxBytes.Val, |  | ||||||
| 		"stat_user-rx_errors":   s.Stat.Ap.UserRxErrors.Val, |  | ||||||
| 		"stat_guest-rx_errors":  s.Stat.Ap.GuestRxErrors.Val, |  | ||||||
| 		"stat_rx_errors":        s.Stat.Ap.RxErrors.Val, |  | ||||||
| 		"stat_user-rx_dropped":  s.Stat.Ap.UserRxDropped.Val, |  | ||||||
| 		"stat_guest-rx_dropped": s.Stat.Ap.GuestRxDropped.Val, |  | ||||||
| 		"stat_rx_dropped":       s.Stat.Ap.RxDropped.Val, |  | ||||||
| 		"stat_user-rx_crypts":   s.Stat.Ap.UserRxCrypts.Val, |  | ||||||
| 		"stat_guest-rx_crypts":  s.Stat.Ap.GuestRxCrypts.Val, |  | ||||||
| 		"stat_rx_crypts":        s.Stat.Ap.RxCrypts.Val, |  | ||||||
| 		"stat_user-rx_frags":    s.Stat.Ap.UserRxFrags.Val, |  | ||||||
| 		"stat_guest-rx_frags":   s.Stat.Ap.GuestRxFrags.Val, |  | ||||||
| 		"stat_rx_frags":         s.Stat.Ap.RxFrags.Val, |  | ||||||
| 		"stat_user-tx_packets":  s.Stat.Ap.UserTxPackets.Val, |  | ||||||
| 		"stat_guest-tx_packets": s.Stat.Ap.GuestTxPackets.Val, |  | ||||||
| 		"stat_tx_packets":       s.Stat.Ap.TxPackets.Val, |  | ||||||
| 		"stat_user-tx_bytes":    s.Stat.Ap.UserTxBytes.Val, |  | ||||||
| 		"stat_guest-tx_bytes":   s.Stat.Ap.GuestTxBytes.Val, |  | ||||||
| 		"stat_tx_bytes":         s.Stat.Ap.TxBytes.Val, |  | ||||||
| 		"stat_user-tx_errors":   s.Stat.Ap.UserTxErrors.Val, |  | ||||||
| 		"stat_guest-tx_errors":  s.Stat.Ap.GuestTxErrors.Val, |  | ||||||
| 		"stat_tx_errors":        s.Stat.Ap.TxErrors.Val, |  | ||||||
| 		"stat_user-tx_dropped":  s.Stat.Ap.UserTxDropped.Val, |  | ||||||
| 		"stat_guest-tx_dropped": s.Stat.Ap.GuestTxDropped.Val, |  | ||||||
| 		"stat_tx_dropped":       s.Stat.Ap.TxDropped.Val, |  | ||||||
| 		"stat_user-tx_retries":  s.Stat.Ap.UserTxRetries.Val, |  | ||||||
| 		"stat_guest-tx_retries": s.Stat.Ap.GuestTxRetries.Val, |  | ||||||
| 	} |  | ||||||
| 	r.send(&metric{Table: "uap", Tags: tags, Fields: fields}) | 	r.send(&metric{Table: "uap", Tags: tags, Fields: fields}) | ||||||
| 	u.processVAPs(r, s.VapTable, s.RadioTable, s.RadioTableStats, s.Name, s.Mac, s.SiteName) | 	u.processVAPs(r, tags, s.VapTable, s.RadioTable, s.RadioTableStats) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u *InfluxUnifi) processUAPstats(r report, ap *unifi.Ap) map[string]interface{} { | ||||||
|  | 	// Accumulative Statistics.
 | ||||||
|  | 	return map[string]interface{}{ | ||||||
|  | 		"stat_user-rx_packets":  ap.UserRxPackets.Val, | ||||||
|  | 		"stat_guest-rx_packets": ap.GuestRxPackets.Val, | ||||||
|  | 		"stat_rx_packets":       ap.RxPackets.Val, | ||||||
|  | 		"stat_user-rx_bytes":    ap.UserRxBytes.Val, | ||||||
|  | 		"stat_guest-rx_bytes":   ap.GuestRxBytes.Val, | ||||||
|  | 		"stat_rx_bytes":         ap.RxBytes.Val, | ||||||
|  | 		"stat_user-rx_errors":   ap.UserRxErrors.Val, | ||||||
|  | 		"stat_guest-rx_errors":  ap.GuestRxErrors.Val, | ||||||
|  | 		"stat_rx_errors":        ap.RxErrors.Val, | ||||||
|  | 		"stat_user-rx_dropped":  ap.UserRxDropped.Val, | ||||||
|  | 		"stat_guest-rx_dropped": ap.GuestRxDropped.Val, | ||||||
|  | 		"stat_rx_dropped":       ap.RxDropped.Val, | ||||||
|  | 		"stat_user-rx_crypts":   ap.UserRxCrypts.Val, | ||||||
|  | 		"stat_guest-rx_crypts":  ap.GuestRxCrypts.Val, | ||||||
|  | 		"stat_rx_crypts":        ap.RxCrypts.Val, | ||||||
|  | 		"stat_user-rx_frags":    ap.UserRxFrags.Val, | ||||||
|  | 		"stat_guest-rx_frags":   ap.GuestRxFrags.Val, | ||||||
|  | 		"stat_rx_frags":         ap.RxFrags.Val, | ||||||
|  | 		"stat_user-tx_packets":  ap.UserTxPackets.Val, | ||||||
|  | 		"stat_guest-tx_packets": ap.GuestTxPackets.Val, | ||||||
|  | 		"stat_tx_packets":       ap.TxPackets.Val, | ||||||
|  | 		"stat_user-tx_bytes":    ap.UserTxBytes.Val, | ||||||
|  | 		"stat_guest-tx_bytes":   ap.GuestTxBytes.Val, | ||||||
|  | 		"stat_tx_bytes":         ap.TxBytes.Val, | ||||||
|  | 		"stat_user-tx_errors":   ap.UserTxErrors.Val, | ||||||
|  | 		"stat_guest-tx_errors":  ap.GuestTxErrors.Val, | ||||||
|  | 		"stat_tx_errors":        ap.TxErrors.Val, | ||||||
|  | 		"stat_user-tx_dropped":  ap.UserTxDropped.Val, | ||||||
|  | 		"stat_guest-tx_dropped": ap.GuestTxDropped.Val, | ||||||
|  | 		"stat_tx_dropped":       ap.TxDropped.Val, | ||||||
|  | 		"stat_user-tx_retries":  ap.UserTxRetries.Val, | ||||||
|  | 		"stat_guest-tx_retries": ap.GuestTxRetries.Val, | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // processVAPs creates points for Wifi Radios. This works with several types of UAP-capable devices.
 | // processVAPs creates points for Wifi Radios. This works with several types of UAP-capable devices.
 | ||||||
| func (u *InfluxUnifi) processVAPs(r report, vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableStats, name, mac, sitename string) { | func (u *InfluxUnifi) processVAPs(r report, tags map[string]string, vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableStats) { | ||||||
| 	// Loop each virtual AP (ESSID) and extract data for it
 | 	// Loop each virtual AP (ESSID) and extract data for it
 | ||||||
| 	// from radio_tables and radio_table_stats.
 | 	// from radio_tables and radio_table_stats.
 | ||||||
| 	for _, s := range vt { | 	for _, s := range vt { | ||||||
| 		tags := make(map[string]string) | 		t := make(map[string]string)      // tags
 | ||||||
| 		fields := make(map[string]interface{}) | 		f := make(map[string]interface{}) // fields
 | ||||||
| 		tags["device_name"] = name | 		t["device_name"] = tags["name"] | ||||||
| 		tags["device_mac"] = mac | 		t["site_name"] = tags["site_name"] | ||||||
| 		tags["site_name"] = sitename | 		t["ap_mac"] = s.ApMac | ||||||
| 		tags["ap_mac"] = s.ApMac | 		t["bssid"] = s.Bssid | ||||||
| 		tags["bssid"] = s.Bssid | 		t["id"] = s.ID | ||||||
| 		tags["id"] = s.ID | 		t["name"] = s.Name | ||||||
| 		tags["name"] = s.Name | 		t["radio_name"] = s.RadioName | ||||||
| 		tags["radio_name"] = s.RadioName | 		t["essid"] = s.Essid | ||||||
| 		tags["essid"] = s.Essid | 		t["site_id"] = s.SiteID | ||||||
| 		tags["site_id"] = s.SiteID | 		t["usage"] = s.Usage | ||||||
| 		tags["usage"] = s.Usage | 		t["state"] = s.State | ||||||
| 		tags["state"] = s.State | 		t["is_guest"] = s.IsGuest.Txt | ||||||
| 		tags["is_guest"] = s.IsGuest.Txt |  | ||||||
| 
 | 
 | ||||||
| 		fields["ccq"] = s.Ccq | 		f["ccq"] = s.Ccq | ||||||
| 		fields["mac_filter_rejections"] = s.MacFilterRejections | 		f["mac_filter_rejections"] = s.MacFilterRejections | ||||||
| 		fields["num_satisfaction_sta"] = s.NumSatisfactionSta.Val | 		f["num_satisfaction_sta"] = s.NumSatisfactionSta.Val | ||||||
| 		fields["avg_client_signal"] = s.AvgClientSignal.Val | 		f["avg_client_signal"] = s.AvgClientSignal.Val | ||||||
| 		fields["satisfaction"] = s.Satisfaction.Val | 		f["satisfaction"] = s.Satisfaction.Val | ||||||
| 		fields["satisfaction_now"] = s.SatisfactionNow.Val | 		f["satisfaction_now"] = s.SatisfactionNow.Val | ||||||
| 		fields["rx_bytes"] = s.RxBytes.Val | 		f["rx_bytes"] = s.RxBytes.Val | ||||||
| 		fields["rx_crypts"] = s.RxCrypts.Val | 		f["rx_crypts"] = s.RxCrypts.Val | ||||||
| 		fields["rx_dropped"] = s.RxDropped.Val | 		f["rx_dropped"] = s.RxDropped.Val | ||||||
| 		fields["rx_errors"] = s.RxErrors.Val | 		f["rx_errors"] = s.RxErrors.Val | ||||||
| 		fields["rx_frags"] = s.RxFrags.Val | 		f["rx_frags"] = s.RxFrags.Val | ||||||
| 		fields["rx_nwids"] = s.RxNwids.Val | 		f["rx_nwids"] = s.RxNwids.Val | ||||||
| 		fields["rx_packets"] = s.RxPackets.Val | 		f["rx_packets"] = s.RxPackets.Val | ||||||
| 		fields["tx_bytes"] = s.TxBytes.Val | 		f["tx_bytes"] = s.TxBytes.Val | ||||||
| 		fields["tx_dropped"] = s.TxDropped.Val | 		f["tx_dropped"] = s.TxDropped.Val | ||||||
| 		fields["tx_errors"] = s.TxErrors.Val | 		f["tx_errors"] = s.TxErrors.Val | ||||||
| 		fields["tx_packets"] = s.TxPackets.Val | 		f["tx_packets"] = s.TxPackets.Val | ||||||
| 		fields["tx_power"] = s.TxPower.Val | 		f["tx_power"] = s.TxPower.Val | ||||||
| 		fields["tx_retries"] = s.TxRetries.Val | 		f["tx_retries"] = s.TxRetries.Val | ||||||
| 		fields["tx_combined_retries"] = s.TxCombinedRetries.Val | 		f["tx_combined_retries"] = s.TxCombinedRetries.Val | ||||||
| 		fields["tx_data_mpdu_bytes"] = s.TxDataMpduBytes.Val | 		f["tx_data_mpdu_bytes"] = s.TxDataMpduBytes.Val | ||||||
| 		fields["tx_rts_retries"] = s.TxRtsRetries.Val | 		f["tx_rts_retries"] = s.TxRtsRetries.Val | ||||||
| 		fields["tx_success"] = s.TxSuccess.Val | 		f["tx_success"] = s.TxSuccess.Val | ||||||
| 		fields["tx_total"] = s.TxTotal.Val | 		f["tx_total"] = s.TxTotal.Val | ||||||
| 		fields["tx_tcp_goodbytes"] = s.TxTCPStats.Goodbytes.Val | 		f["tx_tcp_goodbytes"] = s.TxTCPStats.Goodbytes.Val | ||||||
| 		fields["tx_tcp_lat_avg"] = s.TxTCPStats.LatAvg.Val | 		f["tx_tcp_lat_avg"] = s.TxTCPStats.LatAvg.Val | ||||||
| 		fields["tx_tcp_lat_max"] = s.TxTCPStats.LatMax.Val | 		f["tx_tcp_lat_max"] = s.TxTCPStats.LatMax.Val | ||||||
| 		fields["tx_tcp_lat_min"] = s.TxTCPStats.LatMin.Val | 		f["tx_tcp_lat_min"] = s.TxTCPStats.LatMin.Val | ||||||
| 		fields["rx_tcp_goodbytes"] = s.RxTCPStats.Goodbytes.Val | 		f["rx_tcp_goodbytes"] = s.RxTCPStats.Goodbytes.Val | ||||||
| 		fields["rx_tcp_lat_avg"] = s.RxTCPStats.LatAvg.Val | 		f["rx_tcp_lat_avg"] = s.RxTCPStats.LatAvg.Val | ||||||
| 		fields["rx_tcp_lat_max"] = s.RxTCPStats.LatMax.Val | 		f["rx_tcp_lat_max"] = s.RxTCPStats.LatMax.Val | ||||||
| 		fields["rx_tcp_lat_min"] = s.RxTCPStats.LatMin.Val | 		f["rx_tcp_lat_min"] = s.RxTCPStats.LatMin.Val | ||||||
| 		fields["wifi_tx_latency_mov_avg"] = s.WifiTxLatencyMov.Avg.Val | 		f["wifi_tx_latency_mov_avg"] = s.WifiTxLatencyMov.Avg.Val | ||||||
| 		fields["wifi_tx_latency_mov_max"] = s.WifiTxLatencyMov.Max.Val | 		f["wifi_tx_latency_mov_max"] = s.WifiTxLatencyMov.Max.Val | ||||||
| 		fields["wifi_tx_latency_mov_min"] = s.WifiTxLatencyMov.Min.Val | 		f["wifi_tx_latency_mov_min"] = s.WifiTxLatencyMov.Min.Val | ||||||
| 		fields["wifi_tx_latency_mov_total"] = s.WifiTxLatencyMov.Total.Val | 		f["wifi_tx_latency_mov_total"] = s.WifiTxLatencyMov.Total.Val | ||||||
| 		fields["wifi_tx_latency_mov_cuont"] = s.WifiTxLatencyMov.TotalCount.Val | 		f["wifi_tx_latency_mov_cuont"] = s.WifiTxLatencyMov.TotalCount.Val | ||||||
| 
 | 
 | ||||||
|  | 		// XXX: This is busted. It needs its own table....
 | ||||||
| 		for _, p := range rt { | 		for _, p := range rt { | ||||||
| 			if p.Name != s.RadioName { | 			if p.Name != s.RadioName { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			tags["channel"] = p.Channel.Txt | 			t["channel"] = p.Channel.Txt | ||||||
| 			tags["radio"] = p.Radio | 			t["radio"] = p.Radio | ||||||
| 			fields["current_antenna_gain"] = p.CurrentAntennaGain.Val | 			f["current_antenna_gain"] = p.CurrentAntennaGain.Val | ||||||
| 			fields["ht"] = p.Ht.Txt | 			f["ht"] = p.Ht.Txt | ||||||
| 			fields["max_txpower"] = p.MaxTxpower.Val | 			f["max_txpower"] = p.MaxTxpower.Val | ||||||
| 			fields["min_txpower"] = p.MinTxpower.Val | 			f["min_txpower"] = p.MinTxpower.Val | ||||||
| 			fields["nss"] = p.Nss.Val | 			f["nss"] = p.Nss.Val | ||||||
| 			fields["radio_caps"] = p.RadioCaps.Val | 			f["radio_caps"] = p.RadioCaps.Val | ||||||
| 			fields["tx_power"] = p.TxPower.Val | 			f["tx_power"] = p.TxPower.Val | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		for _, p := range rts { | 		for _, p := range rts { | ||||||
| 			if p.Name != s.RadioName { | 			if p.Name != s.RadioName { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			fields["ast_be_xmit"] = p.AstBeXmit.Val | 			f["ast_be_xmit"] = p.AstBeXmit.Val | ||||||
| 			fields["channel"] = p.Channel.Val | 			f["channel"] = p.Channel.Val | ||||||
| 			fields["cu_self_rx"] = p.CuSelfRx.Val | 			f["cu_self_rx"] = p.CuSelfRx.Val | ||||||
| 			fields["cu_self_tx"] = p.CuSelfTx.Val | 			f["cu_self_tx"] = p.CuSelfTx.Val | ||||||
| 			fields["cu_total"] = p.CuTotal.Val | 			f["cu_total"] = p.CuTotal.Val | ||||||
| 			fields["extchannel"] = p.Extchannel.Val | 			f["extchannel"] = p.Extchannel.Val | ||||||
| 			fields["gain"] = p.Gain.Val | 			f["gain"] = p.Gain.Val | ||||||
| 			fields["guest-num_sta"] = p.GuestNumSta.Val | 			f["guest-num_sta"] = p.GuestNumSta.Val | ||||||
| 			fields["num_sta"] = p.NumSta.Val | 			f["num_sta"] = p.NumSta.Val | ||||||
| 			fields["radio"] = p.Radio | 			f["radio"] = p.Radio | ||||||
| 			fields["tx_packets"] = p.TxPackets.Val | 			f["tx_packets"] = p.TxPackets.Val | ||||||
| 			fields["tx_power"] = p.TxPower.Val | 			f["tx_power"] = p.TxPower.Val | ||||||
| 			fields["tx_retries"] = p.TxRetries.Val | 			f["tx_retries"] = p.TxRetries.Val | ||||||
| 			fields["user-num_sta"] = p.UserNumSta.Val | 			f["user-num_sta"] = p.UserNumSta.Val | ||||||
| 		} | 		} | ||||||
| 		r.send(&metric{Table: "uap_vaps", Tags: tags, Fields: fields}) | 		r.send(&metric{Table: "uap_vaps", Tags: t, Fields: f}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,6 +4,32 @@ import ( | ||||||
| 	"golift.io/unifi" | 	"golift.io/unifi" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | // Combines concatenates N maps. This will delete things if not used with caution.
 | ||||||
|  | func Combine(in ...map[string]interface{}) map[string]interface{} { | ||||||
|  | 	out := make(map[string]interface{}) | ||||||
|  | 	for i := range in { | ||||||
|  | 		for k := range in[i] { | ||||||
|  | 			out[k] = in[i][k] | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return out | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // batchSysStats is used by all device types.
 | ||||||
|  | func (u *InfluxUnifi) batchSysStats(r report, s unifi.SysStats, ss unifi.SystemStats) map[string]interface{} { | ||||||
|  | 	return map[string]interface{}{ | ||||||
|  | 		"loadavg_1":     s.Loadavg1.Val, | ||||||
|  | 		"loadavg_5":     s.Loadavg5.Val, | ||||||
|  | 		"loadavg_15":    s.Loadavg15.Val, | ||||||
|  | 		"mem_used":      s.MemUsed.Val, | ||||||
|  | 		"mem_buffer":    s.MemBuffer.Val, | ||||||
|  | 		"mem_total":     s.MemTotal.Val, | ||||||
|  | 		"cpu":           ss.CPU.Val, | ||||||
|  | 		"mem":           ss.Mem.Val, | ||||||
|  | 		"system_uptime": ss.Uptime.Val, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // batchUDM generates Unifi Gateway datapoints for InfluxDB.
 | // batchUDM generates Unifi Gateway datapoints for InfluxDB.
 | ||||||
| // These points can be passed directly to influx.
 | // These points can be passed directly to influx.
 | ||||||
| func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { | func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { | ||||||
|  | @ -22,7 +48,7 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { | ||||||
| 		"serial":    s.Serial, | 		"serial":    s.Serial, | ||||||
| 		"type":      s.Type, | 		"type":      s.Type, | ||||||
| 	} | 	} | ||||||
| 	fields := map[string]interface{}{ | 	fields := Combine(map[string]interface{}{ | ||||||
| 		"ip":                             s.IP, | 		"ip":                             s.IP, | ||||||
| 		"bytes":                          s.Bytes.Val, | 		"bytes":                          s.Bytes.Val, | ||||||
| 		"last_seen":                      s.LastSeen.Val, | 		"last_seen":                      s.LastSeen.Val, | ||||||
|  | @ -42,72 +68,14 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { | ||||||
| 		"speedtest-status_ping":          s.SpeedtestStatus.StatusPing.Val, | 		"speedtest-status_ping":          s.SpeedtestStatus.StatusPing.Val, | ||||||
| 		"speedtest-status_xput_download": s.SpeedtestStatus.XputDownload.Val, | 		"speedtest-status_xput_download": s.SpeedtestStatus.XputDownload.Val, | ||||||
| 		"speedtest-status_xput_upload":   s.SpeedtestStatus.XputUpload.Val, | 		"speedtest-status_xput_upload":   s.SpeedtestStatus.XputUpload.Val, | ||||||
| 		"wan1_bytes-r":                   s.Wan1.BytesR.Val, | 		"lan-rx_bytes":                   s.Stat.Gw.LanRxBytes.Val, | ||||||
| 		"wan1_enable":                    s.Wan1.Enable.Val, | 		"lan-rx_packets":                 s.Stat.Gw.LanRxPackets.Val, | ||||||
| 		"wan1_full_duplex":               s.Wan1.FullDuplex.Val, | 		"lan-tx_bytes":                   s.Stat.Gw.LanTxBytes.Val, | ||||||
| 		"wan1_gateway":                   s.Wan1.Gateway, | 		"lan-tx_packets":                 s.Stat.Gw.LanTxPackets.Val, | ||||||
| 		"wan1_ifname":                    s.Wan1.Ifname, | 	}, u.batchSysStats(r, s.SysStats, s.SystemStats)) | ||||||
| 		"wan1_ip":                        s.Wan1.IP, |  | ||||||
| 		"wan1_mac":                       s.Wan1.Mac, |  | ||||||
| 		"wan1_max_speed":                 s.Wan1.MaxSpeed.Val, |  | ||||||
| 		"wan1_name":                      s.Wan1.Name, |  | ||||||
| 		"wan1_rx_bytes":                  s.Wan1.RxBytes.Val, |  | ||||||
| 		"wan1_rx_bytes-r":                s.Wan1.RxBytesR.Val, |  | ||||||
| 		"wan1_rx_dropped":                s.Wan1.RxDropped.Val, |  | ||||||
| 		"wan1_rx_errors":                 s.Wan1.RxErrors.Val, |  | ||||||
| 		"wan1_rx_multicast":              s.Wan1.RxMulticast.Val, |  | ||||||
| 		"wan1_rx_packets":                s.Wan1.RxPackets.Val, |  | ||||||
| 		"wan1_type":                      s.Wan1.Type, |  | ||||||
| 		"wan1_speed":                     s.Wan1.Speed.Val, |  | ||||||
| 		"wan1_up":                        s.Wan1.Up.Val, |  | ||||||
| 		"wan1_tx_bytes":                  s.Wan1.TxBytes.Val, |  | ||||||
| 		"wan1_tx_bytes-r":                s.Wan1.TxBytesR.Val, |  | ||||||
| 		"wan1_tx_dropped":                s.Wan1.TxDropped.Val, |  | ||||||
| 		"wan1_tx_errors":                 s.Wan1.TxErrors.Val, |  | ||||||
| 		"wan1_tx_packets":                s.Wan1.TxPackets.Val, |  | ||||||
| 		"wan2_bytes-r":                   s.Wan2.BytesR.Val, |  | ||||||
| 		"wan2_enable":                    s.Wan2.Enable.Val, |  | ||||||
| 		"wan2_full_duplex":               s.Wan2.FullDuplex.Val, |  | ||||||
| 		"wan2_gateway":                   s.Wan2.Gateway, |  | ||||||
| 		"wan2_ifname":                    s.Wan2.Ifname, |  | ||||||
| 		"wan2_ip":                        s.Wan2.IP, |  | ||||||
| 		"wan2_mac":                       s.Wan2.Mac, |  | ||||||
| 		"wan2_max_speed":                 s.Wan2.MaxSpeed.Val, |  | ||||||
| 		"wan2_name":                      s.Wan2.Name, |  | ||||||
| 		"wan2_rx_bytes":                  s.Wan2.RxBytes.Val, |  | ||||||
| 		"wan2_rx_bytes-r":                s.Wan2.RxBytesR.Val, |  | ||||||
| 		"wan2_rx_dropped":                s.Wan2.RxDropped.Val, |  | ||||||
| 		"wan2_rx_errors":                 s.Wan2.RxErrors.Val, |  | ||||||
| 		"wan2_rx_multicast":              s.Wan2.RxMulticast.Val, |  | ||||||
| 		"wan2_rx_packets":                s.Wan2.RxPackets.Val, |  | ||||||
| 		"wan2_type":                      s.Wan2.Type, |  | ||||||
| 		"wan2_speed":                     s.Wan2.Speed.Val, |  | ||||||
| 		"wan2_up":                        s.Wan2.Up.Val, |  | ||||||
| 		"wan2_tx_bytes":                  s.Wan2.TxBytes.Val, |  | ||||||
| 		"wan2_tx_bytes-r":                s.Wan2.TxBytesR.Val, |  | ||||||
| 		"wan2_tx_dropped":                s.Wan2.TxDropped.Val, |  | ||||||
| 		"wan2_tx_errors":                 s.Wan2.TxErrors.Val, |  | ||||||
| 		"wan2_tx_packets":                s.Wan2.TxPackets.Val, |  | ||||||
| 		"loadavg_1":                      s.SysStats.Loadavg1.Val, |  | ||||||
| 		"loadavg_5":                      s.SysStats.Loadavg5.Val, |  | ||||||
| 		"loadavg_15":                     s.SysStats.Loadavg15.Val, |  | ||||||
| 		"mem_used":                       s.SysStats.MemUsed.Val, |  | ||||||
| 		"mem_buffer":                     s.SysStats.MemBuffer.Val, |  | ||||||
| 		"mem_total":                      s.SysStats.MemTotal.Val, |  | ||||||
| 		"cpu":                            s.SystemStats.CPU.Val, |  | ||||||
| 		"mem":                            s.SystemStats.Mem.Val, |  | ||||||
| 		"system_uptime":                  s.SystemStats.Uptime.Val, |  | ||||||
| 		"lan-rx_bytes":                   s.Stat.LanRxBytes.Val, |  | ||||||
| 		"lan-rx_packets":                 s.Stat.LanRxPackets.Val, |  | ||||||
| 		"lan-tx_bytes":                   s.Stat.LanTxBytes.Val, |  | ||||||
| 		"lan-tx_packets":                 s.Stat.LanTxPackets.Val, |  | ||||||
| 		"wan-rx_bytes":                   s.Stat.WanRxBytes.Val, |  | ||||||
| 		"wan-rx_dropped":                 s.Stat.WanRxDropped.Val, |  | ||||||
| 		"wan-rx_packets":                 s.Stat.WanRxPackets.Val, |  | ||||||
| 		"wan-tx_bytes":                   s.Stat.WanTxBytes.Val, |  | ||||||
| 		"wan-tx_packets":                 s.Stat.WanTxPackets.Val, |  | ||||||
| 	} |  | ||||||
| 	r.send(&metric{Table: "usg", Tags: tags, Fields: fields}) | 	r.send(&metric{Table: "usg", Tags: tags, Fields: fields}) | ||||||
|  | 	u.batchNetworkTable(r, tags, s.NetworkTable) | ||||||
|  | 	u.batchUSGwans(r, tags, s.Wan1, s.Wan2) | ||||||
| 
 | 
 | ||||||
| 	tags = map[string]string{ | 	tags = map[string]string{ | ||||||
| 		"mac":       s.Mac, | 		"mac":       s.Mac, | ||||||
|  | @ -127,16 +95,6 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { | ||||||
| 		"tx_bytes":        s.TxBytes.Val, | 		"tx_bytes":        s.TxBytes.Val, | ||||||
| 		"uptime":          s.Uptime.Val, | 		"uptime":          s.Uptime.Val, | ||||||
| 		"state":           s.State.Val, | 		"state":           s.State.Val, | ||||||
| 		"user-num_sta":    s.UserNumSta.Val, |  | ||||||
| 		"loadavg_1":       s.SysStats.Loadavg1.Val, |  | ||||||
| 		"loadavg_5":       s.SysStats.Loadavg5.Val, |  | ||||||
| 		"loadavg_15":      s.SysStats.Loadavg15.Val, |  | ||||||
| 		"mem_buffer":      s.SysStats.MemBuffer.Val, |  | ||||||
| 		"mem_used":        s.SysStats.MemUsed.Val, |  | ||||||
| 		"mem_total":       s.SysStats.MemTotal.Val, |  | ||||||
| 		"cpu":             s.SystemStats.CPU.Val, |  | ||||||
| 		"mem":             s.SystemStats.Mem.Val, |  | ||||||
| 		"system_uptime":   s.SystemStats.Uptime.Val, |  | ||||||
| 		"stat_bytes":      s.Stat.Sw.Bytes.Val, | 		"stat_bytes":      s.Stat.Sw.Bytes.Val, | ||||||
| 		"stat_rx_bytes":   s.Stat.Sw.RxBytes.Val, | 		"stat_rx_bytes":   s.Stat.Sw.RxBytes.Val, | ||||||
| 		"stat_rx_crypts":  s.Stat.Sw.RxCrypts.Val, | 		"stat_rx_crypts":  s.Stat.Sw.RxCrypts.Val, | ||||||
|  | @ -151,85 +109,8 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { | ||||||
| 		"stat_tx_retries": s.Stat.Sw.TxRetries.Val, | 		"stat_tx_retries": s.Stat.Sw.TxRetries.Val, | ||||||
| 	} | 	} | ||||||
| 	r.send(&metric{Table: "usw", Tags: tags, Fields: fields}) | 	r.send(&metric{Table: "usw", Tags: tags, Fields: fields}) | ||||||
|  | 	u.batchPortTable(r, tags, s.PortTable) | ||||||
| 
 | 
 | ||||||
| 	for _, p := range s.NetworkTable { |  | ||||||
| 		tags := map[string]string{ |  | ||||||
| 			"device_name": s.Name, |  | ||||||
| 			"device_id":   s.ID, |  | ||||||
| 			"device_mac":  s.Mac, |  | ||||||
| 			"site_name":   s.SiteName, |  | ||||||
| 			"up":          p.Up.Txt, |  | ||||||
| 			"enabled":     p.Enabled.Txt, |  | ||||||
| 			"site_id":     p.SiteID, |  | ||||||
| 			"ip":          p.IP, |  | ||||||
| 			"ip_subnet":   p.IPSubnet, |  | ||||||
| 			"mac":         p.Mac, |  | ||||||
| 			"name":        p.Name, |  | ||||||
| 			"domain_name": p.DomainName, |  | ||||||
| 			"purpose":     p.Purpose, |  | ||||||
| 		} |  | ||||||
| 		fields := map[string]interface{}{ |  | ||||||
| 			"domain_name":         p.DomainName, |  | ||||||
| 			"dhcpd_start":         p.DhcpdStart, |  | ||||||
| 			"dhcpd_stop":          p.DhcpdStop, |  | ||||||
| 			"ip":                  p.IP, |  | ||||||
| 			"ip_subnet":           p.IPSubnet, |  | ||||||
| 			"mac":                 p.Mac, |  | ||||||
| 			"name":                p.Name, |  | ||||||
| 			"num_sta":             p.NumSta.Val, |  | ||||||
| 			"purpose":             p.Purpose, |  | ||||||
| 			"rx_bytes":            p.RxBytes.Val, |  | ||||||
| 			"rx_packets":          p.RxPackets.Val, |  | ||||||
| 			"tx_bytes":            p.TxBytes.Val, |  | ||||||
| 			"tx_packets":          p.TxPackets.Val, |  | ||||||
| 			"ipv6_interface_type": p.Ipv6InterfaceType, |  | ||||||
| 			"attr_hidden_id":      p.AttrHiddenID, |  | ||||||
| 		} |  | ||||||
| 		r.send(&metric{Table: "usg_networks", Tags: tags, Fields: fields}) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	for _, p := range s.PortTable { |  | ||||||
| 		tags := map[string]string{ |  | ||||||
| 			"site_id":     s.SiteID, |  | ||||||
| 			"site_name":   s.SiteName, |  | ||||||
| 			"device_name": s.Name, |  | ||||||
| 			"name":        p.Name, |  | ||||||
| 			"enable":      p.Enable.Txt, |  | ||||||
| 			"up":          p.Up.Txt, |  | ||||||
| 			"poe_mode":    p.PoeMode, |  | ||||||
| 			"port_poe":    p.PortPoe.Txt, |  | ||||||
| 			"port_idx":    p.PortIdx.Txt, |  | ||||||
| 			"port_id":     s.Name + " Port " + p.PortIdx.Txt, |  | ||||||
| 			"poe_enable":  p.PoeEnable.Txt, |  | ||||||
| 			"flowctrl_rx": p.FlowctrlRx.Txt, |  | ||||||
| 			"flowctrl_tx": p.FlowctrlTx.Txt, |  | ||||||
| 			"media":       p.Media, |  | ||||||
| 			"poe_class":   p.PoeClass, |  | ||||||
| 		} |  | ||||||
| 		fields := map[string]interface{}{ |  | ||||||
| 			"dbytes_r":     p.BytesR.Val, |  | ||||||
| 			"rx_broadcast": p.RxBroadcast.Val, |  | ||||||
| 			"rx_bytes":     p.RxBytes.Val, |  | ||||||
| 			"rx_bytes-r":   p.RxBytesR.Val, |  | ||||||
| 			"rx_dropped":   p.RxDropped.Val, |  | ||||||
| 			"rx_errors":    p.RxErrors.Val, |  | ||||||
| 			"rx_multicast": p.RxMulticast.Val, |  | ||||||
| 			"rx_packets":   p.RxPackets.Val, |  | ||||||
| 			"speed":        p.Speed.Val, |  | ||||||
| 			"stp_pathcost": p.StpPathcost.Val, |  | ||||||
| 			"tx_broadcast": p.TxBroadcast.Val, |  | ||||||
| 			"tx_bytes":     p.TxBytes.Val, |  | ||||||
| 			"tx_bytes-r":   p.TxBytesR.Val, |  | ||||||
| 			"tx_dropped":   p.TxDropped.Val, |  | ||||||
| 			"tx_errors":    p.TxErrors.Val, |  | ||||||
| 			"tx_multicast": p.TxMulticast.Val, |  | ||||||
| 			"tx_packets":   p.TxPackets.Val, |  | ||||||
| 			"poe_current":  p.PoeCurrent.Val, |  | ||||||
| 			"poe_power":    p.PoePower.Val, |  | ||||||
| 			"poe_voltage":  p.PoeVoltage.Val, |  | ||||||
| 		} |  | ||||||
| 		r.send(&metric{Table: "usw_ports", Tags: tags, Fields: fields}) |  | ||||||
| 	} |  | ||||||
| 	if s.Stat.Ap == nil { | 	if s.Stat.Ap == nil { | ||||||
| 		return | 		return | ||||||
| 		// we're done now. the following code process UDM (non-pro) UAP data.
 | 		// we're done now. the following code process UDM (non-pro) UAP data.
 | ||||||
|  | @ -243,60 +124,17 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) { | ||||||
| 		"serial":    s.Serial, | 		"serial":    s.Serial, | ||||||
| 		"type":      s.Type, | 		"type":      s.Type, | ||||||
| 	} | 	} | ||||||
| 	fields = map[string]interface{}{ | 	fields = u.processUAPstats(r, s.Stat.Ap) | ||||||
| 		"ip":            s.IP, | 	fields["ip"] = s.IP | ||||||
| 		"bytes":         s.Bytes.Val, | 	fields["bytes"] = s.Bytes.Val | ||||||
| 		"last_seen":     s.LastSeen.Val, | 	fields["last_seen"] = s.LastSeen.Val | ||||||
| 		"rx_bytes":      s.RxBytes.Val, | 	fields["rx_bytes"] = s.RxBytes.Val | ||||||
| 		"tx_bytes":      s.TxBytes.Val, | 	fields["tx_bytes"] = s.TxBytes.Val | ||||||
| 		"uptime":        s.Uptime.Val, | 	fields["uptime"] = s.Uptime.Val | ||||||
| 		"state":         int(s.State.Val), | 	fields["state"] = s.State | ||||||
| 		"user-num_sta":  int(s.UserWlanNumSta.Val), | 	fields["user-num_sta"] = int(s.UserNumSta.Val) | ||||||
| 		"guest-num_sta": int(s.GuestWlanNumSta.Val), | 	fields["guest-num_sta"] = int(s.GuestNumSta.Val) | ||||||
| 		"num_sta":       s.WlanNumSta.Val, | 	fields["num_sta"] = s.NumSta.Val | ||||||
| 		"loadavg_1":     s.SysStats.Loadavg1.Val, |  | ||||||
| 		"loadavg_5":     s.SysStats.Loadavg5.Val, |  | ||||||
| 		"loadavg_15":    s.SysStats.Loadavg15.Val, |  | ||||||
| 		"mem_buffer":    s.SysStats.MemBuffer.Val, |  | ||||||
| 		"mem_total":     s.SysStats.MemTotal.Val, |  | ||||||
| 		"mem_used":      s.SysStats.MemUsed.Val, |  | ||||||
| 		"cpu":           s.SystemStats.CPU.Val, |  | ||||||
| 		"mem":           s.SystemStats.Mem.Val, |  | ||||||
| 		"system_uptime": s.SystemStats.Uptime.Val, |  | ||||||
| 		// Accumulative Statistics.
 |  | ||||||
| 		"stat_user-rx_packets":  s.Stat.Ap.UserRxPackets.Val, |  | ||||||
| 		"stat_guest-rx_packets": s.Stat.Ap.GuestRxPackets.Val, |  | ||||||
| 		"stat_rx_packets":       s.Stat.Ap.RxPackets.Val, |  | ||||||
| 		"stat_user-rx_bytes":    s.Stat.Ap.UserRxBytes.Val, |  | ||||||
| 		"stat_guest-rx_bytes":   s.Stat.Ap.GuestRxBytes.Val, |  | ||||||
| 		"stat_rx_bytes":         s.Stat.Ap.RxBytes.Val, |  | ||||||
| 		"stat_user-rx_errors":   s.Stat.Ap.UserRxErrors.Val, |  | ||||||
| 		"stat_guest-rx_errors":  s.Stat.Ap.GuestRxErrors.Val, |  | ||||||
| 		"stat_rx_errors":        s.Stat.Ap.RxErrors.Val, |  | ||||||
| 		"stat_user-rx_dropped":  s.Stat.Ap.UserRxDropped.Val, |  | ||||||
| 		"stat_guest-rx_dropped": s.Stat.Ap.GuestRxDropped.Val, |  | ||||||
| 		"stat_rx_dropped":       s.Stat.Ap.RxDropped.Val, |  | ||||||
| 		"stat_user-rx_crypts":   s.Stat.Ap.UserRxCrypts.Val, |  | ||||||
| 		"stat_guest-rx_crypts":  s.Stat.Ap.GuestRxCrypts.Val, |  | ||||||
| 		"stat_rx_crypts":        s.Stat.Ap.RxCrypts.Val, |  | ||||||
| 		"stat_user-rx_frags":    s.Stat.Ap.UserRxFrags.Val, |  | ||||||
| 		"stat_guest-rx_frags":   s.Stat.Ap.GuestRxFrags.Val, |  | ||||||
| 		"stat_rx_frags":         s.Stat.Ap.RxFrags.Val, |  | ||||||
| 		"stat_user-tx_packets":  s.Stat.Ap.UserTxPackets.Val, |  | ||||||
| 		"stat_guest-tx_packets": s.Stat.Ap.GuestTxPackets.Val, |  | ||||||
| 		"stat_tx_packets":       s.Stat.Ap.TxPackets.Val, |  | ||||||
| 		"stat_user-tx_bytes":    s.Stat.Ap.UserTxBytes.Val, |  | ||||||
| 		"stat_guest-tx_bytes":   s.Stat.Ap.GuestTxBytes.Val, |  | ||||||
| 		"stat_tx_bytes":         s.Stat.Ap.TxBytes.Val, |  | ||||||
| 		"stat_user-tx_errors":   s.Stat.Ap.UserTxErrors.Val, |  | ||||||
| 		"stat_guest-tx_errors":  s.Stat.Ap.GuestTxErrors.Val, |  | ||||||
| 		"stat_tx_errors":        s.Stat.Ap.TxErrors.Val, |  | ||||||
| 		"stat_user-tx_dropped":  s.Stat.Ap.UserTxDropped.Val, |  | ||||||
| 		"stat_guest-tx_dropped": s.Stat.Ap.GuestTxDropped.Val, |  | ||||||
| 		"stat_tx_dropped":       s.Stat.Ap.TxDropped.Val, |  | ||||||
| 		"stat_user-tx_retries":  s.Stat.Ap.UserTxRetries.Val, |  | ||||||
| 		"stat_guest-tx_retries": s.Stat.Ap.GuestTxRetries.Val, |  | ||||||
| 	} |  | ||||||
| 	r.send(&metric{Table: "uap", Tags: tags, Fields: fields}) | 	r.send(&metric{Table: "uap", Tags: tags, Fields: fields}) | ||||||
| 	u.processVAPs(r, *s.VapTable, *s.RadioTable, *s.RadioTableStats, s.Name, s.Mac, s.SiteName) | 	u.processVAPs(r, tags, *s.VapTable, *s.RadioTable, *s.RadioTableStats) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,8 +1,6 @@ | ||||||
| package influxunifi | package influxunifi | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"strings" |  | ||||||
| 
 |  | ||||||
| 	"golift.io/unifi" | 	"golift.io/unifi" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -41,84 +39,93 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) { | ||||||
| 		"speedtest-status_ping":          s.SpeedtestStatus.StatusPing.Val, | 		"speedtest-status_ping":          s.SpeedtestStatus.StatusPing.Val, | ||||||
| 		"speedtest-status_xput_download": s.SpeedtestStatus.XputDownload.Val, | 		"speedtest-status_xput_download": s.SpeedtestStatus.XputDownload.Val, | ||||||
| 		"speedtest-status_xput_upload":   s.SpeedtestStatus.XputUpload.Val, | 		"speedtest-status_xput_upload":   s.SpeedtestStatus.XputUpload.Val, | ||||||
| 		"wan1_bytes-r":                   s.Wan1.BytesR.Val, | 		"lan-rx_bytes":                   s.Stat.Gw.LanRxBytes.Val, | ||||||
| 		"wan1_enable":                    s.Wan1.Enable.Val, | 		"lan-rx_packets":                 s.Stat.Gw.LanRxPackets.Val, | ||||||
| 		"wan1_full_duplex":               s.Wan1.FullDuplex.Val, | 		"lan-tx_bytes":                   s.Stat.Gw.LanTxBytes.Val, | ||||||
| 		"wan1_gateway":                   s.Wan1.Gateway, | 		"lan-tx_packets":                 s.Stat.Gw.LanTxPackets.Val, | ||||||
| 		"wan1_ifname":                    s.Wan1.Ifname, |  | ||||||
| 		"wan1_ip":                        s.Wan1.IP, |  | ||||||
| 		"wan1_mac":                       s.Wan1.Mac, |  | ||||||
| 		"wan1_max_speed":                 s.Wan1.MaxSpeed.Val, |  | ||||||
| 		"wan1_name":                      s.Wan1.Name, |  | ||||||
| 		"wan1_rx_bytes":                  s.Wan1.RxBytes.Val, |  | ||||||
| 		"wan1_rx_bytes-r":                s.Wan1.RxBytesR.Val, |  | ||||||
| 		"wan1_rx_dropped":                s.Wan1.RxDropped.Val, |  | ||||||
| 		"wan1_rx_errors":                 s.Wan1.RxErrors.Val, |  | ||||||
| 		"wan1_rx_multicast":              s.Wan1.RxMulticast.Val, |  | ||||||
| 		"wan1_rx_packets":                s.Wan1.RxPackets.Val, |  | ||||||
| 		"wan1_type":                      s.Wan1.Type, |  | ||||||
| 		"wan1_speed":                     s.Wan1.Speed.Val, |  | ||||||
| 		"wan1_up":                        s.Wan1.Up.Val, |  | ||||||
| 		"wan1_tx_bytes":                  s.Wan1.TxBytes.Val, |  | ||||||
| 		"wan1_tx_bytes-r":                s.Wan1.TxBytesR.Val, |  | ||||||
| 		"wan1_tx_dropped":                s.Wan1.TxDropped.Val, |  | ||||||
| 		"wan1_tx_errors":                 s.Wan1.TxErrors.Val, |  | ||||||
| 		"wan1_tx_packets":                s.Wan1.TxPackets.Val, |  | ||||||
| 		"wan2_bytes-r":                   s.Wan2.BytesR.Val, |  | ||||||
| 		"wan2_enable":                    s.Wan2.Enable.Val, |  | ||||||
| 		"wan2_full_duplex":               s.Wan2.FullDuplex.Val, |  | ||||||
| 		"wan2_gateway":                   s.Wan2.Gateway, |  | ||||||
| 		"wan2_ifname":                    s.Wan2.Ifname, |  | ||||||
| 		"wan2_ip":                        s.Wan2.IP, |  | ||||||
| 		"wan2_mac":                       s.Wan2.Mac, |  | ||||||
| 		"wan2_max_speed":                 s.Wan2.MaxSpeed.Val, |  | ||||||
| 		"wan2_name":                      s.Wan2.Name, |  | ||||||
| 		"wan2_rx_bytes":                  s.Wan2.RxBytes.Val, |  | ||||||
| 		"wan2_rx_bytes-r":                s.Wan2.RxBytesR.Val, |  | ||||||
| 		"wan2_rx_dropped":                s.Wan2.RxDropped.Val, |  | ||||||
| 		"wan2_rx_errors":                 s.Wan2.RxErrors.Val, |  | ||||||
| 		"wan2_rx_multicast":              s.Wan2.RxMulticast.Val, |  | ||||||
| 		"wan2_rx_packets":                s.Wan2.RxPackets.Val, |  | ||||||
| 		"wan2_type":                      s.Wan2.Type, |  | ||||||
| 		"wan2_speed":                     s.Wan2.Speed.Val, |  | ||||||
| 		"wan2_up":                        s.Wan2.Up.Val, |  | ||||||
| 		"wan2_tx_bytes":                  s.Wan2.TxBytes.Val, |  | ||||||
| 		"wan2_tx_bytes-r":                s.Wan2.TxBytesR.Val, |  | ||||||
| 		"wan2_tx_dropped":                s.Wan2.TxDropped.Val, |  | ||||||
| 		"wan2_tx_errors":                 s.Wan2.TxErrors.Val, |  | ||||||
| 		"wan2_tx_packets":                s.Wan2.TxPackets.Val, |  | ||||||
| 		"loadavg_1":                      s.SysStats.Loadavg1.Val, |  | ||||||
| 		"loadavg_5":                      s.SysStats.Loadavg5.Val, |  | ||||||
| 		"loadavg_15":                     s.SysStats.Loadavg15.Val, |  | ||||||
| 		"mem_used":                       s.SysStats.MemUsed.Val, |  | ||||||
| 		"mem_buffer":                     s.SysStats.MemBuffer.Val, |  | ||||||
| 		"mem_total":                      s.SysStats.MemTotal.Val, |  | ||||||
| 		"cpu":                            s.SystemStats.CPU.Val, |  | ||||||
| 		"mem":                            s.SystemStats.Mem.Val, |  | ||||||
| 		"system_uptime":                  s.SystemStats.Uptime.Val, |  | ||||||
| 		"lan-rx_bytes":                   s.Stat.LanRxBytes.Val, |  | ||||||
| 		"lan-rx_packets":                 s.Stat.LanRxPackets.Val, |  | ||||||
| 		"lan-tx_bytes":                   s.Stat.LanTxBytes.Val, |  | ||||||
| 		"lan-tx_packets":                 s.Stat.LanTxPackets.Val, |  | ||||||
| 		"wan-rx_bytes":                   s.Stat.WanRxBytes.Val, |  | ||||||
| 		"wan-rx_dropped":                 s.Stat.WanRxDropped.Val, |  | ||||||
| 		"wan-rx_packets":                 s.Stat.WanRxPackets.Val, |  | ||||||
| 		"wan-tx_bytes":                   s.Stat.WanTxBytes.Val, |  | ||||||
| 		"wan-tx_packets":                 s.Stat.WanTxPackets.Val, |  | ||||||
| 	} | 	} | ||||||
|  | 	/* | ||||||
|  | 		for _, p := range s.PortTable { | ||||||
|  | 			t := map[string]string{ | ||||||
|  | 				"device_name": tags["name"], | ||||||
|  | 				"site_name":   tags["site_name"], | ||||||
|  | 				"name":        p.Name, | ||||||
|  | 				"ifname":      p.Ifname, | ||||||
|  | 				"ip":          p.IP, | ||||||
|  | 				"mac":         p.Mac, | ||||||
|  | 				"up":          p.Up.Txt, | ||||||
|  | 				"speed":       p.Speed.Txt, | ||||||
|  | 				"full_duplex": p.FullDuplex.Txt, | ||||||
|  | 				"enable":      p.Enable.Txt, | ||||||
|  | 			} | ||||||
|  | 			f := map[string]interface{}{ | ||||||
|  | 				"rx_bytes":     p.RxBytes.Val, | ||||||
|  | 				"rx_dropped":   p.RxDropped.Val, | ||||||
|  | 				"rx_errors":    p.RxErrors.Val, | ||||||
|  | 				"rx_packets":   p.RxBytes.Val, | ||||||
|  | 				"tx_bytes":     p.TxBytes.Val, | ||||||
|  | 				"tx_dropped":   p.TxDropped.Val, | ||||||
|  | 				"tx_errors":    p.TxErrors.Val, | ||||||
|  | 				"tx_packets":   p.TxPackets.Val, | ||||||
|  | 				"rx_multicast": p.RxMulticast.Val, | ||||||
|  | 				"dns_servers":  strings.Join(p.DNS, ","), | ||||||
|  | 			} | ||||||
|  | 			r.send(&metric{Table: "usg_ports", Tags: t, Fields: f}) | ||||||
|  | 		} | ||||||
|  | 	*/ | ||||||
|  | 	fields = Combine(fields, u.batchSysStats(r, s.SysStats, s.SystemStats)) | ||||||
| 	r.send(&metric{Table: "usg", Tags: tags, Fields: fields}) | 	r.send(&metric{Table: "usg", Tags: tags, Fields: fields}) | ||||||
|  | 	u.batchNetworkTable(r, tags, s.NetworkTable) | ||||||
|  | 	u.batchUSGwans(r, tags, s.Wan1, s.Wan2) | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| 	for _, p := range s.NetworkTable { | func (u *InfluxUnifi) batchUSGwans(r report, tags map[string]string, wans ...unifi.Wan) { | ||||||
|  | 	for _, wan := range wans { | ||||||
|  | 		if !wan.Up.Val { | ||||||
|  | 			continue | ||||||
|  | 		} | ||||||
| 		tags := map[string]string{ | 		tags := map[string]string{ | ||||||
| 			"device_name": s.Name, | 			"device_name": tags["name"], | ||||||
| 			"device_id":   s.ID, | 			"site_name":   tags["site_name"], | ||||||
| 			"device_mac":  s.Mac, | 			"wan_name":    wan.Name, | ||||||
| 			"site_name":   s.SiteName, | 		} | ||||||
|  | 		fields := map[string]interface{}{ | ||||||
|  | 			"bytes-r":      wan.BytesR.Val, | ||||||
|  | 			"enable":       wan.Enable.Val, | ||||||
|  | 			"full_duplex":  wan.FullDuplex.Val, | ||||||
|  | 			"gateway":      wan.Gateway, | ||||||
|  | 			"ifname":       wan.Ifname, | ||||||
|  | 			"ip":           wan.IP, | ||||||
|  | 			"mac":          wan.Mac, | ||||||
|  | 			"max_speed":    wan.MaxSpeed.Val, | ||||||
|  | 			"name":         wan.Name, | ||||||
|  | 			"rx_bytes":     wan.RxBytes.Val, | ||||||
|  | 			"rx_bytes-r":   wan.RxBytesR.Val, | ||||||
|  | 			"rx_dropped":   wan.RxDropped.Val, | ||||||
|  | 			"rx_errors":    wan.RxErrors.Val, | ||||||
|  | 			"rx_multicast": wan.RxMulticast.Val, | ||||||
|  | 			"rx_packets":   wan.RxPackets.Val, | ||||||
|  | 			"type":         wan.Type, | ||||||
|  | 			"speed":        wan.Speed.Val, | ||||||
|  | 			"up":           wan.Up.Val, | ||||||
|  | 			"tx_bytes":     wan.TxBytes.Val, | ||||||
|  | 			"tx_bytes-r":   wan.TxBytesR.Val, | ||||||
|  | 			"tx_dropped":   wan.TxDropped.Val, | ||||||
|  | 			"tx_errors":    wan.TxErrors.Val, | ||||||
|  | 			"tx_packets":   wan.TxPackets.Val, | ||||||
|  | 		} | ||||||
|  | 		r.send(&metric{Table: "usg_wan_ports", Tags: tags, Fields: fields}) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (u *InfluxUnifi) batchNetworkTable(r report, tags map[string]string, nt unifi.NetworkTable) { | ||||||
|  | 	for _, p := range nt { | ||||||
|  | 		tags := map[string]string{ | ||||||
|  | 			"device_name": tags["name"], | ||||||
|  | 			"site_name":   tags["site_name"], | ||||||
| 			"up":          p.Up.Txt, | 			"up":          p.Up.Txt, | ||||||
| 			"enabled":     p.Enabled.Txt, | 			"enabled":     p.Enabled.Txt, | ||||||
| 			"site_id":     p.SiteID, |  | ||||||
| 			"ip":          p.IP, | 			"ip":          p.IP, | ||||||
| 			"ip_subnet":   p.IPSubnet, |  | ||||||
| 			"mac":         p.Mac, | 			"mac":         p.Mac, | ||||||
| 			"name":        p.Name, | 			"name":        p.Name, | ||||||
| 			"domain_name": p.DomainName, | 			"domain_name": p.DomainName, | ||||||
|  | @ -133,34 +140,4 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) { | ||||||
| 		} | 		} | ||||||
| 		r.send(&metric{Table: "usg_networks", Tags: tags, Fields: fields}) | 		r.send(&metric{Table: "usg_networks", Tags: tags, Fields: fields}) | ||||||
| 	} | 	} | ||||||
| 	for _, p := range s.PortTable { |  | ||||||
| 		tags := map[string]string{ |  | ||||||
| 			"device_name": s.Name, |  | ||||||
| 			"device_id":   s.ID, |  | ||||||
| 			"device_mac":  s.Mac, |  | ||||||
| 			"site_name":   s.SiteName, |  | ||||||
| 			"name":        p.Name, |  | ||||||
| 			"ifname":      p.Ifname, |  | ||||||
| 			"ip":          p.IP, |  | ||||||
| 			"mac":         p.Mac, |  | ||||||
| 			"up":          p.Up.Txt, |  | ||||||
| 			"speed":       p.Speed.Txt, |  | ||||||
| 			"full_duplex": p.FullDuplex.Txt, |  | ||||||
| 			"enable":      p.Enable.Txt, |  | ||||||
| 		} |  | ||||||
| 		fields := map[string]interface{}{ |  | ||||||
| 			"rx_bytes":     p.RxBytes.Val, |  | ||||||
| 			"rx_dropped":   p.RxDropped.Val, |  | ||||||
| 			"rx_errors":    p.RxErrors.Val, |  | ||||||
| 			"rx_packets":   p.RxBytes.Val, |  | ||||||
| 			"tx_bytes":     p.TxBytes.Val, |  | ||||||
| 			"tx_dropped":   p.TxDropped.Val, |  | ||||||
| 			"tx_errors":    p.TxErrors.Val, |  | ||||||
| 			"tx_packets":   p.TxPackets.Val, |  | ||||||
| 			"rx_multicast": p.RxMulticast.Val, |  | ||||||
| 			"dns_servers":  strings.Join(p.DNS, ","), |  | ||||||
| 		} |  | ||||||
| 		r.send(&metric{Table: "usg_ports", Tags: tags, Fields: fields}) |  | ||||||
| 
 |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { | ||||||
| 		"serial":    s.Serial, | 		"serial":    s.Serial, | ||||||
| 		"type":      s.Type, | 		"type":      s.Type, | ||||||
| 	} | 	} | ||||||
| 	fields := map[string]interface{}{ | 	fields := Combine(map[string]interface{}{ | ||||||
| 		"guest-num_sta":       s.GuestNumSta.Val, | 		"guest-num_sta":       s.GuestNumSta.Val, | ||||||
| 		"ip":                  s.IP, | 		"ip":                  s.IP, | ||||||
| 		"bytes":               s.Bytes.Val, | 		"bytes":               s.Bytes.Val, | ||||||
|  | @ -31,15 +31,6 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { | ||||||
| 		"uptime":              s.Uptime.Val, | 		"uptime":              s.Uptime.Val, | ||||||
| 		"state":               s.State.Val, | 		"state":               s.State.Val, | ||||||
| 		"user-num_sta":        s.UserNumSta.Val, | 		"user-num_sta":        s.UserNumSta.Val, | ||||||
| 		"loadavg_1":           s.SysStats.Loadavg1.Val, |  | ||||||
| 		"loadavg_5":           s.SysStats.Loadavg5.Val, |  | ||||||
| 		"loadavg_15":          s.SysStats.Loadavg15.Val, |  | ||||||
| 		"mem_buffer":          s.SysStats.MemBuffer.Val, |  | ||||||
| 		"mem_used":            s.SysStats.MemUsed.Val, |  | ||||||
| 		"mem_total":           s.SysStats.MemTotal.Val, |  | ||||||
| 		"cpu":                 s.SystemStats.CPU.Val, |  | ||||||
| 		"mem":                 s.SystemStats.Mem.Val, |  | ||||||
| 		"system_uptime":       s.SystemStats.Uptime.Val, |  | ||||||
| 		"stat_bytes":          s.Stat.Sw.Bytes.Val, | 		"stat_bytes":          s.Stat.Sw.Bytes.Val, | ||||||
| 		"stat_rx_bytes":       s.Stat.Sw.RxBytes.Val, | 		"stat_rx_bytes":       s.Stat.Sw.RxBytes.Val, | ||||||
| 		"stat_rx_crypts":      s.Stat.Sw.RxCrypts.Val, | 		"stat_rx_crypts":      s.Stat.Sw.RxCrypts.Val, | ||||||
|  | @ -52,21 +43,24 @@ func (u *InfluxUnifi) batchUSW(r report, s *unifi.USW) { | ||||||
| 		"stat_tx_errors":      s.Stat.Sw.TxErrors.Val, | 		"stat_tx_errors":      s.Stat.Sw.TxErrors.Val, | ||||||
| 		"stat_tx_packets":     s.Stat.Sw.TxPackets.Val, | 		"stat_tx_packets":     s.Stat.Sw.TxPackets.Val, | ||||||
| 		"stat_tx_retries":     s.Stat.Sw.TxRetries.Val, | 		"stat_tx_retries":     s.Stat.Sw.TxRetries.Val, | ||||||
| 	} | 	}, u.batchSysStats(r, s.SysStats, s.SystemStats)) | ||||||
| 	r.send(&metric{Table: "usw", Tags: tags, Fields: fields}) | 	r.send(&metric{Table: "usw", Tags: tags, Fields: fields}) | ||||||
|  | 	u.batchPortTable(r, tags, s.PortTable) | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| 	for _, p := range s.PortTable { | func (u *InfluxUnifi) batchPortTable(r report, tags map[string]string, pt []unifi.Port) { | ||||||
|  | 	for _, p := range pt { | ||||||
| 		if !p.Up.Val || !p.Enable.Val { | 		if !p.Up.Val || !p.Enable.Val { | ||||||
| 			continue // only record UP ports.
 | 			continue // only record UP ports.
 | ||||||
| 		} | 		} | ||||||
| 		tags := map[string]string{ | 		tags := map[string]string{ | ||||||
| 			"site_name":   s.SiteName, | 			"site_name":   tags["site_name"], | ||||||
| 			"device_name": s.Name, | 			"device_name": tags["name"], | ||||||
| 			"name":        p.Name, | 			"name":        p.Name, | ||||||
| 			"poe_mode":    p.PoeMode, | 			"poe_mode":    p.PoeMode, | ||||||
| 			"port_poe":    p.PortPoe.Txt, | 			"port_poe":    p.PortPoe.Txt, | ||||||
| 			"port_idx":    p.PortIdx.Txt, | 			"port_idx":    p.PortIdx.Txt, | ||||||
| 			"port_id":     s.Name + " Port " + p.PortIdx.Txt, | 			"port_id":     tags["name"] + " Port " + p.PortIdx.Txt, | ||||||
| 			"poe_enable":  p.PoeEnable.Txt, | 			"poe_enable":  p.PoeEnable.Txt, | ||||||
| 			"flowctrl_rx": p.FlowctrlRx.Txt, | 			"flowctrl_rx": p.FlowctrlRx.Txt, | ||||||
| 			"flowctrl_tx": p.FlowctrlTx.Txt, | 			"flowctrl_tx": p.FlowctrlTx.Txt, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue