[PR #6561] [MERGED] [management] Add agent-network telemetry metrics #29658

Closed
opened 2026-08-05 08:08:36 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6561
Author: @mlsmaycon
Created: 6/27/2026
Status: Merged
Merged: 6/27/2026
Merged by: @mlsmaycon

Base: 0.74.0-branchHead: feat/agent-network-metrics


📝 Commits (1)

  • bf83ecb [management] Add agent-network telemetry metrics

📊 Changes

6 files changed (+124 additions, -0 deletions)

View changed files

📝 management/server/metrics/selfhosted.go (+16 -0)
📝 management/server/metrics/selfhosted_test.go (+15 -0)
📝 management/server/store/file_store.go (+6 -0)
📝 management/server/store/sql_store_agentnetwork.go (+41 -0)
📝 management/server/store/store.go (+31 -0)
📝 management/server/store/store_mock_agentnetwork.go (+15 -0)

📄 Description

Describe your changes

Surfaces agent-network adoption and usage in the self-hosted metrics worker so we can understand how much customers are managing through NetBird's per-account LLM gateway.

New telemetry properties:

Property Meaning
agent_network_accounts distinct accounts with ≥1 provider
agent_network_providers total providers
agent_network_policies total policies
agent_network_budget_rules account-level budget rules
agent_network_log_collection_enabled accounts with log collection on
agent_network_input_tokens aggregated input tokens
agent_network_output_tokens aggregated output tokens
agent_network_cost_usd aggregated cost

Tokens and cost are summed from agent_network_request_usage — the always-written per-request ledger — so the figures are accurate regardless of the log-collection toggle and carry no double-counting (unlike the consumption table, which books per-window rows). All values come from a handful of indexed aggregate queries (COUNT / COALESCE(SUM(...))) executed only on the metrics worker's periodic tick, so the DB/CPU cost is negligible.

Implementation:

  • store.AgentNetworkMetrics struct + GetAgentNetworkMetrics on the Store interface
  • SqlStore implementation (a few aggregate queries)
  • zero-valued FileStore stub (agent-network state isn't persisted in the JSON format)
  • wired into metrics.Worker.generateProperties

N/A

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 (explain why)

Anonymized self-hosted telemetry properties are internal and not part of the user-facing product surface.

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 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/6561 **Author:** [@mlsmaycon](https://github.com/mlsmaycon) **Created:** 6/27/2026 **Status:** ✅ Merged **Merged:** 6/27/2026 **Merged by:** [@mlsmaycon](https://github.com/mlsmaycon) **Base:** `0.74.0-branch` ← **Head:** `feat/agent-network-metrics` --- ### 📝 Commits (1) - [`bf83ecb`](https://github.com/netbirdio/netbird/commit/bf83ecbcb6a0715f93ac057e76c74a9134efe080) [management] Add agent-network telemetry metrics ### 📊 Changes **6 files changed** (+124 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `management/server/metrics/selfhosted.go` (+16 -0) 📝 `management/server/metrics/selfhosted_test.go` (+15 -0) 📝 `management/server/store/file_store.go` (+6 -0) 📝 `management/server/store/sql_store_agentnetwork.go` (+41 -0) 📝 `management/server/store/store.go` (+31 -0) 📝 `management/server/store/store_mock_agentnetwork.go` (+15 -0) </details> ### 📄 Description ## Describe your changes Surfaces agent-network adoption and usage in the self-hosted metrics worker so we can understand how much customers are managing through NetBird's per-account LLM gateway. New telemetry properties: | Property | Meaning | |---|---| | `agent_network_accounts` | distinct accounts with ≥1 provider | | `agent_network_providers` | total providers | | `agent_network_policies` | total policies | | `agent_network_budget_rules` | account-level budget rules | | `agent_network_log_collection_enabled` | accounts with log collection on | | `agent_network_input_tokens` | aggregated input tokens | | `agent_network_output_tokens` | aggregated output tokens | | `agent_network_cost_usd` | aggregated cost | Tokens and cost are summed from `agent_network_request_usage` — the always-written per-request ledger — so the figures are accurate regardless of the log-collection toggle and carry no double-counting (unlike the consumption table, which books per-window rows). All values come from a handful of indexed aggregate queries (`COUNT` / `COALESCE(SUM(...))`) executed only on the metrics worker's periodic tick, so the DB/CPU cost is negligible. Implementation: - `store.AgentNetworkMetrics` struct + `GetAgentNetworkMetrics` on the `Store` interface - `SqlStore` implementation (a few aggregate queries) - zero-valued `FileStore` stub (agent-network state isn't persisted in the JSON format) - wired into `metrics.Worker.generateProperties` ## Issue ticket number and link N/A ## 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 (explain why) Anonymized self-hosted telemetry properties are internal and not part of the user-facing product surface. ### 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/__ --- <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 08:08:36 -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#29658