Commit Graph

79 Commits

Author SHA1 Message Date
Brian Gates
5ea7fcf736 feat: UPS battery metrics, example Prometheus/Loki alerts (unpoller#930) (#941) 2026-01-31 20:25:58 -06:00
brngates98
b96606128d chore: Update go.sum for unifi v5.11.0 and fix formatting
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-29 17:37:33 -05:00
brngates98
b8519ca058 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>
2026-01-29 17:27:28 -05:00
Cody Lee
ae1ab40386 Populate num_user field for VPN subsystem metrics
Fixes #417

UniFi controllers populate RemoteUserNumActive for VPN connections but
leave NumUser at 0 for the VPN subsystem. This caused dashboard queries
looking for num_user in the VPN subsystem to always show 0 active users,
even when VPN connections were active.

Root Cause:
For most subsystems (wlan, lan, www), the controller populates NumUser
directly. However, for the VPN subsystem, the controller uses the
RemoteUserNumActive field instead, leaving NumUser at 0.

The Prometheus exporter had special handling for VPN (lines 148-156 in
pkg/promunifi/site.go) and exported RemoteUserNumActive, but did not
export NumUser. The InfluxDB and Datadog exporters exported all fields
for all subsystems without special handling, resulting in num_user
always being 0 for VPN.

Existing Grafana dashboards query:
  SELECT "num_user" FROM "subsystems" WHERE subsystem='vpn'

This always returned 0 even with active VPN users.

Solution:
For all three exporters (InfluxDB, Datadog, Prometheus), when the
subsystem is 'vpn' and NumUser is 0 but RemoteUserNumActive has a
value, populate num_user with RemoteUserNumActive.

Changes:
- pkg/influxunifi/site.go: Add VPN-specific num_user fallback logic
- pkg/datadogunifi/site.go: Add VPN-specific num_user fallback logic
- pkg/promunifi/site.go: Add NumUser metric to VPN case with fallback

This maintains backward compatibility - existing queries for num_user
will now work correctly, and the remote_user_num_active field is still
available for those who updated their dashboards.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 12:09:01 -06:00
Cody Lee
9e3debd58a Allow PoE-providing ports to be scraped even when disabled
Ports providing PoE power are no longer considered "dead" even when
disabled or down. This allows users to collect PoE metrics from ports
that are disabled for security reasons but still providing power.

Fixes #910

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 11:31:39 -06:00
Cody Lee
07781214c3 Add config option to suppress unknown device type messages
Adds log_unknown_types config option (default: false) to control logging
of unknown UniFi device types. When disabled (default), unknown devices
are silently ignored to reduce log volume. When enabled, they are logged
as DEBUG messages instead of ERROR. Addresses issue #912.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 11:24:33 -06:00
Cody Lee
a00aeb2eb5 Add byte counters for InfluxDB and Prometheus outputs (issue #350)
Track the number of bytes written per request for both InfluxDB and Prometheus outputs.

InfluxDB:
- Added bytesT counter constant
- Implemented calculateMetricBytes() to estimate line protocol size
- Updated batchV1() and batchV2() to count bytes per point
- Updated log output to display bytes written

Prometheus:
- Added Bytes field to Report struct
- Updated export() to calculate approximate metric byte size
- Updated log output to display bytes written

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 10:55:33 -06:00
Cody Lee
0ffe6152ab Fix multi-WAN speed test reporting (issue #841)
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>
2025-12-09 16:46:14 -06:00
Cody Lee
c61d2651a2 Enhance InfluxDB and Datadog UBB outputs with comprehensive metrics
This change significantly expands the metrics exported for UBB devices
to InfluxDB and Datadog, matching the comprehensive coverage added to
the Prometheus output.

Changes to InfluxDB (pkg/influxunifi/ubb.go):
- Added batchUBBstats() to export comprehensive statistics separated
  by radio (total, wifi0, terra2, user-wifi0, user-terra2)
- Added VAP table export via processVAPTable()
- Added Radio table export via processRadTable()
- Added P2P stats (rx_rate, tx_rate, throughput)
- Added link quality metrics (link_quality, link_quality_current,
  link_capacity)
- Comprehensive stats exported to new "ubb_stats" table with full
  breakdown of traffic per radio

Changes to Datadog (pkg/datadogunifi/ubb.go):
- Added batchUBBstats() to export comprehensive statistics separated
  by radio (total, wifi0, terra2, user-wifi0, user-terra2)
- Added VAP table export via processVAPTable()
- Added Radio table export via processRadTable()
- Added P2P stats (rx_rate, tx_rate, throughput)
- Added link quality metrics (link_quality, link_quality_current,
  link_capacity)
- Comprehensive stats exported with namespace "ubb.stats"

All implementations now fully support:
- 5GHz radio (wifi0) metrics
- 60GHz radio (terra2/ad) metrics - Full 802.11ad support!
- Per-radio RX/TX packets, bytes, errors, dropped, retries
- User-specific metrics for each radio
- Interface-specific metrics (ath0 for 5GHz, wlan0 for 60GHz)
- Point-to-point link statistics and quality metrics

Fixes: #409

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 11:04:35 -06:00
Cody Lee
7e2fb0135e fix dd client interface change, update deprecated context lib in influxdb 2025-12-03 11:51:40 -06:00
Cody Lee
6f4384c18d fix linting 2025-12-03 11:40:21 -06:00
Cody Lee
4b19b873ab address issue 2025-04-04 08:33:58 -05:00
Cody Lee
6d4065113f fixes metrics prefix names for ubb and uci devices 2025-01-15 15:50:47 -06:00
Cody Lee
9d1f8606df update expectations 2025-01-02 12:46:17 -06:00
Cody Lee
4da299ff46 adds device uplink stats for issue #585 2025-01-02 12:41:34 -06:00
Cody Lee
1b120a258a tests pass locally; 2025-01-02 11:33:28 -06:00
Cody Lee
3602d8cc8f adds in UBB & UCI support 2025-01-02 08:57:47 -06:00
Cody Lee
a30c82093d add ubb and uci initial support 2024-12-31 16:26:54 -06:00
Cody Lee
ebdb224d95 fixes mocks 2024-12-31 15:03:55 -06:00
Cody Lee
b372198840 painful upgrade for dumb go versioning 2024-12-31 14:44:10 -06:00
Cody Lee
9bdc6e8d0f auto fix lint rules 2024-09-09 08:55:12 -05:00
Cody Lee
4bd56677c9 fix type 2024-04-19 15:43:00 -05:00
Cody Lee
cfd35ddf67 nice find here, pct should be float 2024-04-03 18:41:34 -05:00
Cody Lee
f372ddd3b6 fix integration test 2024-04-03 18:34:54 -05:00
Cody Lee
7308a1c2e6 fix type errors 2024-04-03 12:17:24 -05:00
Mike Piatek-Jimenez
b5247cf65d Updated the integration test expectations for the parsed PDU data. 2023-09-10 22:02:41 -04:00
Cody Lee
7e87e7f4fb rename package per per comment, add comments, and drop unnecessary compile time check 2023-08-03 09:27:09 -05:00
Cody Lee
ffb8579369 add integration test guard;
datadog integration test works

influx package tests

update unifi version

golanglint-ci and address *all* issues.

all tests pass

bump unifi version
2023-07-31 14:40:33 -05:00
Cody Lee
c5e409adff per https://github.com/unpoller/unpoller/issues/575\#issuecomment-1641041603 fixes the other two data points that need to be re-cast 2023-07-18 16:56:50 -05:00
Cody Lee
2b186a9451 anomalies 2023-07-18 14:20:51 -05:00
Cody Lee
0aa406a2dc cast back to int64 so existing timeseries continue to ingest, influxdb is very strict about int vs float storage 2023-07-18 13:48:57 -05:00
Cody Lee
2b185e88c7 fixes sitedpi strings on influx and prom 2023-01-23 17:32:14 -06:00
Cody Lee
27bab9a01c fixes client dpi strings on influx and prom 2023-01-07 11:36:11 -06:00
Cody Lee
1edb580084 bump unifi client and address
https://github.com/unpoller/dashboards/issues/20\#issuecomment-1364716049
and the duplicate https://github.com/unpoller/unpoller/issues/492
2023-01-06 21:12:24 -06:00
Cody Lee
3768c53512 CLI works 2022-12-22 18:16:43 -06:00
Cody Lee
db9bcd5687 add new interface for testing 2022-12-22 17:44:39 -06:00
Cody Lee
26e2771229 prom and influx support 2022-12-22 14:36:08 -06:00
Cody Lee
2bb5b1bd13 Merge pull request #480 from unpoller/bugfix-395
Invalid Influx URL causes unhelpful panic
2022-12-21 20:46:11 -06:00
Cody Lee
f092480019 add helpful guard when influxdb url is invalid to fix #395 2022-12-21 20:42:18 -06:00
Cody Lee
0329066fe5 remote upgrade metrics for #433 2022-12-21 20:14:22 -06:00
Cody Lee
acd6592f5c another NPE for #422 2022-12-20 21:35:06 -06:00
Cody Lee
2e8fb0b2ec FlexInt adaptation 2022-12-20 21:29:56 -06:00
Cody Lee
97b3a476f9 fixes NPE on issue #422 2022-12-20 20:53:48 -06:00
Cody Lee
fded91ce40 fixed start loop 2022-12-11 13:00:40 -06:00
Cody Lee
4816c13431 Merge branch 'output-plugin-interface' of github.com:unpoller/unpoller into output-plugin-interface 2022-12-08 20:45:21 -06:00
Cody Lee
3e5dd38e2f duplicated assignment 2022-12-08 20:45:16 -06:00
Cody Lee
25871385b0 Merge branch 'master' into output-plugin-interface 2022-12-08 20:42:33 -06:00
Cody Lee
f392648182 add log info 2022-12-08 20:35:13 -06:00
Cody Lee
bd51cf59f3 move to a common pattern on output plugins to catch common issues 2022-12-05 22:00:48 -06:00
Cody Lee
a148f669da update per PR suggestions 2022-12-05 16:06:30 -06:00