mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:33:57 -04:00
Speed tests were not being reported correctly for multi-WAN setups
because the device-level speedtest-status field was returning zeros.
The data has moved to a new aggregated dashboard API endpoint.
Changes:
- Add GetSpeedTests() and GetSiteSpeedTests() methods to fetch from
/v2/api/site/{site}/aggregated-dashboard endpoint
- Create SpeedTestResult data structures to capture per-WAN metrics
- Update Prometheus exporter with new speedtest_* metrics per interface
- Update InfluxDB exporter to write speedtest measurements per WAN
- Update Datadog exporter with unifi.speedtest.* metrics per WAN
- Update metrics collection to include speed test data for all sites
Metrics now include labels/tags for:
- wan_interface: Physical interface (eth8, eth9, etc.)
- wan_group: Logical WAN name (WAN, WAN2, etc.)
- site_name: Site identifier
- source: Controller URL
Gracefully handles older controllers without the new API endpoint.
Fixes #841
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package promunifi
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/unpoller/unifi/v5"
|
|
)
|
|
|
|
type speedtest struct {
|
|
DownloadMbps *prometheus.Desc
|
|
UploadMbps *prometheus.Desc
|
|
LatencyMs *prometheus.Desc
|
|
Timestamp *prometheus.Desc
|
|
}
|
|
|
|
func descSpeedTest(ns string) *speedtest {
|
|
labels := []string{"wan_interface", "wan_group", "site_name", "source"}
|
|
|
|
return &speedtest{
|
|
DownloadMbps: prometheus.NewDesc(ns+"download_mbps", "Speed Test Download in Mbps", labels, nil),
|
|
UploadMbps: prometheus.NewDesc(ns+"upload_mbps", "Speed Test Upload in Mbps", labels, nil),
|
|
LatencyMs: prometheus.NewDesc(ns+"latency_ms", "Speed Test Latency in milliseconds", labels, nil),
|
|
Timestamp: prometheus.NewDesc(ns+"timestamp_seconds", "Speed Test Timestamp (Unix epoch)", labels, nil),
|
|
}
|
|
}
|
|
|
|
func (u *promUnifi) exportSpeedTest(r report, st *unifi.SpeedTestResult) {
|
|
if st == nil {
|
|
return
|
|
}
|
|
|
|
labels := []string{st.InterfaceName, st.WANNetworkGroup, st.SiteName, st.SourceName}
|
|
|
|
r.send([]*metric{
|
|
{u.SpeedTest.DownloadMbps, gauge, st.DownloadMbps, labels},
|
|
{u.SpeedTest.UploadMbps, gauge, st.UploadMbps, labels},
|
|
{u.SpeedTest.LatencyMs, gauge, st.LatencyMs, labels},
|
|
{u.SpeedTest.Timestamp, gauge, st.Time, labels},
|
|
})
|
|
}
|