[PR #6689] [client] Add local Prometheus metrics endpoint #26676

Open
opened 2026-08-05 07:07:40 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6689
Author: @lixmal
Created: 7/7/2026
Status: 🔄 Open

Base: mainHead: client-local-metrics


📝 Commits (4)

  • 9d2a7e3 Add opt-in local Prometheus metrics endpoint to the client
  • 8280696 Render local metrics config in debug bundle and harden metrics HTTP server
  • e93fd6c Gate local metrics settings behind update-settings and MDM policy
  • 6b7c22e Merge branch 'main' into client-local-metrics

📊 Changes

21 files changed (+1838 additions, -31 deletions)

View changed files

📝 client/cmd/root.go (+7 -0)
📝 client/cmd/up.go (+23 -0)
📝 client/internal/debug/debug.go (+2 -0)
client/internal/localmetrics/localmetrics.go (+243 -0)
client/internal/localmetrics/localmetrics_test.go (+97 -0)
📝 client/internal/metrics/influxdb.go (+3 -20)
📝 client/internal/metrics/metrics.go (+23 -0)
📝 client/internal/metrics/metrics_default.go (+15 -1)
client/internal/metrics/prometheus.go (+119 -0)
📝 client/internal/peer/status.go (+12 -0)
📝 client/internal/profilemanager/config.go (+26 -0)
📝 client/internal/profilemanager/config_mdm_test.go (+26 -0)
📝 client/mdm/policy.go (+2 -0)
📝 client/proto/daemon.pb.go (+46 -6)
📝 client/proto/daemon.proto (+6 -0)
📝 client/server/mdm.go (+10 -2)
📝 client/server/server.go (+35 -1)
📝 client/server/setconfig_mdm_test.go (+24 -0)
📝 client/server/setconfig_test.go (+10 -0)
📝 go.mod (+2 -1)

...and 1 more files

📄 Description

Adds an opt-in Prometheus /metrics endpoint to the client daemon so deployments can scrape connection health locally (requested for a RedHat evaluation: latency, connected peers, P2P vs relay).

  • Add netbird up --enable-local-metrics and --local-metrics-address (default 127.0.0.1:9191); the setting persists in the profile config and travels through SetConfig/Login like other config flags
  • Expose the existing client metrics (peer connection stage durations, sync and login durations) by mirroring them into a Prometheus registry behind the same recording interface
  • Add scrape-time gauges for current state: management/signal connectivity, known peers, connected peers by connection type, and per-peer latency for direct connections
  • Add a Grafana dashboard for the client next to the existing management/signal/relay dashboards
  • Gate the new settings behind --disable-update-settings and MDM policy (enableLocalMetrics, localMetricsAddress keys)
  • Regenerate the daemon JSON gateway, which was missing routes for recently added RPCs

All labels are bounded enums except the per-peer latency series, which carries the peer FQDN only.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (PoC under team discussion; docs to follow once the flag surface is finalized)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features
    • Added an optional local Prometheus /metrics endpoint for monitoring client connectivity, peer states, latency, and connection performance.
    • Added CLI and configuration options to enable local metrics and set its listening address.
    • Added MDM policy support for managing local metrics settings.
    • Added a Grafana dashboard for visualizing client metrics.
  • Documentation
    • Debug bundles now include local metrics configuration details.
  • Bug Fixes
    • Improved connection-duration metric calculations and reporting consistency.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6689 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 7/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `client-local-metrics` --- ### 📝 Commits (4) - [`9d2a7e3`](https://github.com/netbirdio/netbird/commit/9d2a7e330ad5cab0722aa0c651cbd67b03ecf666) Add opt-in local Prometheus metrics endpoint to the client - [`8280696`](https://github.com/netbirdio/netbird/commit/8280696e6ee2bc3b0042be79d568833fe49e06a4) Render local metrics config in debug bundle and harden metrics HTTP server - [`e93fd6c`](https://github.com/netbirdio/netbird/commit/e93fd6c1eb27d8d037117cac8240223134778910) Gate local metrics settings behind update-settings and MDM policy - [`6b7c22e`](https://github.com/netbirdio/netbird/commit/6b7c22e443940c6e2f85e41396128de8d55df890) Merge branch 'main' into client-local-metrics ### 📊 Changes **21 files changed** (+1838 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `client/cmd/root.go` (+7 -0) 📝 `client/cmd/up.go` (+23 -0) 📝 `client/internal/debug/debug.go` (+2 -0) ➕ `client/internal/localmetrics/localmetrics.go` (+243 -0) ➕ `client/internal/localmetrics/localmetrics_test.go` (+97 -0) 📝 `client/internal/metrics/influxdb.go` (+3 -20) 📝 `client/internal/metrics/metrics.go` (+23 -0) 📝 `client/internal/metrics/metrics_default.go` (+15 -1) ➕ `client/internal/metrics/prometheus.go` (+119 -0) 📝 `client/internal/peer/status.go` (+12 -0) 📝 `client/internal/profilemanager/config.go` (+26 -0) 📝 `client/internal/profilemanager/config_mdm_test.go` (+26 -0) 📝 `client/mdm/policy.go` (+2 -0) 📝 `client/proto/daemon.pb.go` (+46 -6) 📝 `client/proto/daemon.proto` (+6 -0) 📝 `client/server/mdm.go` (+10 -2) 📝 `client/server/server.go` (+35 -1) 📝 `client/server/setconfig_mdm_test.go` (+24 -0) 📝 `client/server/setconfig_test.go` (+10 -0) 📝 `go.mod` (+2 -1) _...and 1 more files_ </details> ### 📄 Description Adds an opt-in Prometheus `/metrics` endpoint to the client daemon so deployments can scrape connection health locally (requested for a RedHat evaluation: latency, connected peers, P2P vs relay). - Add `netbird up --enable-local-metrics` and `--local-metrics-address` (default `127.0.0.1:9191`); the setting persists in the profile config and travels through SetConfig/Login like other config flags - Expose the existing client metrics (peer connection stage durations, sync and login durations) by mirroring them into a Prometheus registry behind the same recording interface - Add scrape-time gauges for current state: management/signal connectivity, known peers, connected peers by connection type, and per-peer latency for direct connections - Add a Grafana dashboard for the client next to the existing management/signal/relay dashboards - Gate the new settings behind `--disable-update-settings` and MDM policy (`enableLocalMetrics`, `localMetricsAddress` keys) - Regenerate the daemon JSON gateway, which was missing routes for recently added RPCs All labels are bounded enums except the per-peer latency series, which carries the peer FQDN only. ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) - [x] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (PoC under team discussion; docs to follow once the flag surface is finalized) ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an optional local Prometheus `/metrics` endpoint for monitoring client connectivity, peer states, latency, and connection performance. * Added CLI and configuration options to enable local metrics and set its listening address. * Added MDM policy support for managing local metrics settings. * Added a Grafana dashboard for visualizing client metrics. * **Documentation** * Debug bundles now include local metrics configuration details. * **Bug Fixes** * Improved connection-duration metric calculations and reporting consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 07:07:40 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#26676