mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:24:19 -04:00
feat: Add WAN metrics to InfluxDB and Datadog exporters
Add comprehensive WAN metrics support to InfluxDB and Datadog exporters:
InfluxDB Metrics (measurement: wan):
- Configuration: failover_priority, load_balance_weight, provider_download_kbps,
provider_upload_kbps, smartq_enabled, magic_enabled, vlan_enabled
- Statistics: uptime_percentage, peak_download_percent, peak_upload_percent,
max_rx_bytes_rate, max_tx_bytes_rate
- Service Provider: service_provider_asn
- Metadata: creation_timestamp
Tags: wan_id, wan_name, wan_networkgroup, wan_type, wan_load_balance_type,
isp_name, isp_city
Datadog Metrics (namespace: unpoller.wan.*):
- Same metrics as InfluxDB with gauge type
- All metrics tagged with WAN and ISP information
Changes:
- pkg/influxunifi/wan.go: New WAN exporter for InfluxDB
- pkg/influxunifi/influxdb.go: Add WAN to loopPoints and switchExport
- pkg/datadogunifi/wan.go: New WAN exporter for Datadog
- pkg/datadogunifi/datadog.go: Add WAN to loopPoints and switchExport
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2
go.mod
2
go.mod
@@ -47,4 +47,4 @@ require (
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
)
|
||||
|
||||
replace github.com/unpoller/unifi/v5 => ../unifi
|
||||
// replace github.com/unpoller/unifi/v5 => ../unifi
|
||||
|
||||
@@ -317,6 +317,10 @@ func (u *DatadogUnifi) loopPoints(r report) {
|
||||
}
|
||||
|
||||
reportClientDPItotals(r, appTotal, catTotal)
|
||||
|
||||
for _, w := range m.WANConfigs {
|
||||
u.switchExport(r, w)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *DatadogUnifi) switchExport(r report, v any) { //nolint:cyclop
|
||||
@@ -353,6 +357,8 @@ func (u *DatadogUnifi) switchExport(r report, v any) { //nolint:cyclop
|
||||
u.batchAnomaly(r, v)
|
||||
case *unifi.SpeedTestResult:
|
||||
u.batchSpeedTest(r, v)
|
||||
case *unifi.WANEnrichedConfiguration:
|
||||
u.batchWAN(r, v)
|
||||
default:
|
||||
if u.Collector != nil && u.Collector.Poller().LogUnknownTypes {
|
||||
u.LogDebugf("unknown export type: %T", v)
|
||||
|
||||
@@ -70,6 +70,7 @@ func (u *DatadogUnifi) batchUBB(r report, s *unifi.UBB) { // nolint: funlen
|
||||
data["p2p_tx_rate"] = s.P2PStats.TXRate.Val
|
||||
data["p2p_throughput"] = s.P2PStats.Throughput.Val
|
||||
}
|
||||
|
||||
data["link_quality"] = s.LinkQuality.Val
|
||||
data["link_quality_current"] = s.LinkQualityCurrent.Val
|
||||
data["link_capacity"] = s.LinkCapacity.Val
|
||||
|
||||
70
pkg/datadogunifi/wan.go
Normal file
70
pkg/datadogunifi/wan.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package datadogunifi
|
||||
|
||||
import (
|
||||
"github.com/unpoller/unifi/v5"
|
||||
)
|
||||
|
||||
// batchWAN generates WAN configuration datapoints for Datadog.
|
||||
// These points can be passed directly to Datadog.
|
||||
func (u *DatadogUnifi) batchWAN(r report, w *unifi.WANEnrichedConfiguration) {
|
||||
if w == nil {
|
||||
return
|
||||
}
|
||||
|
||||
metricName := metricNamespace("wan")
|
||||
|
||||
cfg := w.Configuration
|
||||
stats := w.Statistics
|
||||
details := w.Details
|
||||
|
||||
tags := []string{
|
||||
tag("wan_id", cfg.ID),
|
||||
tag("wan_name", cfg.Name),
|
||||
tag("wan_networkgroup", cfg.WANNetworkgroup),
|
||||
tag("wan_type", cfg.WANType),
|
||||
tag("wan_load_balance_type", cfg.WANLoadBalanceType),
|
||||
tag("isp_name", details.ServiceProvider.Name),
|
||||
tag("isp_city", details.ServiceProvider.City),
|
||||
}
|
||||
|
||||
// Convert boolean FlexBool values to float64 for Datadog
|
||||
smartQEnabled := 0.0
|
||||
if cfg.WANSmartqEnabled.Val {
|
||||
smartQEnabled = 1.0
|
||||
}
|
||||
|
||||
magicEnabled := 0.0
|
||||
if cfg.WANMagicEnabled.Val {
|
||||
magicEnabled = 1.0
|
||||
}
|
||||
|
||||
vlanEnabled := 0.0
|
||||
if cfg.WANVlanEnabled.Val {
|
||||
vlanEnabled = 1.0
|
||||
}
|
||||
|
||||
data := map[string]float64{
|
||||
// Configuration
|
||||
"failover_priority": cfg.WANFailoverPriority.Val,
|
||||
"load_balance_weight": cfg.WANLoadBalanceWeight.Val,
|
||||
"provider_download_kbps": cfg.WANProviderCapabilities.DownloadKbps.Val,
|
||||
"provider_upload_kbps": cfg.WANProviderCapabilities.UploadKbps.Val,
|
||||
"smartq_enabled": smartQEnabled,
|
||||
"magic_enabled": magicEnabled,
|
||||
"vlan_enabled": vlanEnabled,
|
||||
// Statistics
|
||||
"uptime_percentage": stats.UptimePercentage,
|
||||
"peak_download_percent": stats.PeakUsage.DownloadPercentage,
|
||||
"peak_upload_percent": stats.PeakUsage.UploadPercentage,
|
||||
"max_rx_bytes_rate": stats.PeakUsage.MaxRxBytesR.Val,
|
||||
"max_tx_bytes_rate": stats.PeakUsage.MaxTxBytesR.Val,
|
||||
// Service Provider
|
||||
"service_provider_asn": details.ServiceProvider.ASN.Val,
|
||||
// Metadata
|
||||
"creation_timestamp": details.CreationTimestamp.Val,
|
||||
}
|
||||
|
||||
for name, value := range data {
|
||||
_ = r.reportGauge(metricName(name), value, tags)
|
||||
}
|
||||
}
|
||||
@@ -430,6 +430,10 @@ func (u *InfluxUnifi) loopPoints(r report) {
|
||||
}
|
||||
|
||||
reportClientDPItotals(r, appTotal, catTotal)
|
||||
|
||||
for _, w := range m.WANConfigs {
|
||||
u.switchExport(r, w)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *InfluxUnifi) switchExport(r report, v any) { //nolint:cyclop
|
||||
@@ -466,6 +470,8 @@ func (u *InfluxUnifi) switchExport(r report, v any) { //nolint:cyclop
|
||||
u.batchAnomaly(r, v)
|
||||
case *unifi.SpeedTestResult:
|
||||
u.batchSpeedTest(r, v)
|
||||
case *unifi.WANEnrichedConfiguration:
|
||||
u.batchWAN(r, v)
|
||||
default:
|
||||
if u.Collector.Poller().LogUnknownTypes {
|
||||
u.LogDebugf("unknown export type: %T", v)
|
||||
|
||||
@@ -66,6 +66,7 @@ func (u *InfluxUnifi) batchUBB(r report, s *unifi.UBB) { // nolint: funlen
|
||||
fields["p2p_tx_rate"] = s.P2PStats.TXRate.Val
|
||||
fields["p2p_throughput"] = s.P2PStats.Throughput.Val
|
||||
}
|
||||
|
||||
fields["link_quality"] = s.LinkQuality.Val
|
||||
fields["link_quality_current"] = s.LinkQualityCurrent.Val
|
||||
fields["link_capacity"] = s.LinkCapacity.Val
|
||||
|
||||
66
pkg/influxunifi/wan.go
Normal file
66
pkg/influxunifi/wan.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package influxunifi
|
||||
|
||||
import (
|
||||
"github.com/unpoller/unifi/v5"
|
||||
)
|
||||
|
||||
// batchWAN generates WAN configuration datapoints for InfluxDB.
|
||||
// These points can be passed directly to influx.
|
||||
func (u *InfluxUnifi) batchWAN(r report, w *unifi.WANEnrichedConfiguration) {
|
||||
if w == nil {
|
||||
return
|
||||
}
|
||||
|
||||
cfg := w.Configuration
|
||||
stats := w.Statistics
|
||||
details := w.Details
|
||||
|
||||
tags := map[string]string{
|
||||
"wan_id": cfg.ID,
|
||||
"wan_name": cfg.Name,
|
||||
"wan_networkgroup": cfg.WANNetworkgroup,
|
||||
"wan_type": cfg.WANType,
|
||||
"wan_load_balance_type": cfg.WANLoadBalanceType,
|
||||
"isp_name": details.ServiceProvider.Name,
|
||||
"isp_city": details.ServiceProvider.City,
|
||||
}
|
||||
|
||||
// Convert boolean FlexBool values to int for InfluxDB
|
||||
smartQEnabled := 0
|
||||
if cfg.WANSmartqEnabled.Val {
|
||||
smartQEnabled = 1
|
||||
}
|
||||
|
||||
magicEnabled := 0
|
||||
if cfg.WANMagicEnabled.Val {
|
||||
magicEnabled = 1
|
||||
}
|
||||
|
||||
vlanEnabled := 0
|
||||
if cfg.WANVlanEnabled.Val {
|
||||
vlanEnabled = 1
|
||||
}
|
||||
|
||||
fields := map[string]any{
|
||||
// Configuration
|
||||
"failover_priority": cfg.WANFailoverPriority.Val,
|
||||
"load_balance_weight": cfg.WANLoadBalanceWeight.Val,
|
||||
"provider_download_kbps": cfg.WANProviderCapabilities.DownloadKbps.Val,
|
||||
"provider_upload_kbps": cfg.WANProviderCapabilities.UploadKbps.Val,
|
||||
"smartq_enabled": smartQEnabled,
|
||||
"magic_enabled": magicEnabled,
|
||||
"vlan_enabled": vlanEnabled,
|
||||
// Statistics
|
||||
"uptime_percentage": stats.UptimePercentage,
|
||||
"peak_download_percent": stats.PeakUsage.DownloadPercentage,
|
||||
"peak_upload_percent": stats.PeakUsage.UploadPercentage,
|
||||
"max_rx_bytes_rate": stats.PeakUsage.MaxRxBytesR.Val,
|
||||
"max_tx_bytes_rate": stats.PeakUsage.MaxTxBytesR.Val,
|
||||
// Service Provider
|
||||
"service_provider_asn": details.ServiceProvider.ASN.Val,
|
||||
// Metadata
|
||||
"creation_timestamp": details.CreationTimestamp.Val,
|
||||
}
|
||||
|
||||
r.send(&metric{Table: "wan", Tags: tags, Fields: fields})
|
||||
}
|
||||
Reference in New Issue
Block a user