Update USW device collection.

This commit is contained in:
David Newhall II 2019-06-06 16:40:32 -07:00
parent 34d6674134
commit 67237e9c38
2 changed files with 138 additions and 84 deletions

View File

@ -47,72 +47,126 @@ func (u USW) Points() ([]*influx.Point, error) {
"stp_version": u.StpVersion,
}
fields := map[string]interface{}{
"fw_caps": u.FwCaps,
"guest-num_sta": u.GuestNumSta,
"ip": u.IP,
"bytes": u.Bytes,
"fan_level": u.FanLevel,
"general_temperature": u.GeneralTemperature,
"last_seen": u.LastSeen,
"license_state": u.LicenseState,
"overheating": u.Overheating.Val,
"rx_bytes": u.RxBytes,
"tx_bytes": u.TxBytes,
"uptime": u.Uptime,
"considered_lost_at": u.ConsideredLostAt,
"next_heartbeat_at": u.NextHeartbeatAt,
"roll_upgrade": u.Rollupgrade.Val,
"state": u.State,
"upgradable": u.Upgradable.Val,
"user-num_sta": u.UserNumSta,
"version": u.Version,
"loadavg_1": u.SysStats.Loadavg1,
"loadavg_5": u.SysStats.Loadavg5,
"loadavg_15": u.SysStats.Loadavg15,
"mem_buffer": u.SysStats.MemBuffer,
"mem_used": u.SysStats.MemUsed,
"mem_total": u.SysStats.MemTotal,
"cpu": u.SystemStats.CPU,
"mem": u.SystemStats.Mem,
"system_uptime": u.SystemStats.Uptime,
"stat_bytes": u.Stat.Bytes,
"stat_duration": u.Stat.Duration,
"stat_guest-rx_bytes": u.Stat.RxBytes,
"stat_guest-rx_crypts": u.Stat.RxCrypts,
"stat_guest-rx_dropped": u.Stat.RxDropped,
"stat_guest-rx_errors": u.Stat.RxErrors,
"stat_guest-rx_frags": u.Stat.RxFrags,
"stat_guest-rx_packets": u.Stat.RxPackets,
"stat_guest-tx_bytes": u.Stat.TxBytes,
"stat_guest-tx_dropped": u.Stat.TxDropped,
"stat_guest-tx_errors": u.Stat.TxErrors,
"stat_guest-tx_packets": u.Stat.TxPackets,
"stat_guest-tx_retries": u.Stat.TxRetries,
"stat_port_1-rx_broadcast": u.Stat.Port1RxBroadcast,
"stat_port_1-rx_bytes": u.Stat.Port1RxBytes,
"stat_port_1-rx_multicast": u.Stat.Port1RxMulticast,
"stat_port_1-rx_packets": u.Stat.Port1RxPackets,
"stat_port_1-tx_broadcast": u.Stat.Port1TxBroadcast,
"stat_port_1-tx_bytes": u.Stat.Port1TxBytes,
"stat_port_1-tx_multicast": u.Stat.Port1TxMulticast,
"stat_port_1-tx_packets": u.Stat.Port1TxPackets,
"stat_rx_bytes": u.Stat.RxBytes,
"stat_rx_crypts": u.Stat.RxCrypts,
"stat_rx_dropped": u.Stat.RxDropped,
"stat_rx_errors": u.Stat.RxErrors,
"stat_rx_frags": u.Stat.RxFrags,
"stat_rx_packets": u.Stat.TxPackets,
"stat_tx_bytes": u.Stat.TxBytes,
"stat_tx_dropped": u.Stat.TxDropped,
"stat_tx_errors": u.Stat.TxErrors,
"stat_tx_packets": u.Stat.TxPackets,
"stat_tx_retries": u.Stat.TxRetries,
"uplink_depth": u.UplinkDepth.Txt,
"fw_caps": u.FwCaps,
"guest-num_sta": u.GuestNumSta,
"ip": u.IP,
"bytes": u.Bytes,
"fan_level": u.FanLevel,
"general_temperature": u.GeneralTemperature,
"last_seen": u.LastSeen,
"license_state": u.LicenseState,
"overheating": u.Overheating.Val,
"rx_bytes": u.RxBytes,
"tx_bytes": u.TxBytes,
"uptime": u.Uptime,
"considered_lost_at": u.ConsideredLostAt,
"next_heartbeat_at": u.NextHeartbeatAt,
"roll_upgrade": u.Rollupgrade.Val,
"state": u.State,
"upgradable": u.Upgradable.Val,
"user-num_sta": u.UserNumSta,
"version": u.Version,
"loadavg_1": u.SysStats.Loadavg1,
"loadavg_5": u.SysStats.Loadavg5,
"loadavg_15": u.SysStats.Loadavg15,
"mem_buffer": u.SysStats.MemBuffer,
"mem_used": u.SysStats.MemUsed,
"mem_total": u.SysStats.MemTotal,
"cpu": u.SystemStats.CPU,
"mem": u.SystemStats.Mem,
"system_uptime": u.SystemStats.Uptime,
"stat_bytes": u.Stat.Bytes,
"stat_duration": u.Stat.Duration,
"stat_guest-rx_bytes": u.Stat.RxBytes,
"stat_guest-rx_crypts": u.Stat.RxCrypts,
"stat_guest-rx_dropped": u.Stat.RxDropped,
"stat_guest-rx_errors": u.Stat.RxErrors,
"stat_guest-rx_frags": u.Stat.RxFrags,
"stat_guest-rx_packets": u.Stat.RxPackets,
"stat_guest-tx_bytes": u.Stat.TxBytes,
"stat_guest-tx_dropped": u.Stat.TxDropped,
"stat_guest-tx_errors": u.Stat.TxErrors,
"stat_guest-tx_packets": u.Stat.TxPackets,
"stat_guest-tx_retries": u.Stat.TxRetries,
"stat_rx_bytes": u.Stat.RxBytes,
"stat_rx_crypts": u.Stat.RxCrypts,
"stat_rx_dropped": u.Stat.RxDropped,
"stat_rx_errors": u.Stat.RxErrors,
"stat_rx_frags": u.Stat.RxFrags,
"stat_rx_packets": u.Stat.TxPackets,
"stat_tx_bytes": u.Stat.TxBytes,
"stat_tx_dropped": u.Stat.TxDropped,
"stat_tx_errors": u.Stat.TxErrors,
"stat_tx_packets": u.Stat.TxPackets,
"stat_tx_retries": u.Stat.TxRetries,
"uplink_depth": u.UplinkDepth.Txt,
// Add the port stats too.
}
pt, err := influx.NewPoint("usw", tags, fields, time.Now())
if err != nil {
return nil, err
}
return []*influx.Point{pt}, nil
points := []*influx.Point{pt}
for _, p := range u.PortTable {
tags := map[string]string{
"site_id": u.SiteID,
"site_name": u.SiteName,
"device_name": u.Name,
"name": p.Name,
"enable": p.Enable.Txt,
"is_uplink": p.IsUplink.Txt,
"up": p.Up.Txt,
"portconf_id": p.PortconfID,
"dot1x_mode": p.Dot1XMode,
"dot1x_status": p.Dot1XStatus,
"stp_state": p.StpState,
"sfp_found": p.SfpFound.Txt,
"op_mode": p.OpMode,
"poe_mode": p.PoeMode,
"port_poe": p.PortPoe.Txt,
"port_idx": p.PortIdx.Txt,
"port_id": u.Name + " Port " + p.PortIdx.Txt,
"poe_enable": p.PoeEnable.Txt,
"flowctrl_rx": p.FlowctrlRx.Txt,
"flowctrl_tx": p.FlowctrlTx.Txt,
"autoneg": p.Autoneg.Txt,
"full_duplex": p.FullDuplex.Txt,
"jumbo": p.Jumbo.Txt,
"masked": p.Masked.Txt,
"poe_good": p.PoeGood.Txt,
"media": p.Media,
"poe_class": p.PoeClass,
"poe_caps": p.PoeCaps.Txt,
"aggregated_by": p.AggregatedBy.Txt,
}
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,
"full_duplex": p.FullDuplex.Val,
}
pt, err = influx.NewPoint("usw_ports", tags, fields, time.Now())
if err != nil {
return points, err
}
points = append(points, pt)
}
return points, nil
}

