Commit Graph

197 Commits

Author SHA1 Message Date
aharper343 6205900446 Adding constants for periods and debug logs for retrieved counts 2025-12-24 00:23:05 -05:00
aharper343 ab7073d63d Added support for regions and sub-regions 2025-12-24 00:23:05 -05:00
aharper343 22dfc25801 Temp fix for test cases and warning from Dockerfile 2025-12-24 00:23:05 -05:00
aharper343 0b9d3de5cc First working version DPI metrics and traffic exported 2025-12-24 00:23:00 -05:00
Sven Grossmann 7e59c4883b fix: add HTTP timeout configuration to prevent indefinite hangs
The UniFi controller HTTP client was created without a timeout, causing
unpoller to hang indefinitely when the controller becomes unresponsive.
This resulted in random stops where polling would cease until the
container was restarted.

Changes:
- Add Timeout field to Controller struct (cnfg.Duration)
- Set default timeout of 60 seconds
- Pass timeout to unifi.Config when creating the client
- Log timeout value on startup for visibility

The timeout can be configured via:
- Config file: timeout = "60s"
- Environment: UP_UNIFI_DEFAULT_TIMEOUT=60s

Fixes issue where container would hang overnight:
  2025/12/22 22:29:27 - Requesting https://unifi/.../stat/sta
  [~2 hour gap - request hung indefinitely]
  2025/12/23 00:17:57 - Unmarshalling Device Type: udm...
2025-12-23 11:13:54 +01:00
Sven Grossmann 07e1e5bc4d feat: add UniFi Protect logs support with Loki integration
- Add SaveProtectLogs config option to enable Protect log collection
- Add ProtectThumbnails config option to fetch event thumbnails
- Add collectProtectLogs function with 24h default fetch window
- Add ProtectLogEvent for Loki reporting with separate thumbnail log lines
- Add PII redaction for Protect log entries
- Filter thumbnail fetching to camera events only (motion, smartDetect*, etc.)
- Update log output to show Protect logs status
2025-12-22 22:55:30 +01:00
Sven Grossmann a3dc4cd0b2 feat: add save_syslog option for v2 system-log API
Add new save_syslog config option to collect events from the v2 UniFi
system-log API (/v2/api/site/{site}/system-log/all).

Changes:
- Add SaveSyslog field to Controller struct
- Add collectSyslog() function using v2 API
- Keep collectEvents() using v1 API for backwards compatibility
- Add RedactIPPII() helper for PII redaction
- Update lokiunifi to log raw JSON (parseable with Loki | json)
- Reduce indexed labels to low-cardinality fields only
- Add SystemLogEntry handler in lokiunifi report

Config: save_syslog (v2 API) vs save_events (v1 API)
Env: UP_UNIFI_DEFAULT_SAVE_SYSLOG=true
2025-12-22 17:23:53 +01: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 8000597fce
Refactor Prometheus UBB label construction to use append
Replace manual array indexing (labels[1], labels[2], labels[3]) with
cleaner append syntax using slice notation (labels[1:]...).

This makes the code more maintainable and idiomatic Go.

Before: labelTotal := []string{"total", labels[1], labels[2], labels[3]}
After:  labelTotal := append([]string{"total"}, labels[1:]...)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 11:12:00 -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 6a135c60a7
Enhance UBB device support with comprehensive Prometheus metrics
This change significantly improves UniFi Building Bridge (UBB) device
support by adding comprehensive Prometheus metric exports.

UBB devices are point-to-point wireless bridges with dual radios:
- wifi0: 5GHz radio (802.11ac)
- terra2/wlan0/ad: 60GHz radio (802.11ad - Terragraph/WiGig)

Changes:
- Added exportUBBstats() to export UBB-specific statistics separated
  by radio (total, wifi0, terra2, user-wifi0, user-terra2)
- Added exportP2Pstats() to export point-to-point link metrics
  (rx_rate, tx_rate, throughput)
- Added VAP (Virtual Access Point) table export via existing exportVAPtable()
- Added Radio table export via existing exportRADtable() to capture
  60GHz radio metrics
