Merge pull request #150 from davidnewhall/dn2_udm_fixes

combine usg stats with udm stats to add missing uplink values
This commit is contained in:
David Newhall II 2019-12-02 17:54:23 -08:00 committed by GitHub
commit 46e2631888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 54 deletions

View File

@ -48,31 +48,26 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) {
"serial": s.Serial, "serial": s.Serial,
"type": s.Type, "type": s.Type,
} }
fields := Combine(map[string]interface{}{ fields := Combine(
"ip": s.IP, u.batchUSGstat(s.SpeedtestStatus, s.Stat.Gw, s.Uplink),
"bytes": s.Bytes.Val, u.batchSysStats(s.SysStats, s.SystemStats),
"last_seen": s.LastSeen.Val, map[string]interface{}{
"license_state": s.LicenseState, "ip": s.IP,
"guest-num_sta": s.GuestNumSta.Val, "bytes": s.Bytes.Val,
"rx_bytes": s.RxBytes.Val, "last_seen": s.LastSeen.Val,
"tx_bytes": s.TxBytes.Val, "license_state": s.LicenseState,
"uptime": s.Uptime.Val, "guest-num_sta": s.GuestNumSta.Val,
"state": s.State.Val, "rx_bytes": s.RxBytes.Val,
"user-num_sta": s.UserNumSta.Val, "tx_bytes": s.TxBytes.Val,
"version": s.Version, "uptime": s.Uptime.Val,
"num_desktop": s.NumDesktop.Val, "state": s.State.Val,
"num_handheld": s.NumHandheld.Val, "user-num_sta": s.UserNumSta.Val,
"num_mobile": s.NumMobile.Val, "version": s.Version,
"speedtest-status_latency": s.SpeedtestStatus.Latency.Val, "num_desktop": s.NumDesktop.Val,
"speedtest-status_runtime": s.SpeedtestStatus.Runtime.Val, "num_handheld": s.NumHandheld.Val,
"speedtest-status_ping": s.SpeedtestStatus.StatusPing.Val, "num_mobile": s.NumMobile.Val,
"speedtest-status_xput_download": s.SpeedtestStatus.XputDownload.Val, },
"speedtest-status_xput_upload": s.SpeedtestStatus.XputUpload.Val, )
"lan-rx_bytes": s.Stat.Gw.LanRxBytes.Val,
"lan-rx_packets": s.Stat.Gw.LanRxPackets.Val,
"lan-tx_bytes": s.Stat.Gw.LanTxBytes.Val,
"lan-tx_packets": s.Stat.Gw.LanTxPackets.Val,
}, u.batchSysStats(s.SysStats, s.SystemStats))
r.send(&metric{Table: "usg", Tags: tags, Fields: fields}) r.send(&metric{Table: "usg", Tags: tags, Fields: fields})
u.batchNetTable(r, tags, s.NetworkTable) u.batchNetTable(r, tags, s.NetworkTable)
u.batchUSGwans(r, tags, s.Wan1, s.Wan2) u.batchUSGwans(r, tags, s.Wan1, s.Wan2)

View File

@ -19,37 +19,30 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) {
"serial": s.Serial, "serial": s.Serial,
"type": s.Type, "type": s.Type,
} }
fields := Combine(map[string]interface{}{ fields := Combine(
"ip": s.IP, u.batchSysStats(s.SysStats, s.SystemStats),
"bytes": s.Bytes.Val, u.batchUSGstat(s.SpeedtestStatus, s.Stat.Gw, s.Uplink),
"last_seen": s.LastSeen.Val, map[string]interface{}{
"license_state": s.LicenseState, "ip": s.IP,
"guest-num_sta": s.GuestNumSta.Val, "bytes": s.Bytes.Val,
"rx_bytes": s.RxBytes.Val, "last_seen": s.LastSeen.Val,
"tx_bytes": s.TxBytes.Val, "license_state": s.LicenseState,
"uptime": s.Uptime.Val, "guest-num_sta": s.GuestNumSta.Val,
"state": s.State.Val, "rx_bytes": s.RxBytes.Val,
"user-num_sta": s.UserNumSta.Val, "tx_bytes": s.TxBytes.Val,
"version": s.Version, "uptime": s.Uptime.Val,
"num_desktop": s.NumDesktop.Val, "state": s.State.Val,
"num_handheld": s.NumHandheld.Val, "user-num_sta": s.UserNumSta.Val,
"uplink_latency": s.Uplink.Latency.Val, "version": s.Version,
"uplink_speed": s.Uplink.Speed.Val, "num_desktop": s.NumDesktop.Val,
"num_mobile": s.NumMobile.Val, "num_handheld": s.NumHandheld.Val,
"speedtest-status_latency": s.SpeedtestStatus.Latency.Val, "num_mobile": s.NumMobile.Val,
"speedtest-status_runtime": s.SpeedtestStatus.Runtime.Val, },
"speedtest-status_ping": s.SpeedtestStatus.StatusPing.Val, )
"speedtest-status_xput_download": s.SpeedtestStatus.XputDownload.Val,
"speedtest-status_xput_upload": s.SpeedtestStatus.XputUpload.Val,
"lan-rx_bytes": s.Stat.Gw.LanRxBytes.Val,
"lan-rx_packets": s.Stat.Gw.LanRxPackets.Val,
"lan-tx_bytes": s.Stat.Gw.LanTxBytes.Val,
"lan-tx_packets": s.Stat.Gw.LanTxPackets.Val,
"lan-rx_dropped": s.Stat.Gw.LanRxDropped.Val,
}, u.batchSysStats(s.SysStats, s.SystemStats))
r.send(&metric{Table: "usg", Tags: tags, Fields: fields}) r.send(&metric{Table: "usg", Tags: tags, Fields: fields})
u.batchNetTable(r, tags, s.NetworkTable) u.batchNetTable(r, tags, s.NetworkTable)
u.batchUSGwans(r, tags, s.Wan1, s.Wan2) u.batchUSGwans(r, tags, s.Wan1, s.Wan2)
/* /*
for _, p := range s.PortTable { for _, p := range s.PortTable {
t := map[string]string{ t := map[string]string{
@ -80,7 +73,22 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) {
} }
*/ */
} }
func (u *InfluxUnifi) batchUSGstat(ss unifi.SpeedtestStatus, gw *unifi.Gw, ul unifi.Uplink) map[string]interface{} {
return map[string]interface{}{
"uplink_latency": ul.Latency.Val,
"uplink_speed": ul.Speed.Val,
"speedtest-status_latency": ss.Latency.Val,
"speedtest-status_runtime": ss.Runtime.Val,
"speedtest-status_ping": ss.StatusPing.Val,
"speedtest-status_xput_download": ss.XputDownload.Val,
"speedtest-status_xput_upload": ss.XputUpload.Val,
"lan-rx_bytes": gw.LanRxBytes.Val,
"lan-rx_packets": gw.LanRxPackets.Val,
"lan-tx_bytes": gw.LanTxBytes.Val,
"lan-tx_packets": gw.LanTxPackets.Val,
"lan-rx_dropped": gw.LanRxDropped.Val,
}
}
func (u *InfluxUnifi) batchUSGwans(r report, tags map[string]string, wans ...unifi.Wan) { func (u *InfluxUnifi) batchUSGwans(r report, tags map[string]string, wans ...unifi.Wan) {
for _, wan := range wans { for _, wan := range wans {
if !wan.Up.Val { if !wan.Up.Val {