View File

@ -68,7 +68,7 @@ type USW struct {
PortTable []struct {
AggregatedBy FlexBool `json:"aggregated_by"`
Autoneg FlexBool `json:"autoneg"`
BytesR float64 `json:"bytes-r"`
BytesR FlexInt `json:"bytes-r"`
Dot1XMode string `json:"dot1x_mode"`
Dot1XStatus string `json:"dot1x_status"`
Enable FlexBool `json:"enable"`
@ -82,34 +82,34 @@ type USW struct {
Media string `json:"media"`
Name string `json:"name"`
OpMode string `json:"op_mode"`
PoeCaps float64 `json:"poe_caps"`
PoeCaps FlexInt `json:"poe_caps"`
PoeClass string `json:"poe_class,omitempty"`
PoeCurrent string `json:"poe_current,omitempty"`
PoeCurrent FlexInt `json:"poe_current,omitempty"`
PoeEnable FlexBool `json:"poe_enable,omitempty"`
PoeGood FlexBool `json:"poe_good,omitempty"`
PoeMode string `json:"poe_mode,omitempty"`
PoePower string `json:"poe_power,omitempty"`
PoeVoltage string `json:"poe_voltage,omitempty"`
PortIdx float64 `json:"port_idx"`
PoePower FlexInt `json:"poe_power,omitempty"`
PoeVoltage FlexInt `json:"poe_voltage,omitempty"`
PortIdx FlexInt `json:"port_idx"`
PortPoe FlexBool `json:"port_poe"`
PortconfID string `json:"portconf_id"`
RxBroadcast float64 `json:"rx_broadcast"`
RxBytes float64 `json:"rx_bytes"`
RxBytesR float64 `json:"rx_bytes-r"`
RxDropped float64 `json:"rx_dropped"`
RxErrors float64 `json:"rx_errors"`
RxMulticast float64 `json:"rx_multicast"`
RxPackets float64 `json:"rx_packets"`
Speed float64 `json:"speed"`
StpPathcost float64 `json:"stp_pathcost"`
RxBroadcast FlexInt `json:"rx_broadcast"`
RxBytes FlexInt `json:"rx_bytes"`
RxBytesR FlexInt `json:"rx_bytes-r"`
RxDropped FlexInt `json:"rx_dropped"`
RxErrors FlexInt `json:"rx_errors"`
RxMulticast FlexInt `json:"rx_multicast"`
RxPackets FlexInt `json:"rx_packets"`
Speed FlexInt `json:"speed"`
StpPathcost FlexInt `json:"stp_pathcost"`
StpState string `json:"stp_state"`
TxBroadcast float64 `json:"tx_broadcast"`
TxBytes float64 `json:"tx_bytes"`
TxBytesR float64 `json:"tx_bytes-r"`
TxDropped float64 `json:"tx_dropped"`
TxErrors float64 `json:"tx_errors"`
TxMulticast float64 `json:"tx_multicast"`
TxPackets float64 `json:"tx_packets"`
TxBroadcast FlexInt `json:"tx_broadcast"`
TxBytes FlexInt `json:"tx_bytes"`
TxBytesR FlexInt `json:"tx_bytes-r"`
TxDropped FlexInt `json:"tx_dropped"`
TxErrors FlexInt `json:"tx_errors"`
TxMulticast FlexInt `json:"tx_multicast"`
TxPackets FlexInt `json:"tx_packets"`
Up FlexBool `json:"up"`
SfpFound FlexBool `json:"sfp_found,omitempty"`
} `json:"port_table"`