- Added link quality metrics (link_quality, link_quality_current,
  link_capacity)
- Added comprehensive comments documenting UBB device characteristics
  and 60GHz band support

The implementation reuses existing UAP metric descriptors where
appropriate, allowing UBB metrics to be collected alongside UAP metrics
in Prometheus with proper labeling for differentiation.

Requires: unpoller/unifi#169 (UBB type definition fixes)
Fixes: #409

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 10:20:23 -06:00
Cody Lee 832334655c
Fix health check port binding conflict (issue #892)
The Docker health check was attempting to bind to ports already in use by
the running application, causing "address already in use" errors. This fix
adds a health check mode that skips network binding operations while still
validating output configuration (listen addresses, paths, etc.).

Changes:
- Add health check mode flag in pkg/poller/outputs.go
- Update prometheus and webserver DebugOutput() to skip port binding in health check mode
- Maintain full configuration validation without network conflicts

Fixes #892

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 08:11:21 -06:00
Cody Lee b960695f3b
Add Docker health check support
Implements #406 by adding a --health CLI flag and HEALTHCHECK instruction
to the Dockerfile. This allows Docker and container orchestration platforms
to monitor container health automatically.

Changes:
- Added --health flag that validates configuration and plugin connectivity
- Implemented HealthCheck() method in pkg/poller/commands.go
- Updated Dockerfile with HEALTHCHECK instruction (30s interval, 10s timeout)
- Updated MANUAL.md with --health flag documentation
- Added health check documentation to Docker README
- Added comments to docker-compose examples about built-in health check

The health check:
- Validates configuration file is found and parseable
- Ensures at least one input and one enabled output are configured
- Performs basic validation on enabled outputs
- Returns exit code 0 (healthy) or 1 (unhealthy)
- Runs silently for Docker compatibility

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-08 13:09:10 -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 c3126d27e3
interface change updates 2025-08-20 11:36:29 -05:00
Traxmaxx 8fb9c3cb40 fix: skip loki reporting if streams is empty 2025-07-20 13:18:58 +02:00
Sofiane A 10ccd0c2d7 Correct logic for default site condition 2025-04-29 19:34:52 +02:00
Sofiane A 5a89a4634a Add default_site_name_override to support customizable default site names 2025-04-29 16:12:32 +02: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 cba1111f29
add support for api-key auth 2025-01-10 15:19:30 -06:00
Cody Lee ed3c222992
oops fix dd expectation 2025-01-02 12:51:37 -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 78f30e0056
fix vet 2024-12-31 14:47:06 -06:00
Cody Lee b372198840
painful upgrade for dumb go versioning 2024-12-31 14:44:10 -06:00
Cody Lee b9d668abee
upgrading dependencies 2024-12-31 14:23:53 -06:00
Cody Lee 38ac45fc17
update golangci-lint, address lint issue 2024-12-31 14:12:35 -06:00
Cody Lee 9bdc6e8d0f
auto fix lint rules 2024-09-09 08:55:12 -05:00
Cody Lee 5b58e6c237
fix promver collector to default buildinfo collector 2024-04-19 15:51:18 -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
Cody Lee b87ee94111
add hostname per #415 request to loki exports 2024-03-04 18:28:04 -06:00
Austin Browder 8974cce072 Fixed PR lint failure 2023-11-07 12:25:02 -07:00
Austin Browder 746ab856e0 Added source interface identifier to exportUSGstats function 2023-10-23 14:39:22 -06:00
Mike Piatek-Jimenez ce55a864ea Make sure descPDU handles the power outlets. 2023-09-11 00:00:48 -04:00
Mike Piatek-Jimenez 5514be1a57 Update the test expectations for the datadog output package. 2023-09-10 22:15:50 -04:00
Mike Piatek-Jimenez b5247cf65d Updated the integration test expectations for the parsed PDU data. 2023-09-10 22:02:41 -04:00
Mike Piatek-Jimenez 6ddb2055d0 Fix a bug where the PDU metrics captured by the unifi collector wouldn’t be included in the device output. 2023-09-10 13:06:37 -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 11142c0209
remove nl 2023-07-31 16:16:48 -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