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,7 +48,10 @@ 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(
u.batchUSGstat(s.SpeedtestStatus, s.Stat.Gw, s.Uplink),
u.batchSysStats(s.SysStats, s.SystemStats),
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,
@ -63,16 +66,8 @@ func (u *InfluxUnifi) batchUDM(r report, s *unifi.UDM) {
"num_desktop": s.NumDesktop.Val, "num_desktop": s.NumDesktop.Val,
"num_handheld": s.NumHandheld.Val, "num_handheld": s.NumHandheld.Val,
"num_mobile": s.NumMobile.Val, "num_mobile": s.NumMobile.Val,
"speedtest-status_latency": s.SpeedtestStatus.Latency.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,
}, 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,7 +19,10 @@ 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(
u.batchSysStats(s.SysStats, s.SystemStats),
u.batchUSGstat(s.SpeedtestStatus, s.Stat.Gw, s.Uplink),
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,
@ -33,23 +36,13 @@ func (u *InfluxUnifi) batchUSG(r report, s *unifi.USG) {
"version": s.Version, "version": s.Version,
"num_desktop": s.NumDesktop.Val, "num_desktop": s.NumDesktop.Val,
"num_handheld": s.NumHandheld.Val, "num_handheld": s.NumHandheld.Val,
"uplink_latency": s.Uplink.Latency.Val,
"uplink_speed": s.Uplink.Speed.Val,
"num_mobile": s.NumMobile.Val, "num_mobile": s.NumMobile.Val,
"speedtest-status_latency": s.SpeedtestStatus.Latency.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 {