Documentation
¶
Index ¶
- Constants
- func IsMetricsPushEnabled() bool
- type AgentInfo
- type ClientMetrics
- func (c *ClientMetrics) Export(w io.Writer) error
- func (c *ClientMetrics) RecordConnectionStages(ctx context.Context, remotePubKey string, connectionType ConnectionType, ...)
- func (c *ClientMetrics) RecordLoginDuration(ctx context.Context, duration time.Duration, success bool)
- func (c *ClientMetrics) RecordSyncDuration(ctx context.Context, duration time.Duration)
- func (c *ClientMetrics) StartPush(ctx context.Context, config PushConfig)
- func (c *ClientMetrics) StopPush()
- func (c *ClientMetrics) UpdateAgentInfo(agentInfo AgentInfo, publicKey string)
- type ConnectionStageTimestamps
- type ConnectionType
- type DeploymentType
- type Push
- type PushConfig
Constants ¶
const ( // EnvMetricsPushEnabled controls whether collected metrics are pushed to the backend. // Metrics collection itself is always active (for debug bundles). // Disabled by default. Set NB_METRICS_PUSH_ENABLED=true to enable push. EnvMetricsPushEnabled = "NB_METRICS_PUSH_ENABLED" // EnvMetricsForceSending if set to true, skips remote configuration fetch and forces metric sending EnvMetricsForceSending = "NB_METRICS_FORCE_SENDING" // EnvMetricsConfigURL is the environment variable to override the metrics push config ServerAddress EnvMetricsConfigURL = "NB_METRICS_CONFIG_URL" // EnvMetricsServerURL is the environment variable to override the metrics server address. // When set, this takes precedence over the server_url from remote push config. EnvMetricsServerURL = "NB_METRICS_SERVER_URL" // EnvMetricsInterval overrides the push interval from the remote config. // Only affects how often metrics are pushed; remote config availability // and version range checks are still respected. // Format: duration string like "1h", "30m", "4h" EnvMetricsInterval = "NB_METRICS_INTERVAL" )
Variables ¶
This section is empty.
Functions ¶
func IsMetricsPushEnabled ¶
func IsMetricsPushEnabled() bool
IsMetricsPushEnabled returns true if metrics push is enabled via NB_METRICS_PUSH_ENABLED env var. Disabled by default. Metrics collection is always active for debug bundles.
Types ¶
type AgentInfo ¶
type AgentInfo struct {
DeploymentType DeploymentType
Version string
OS string // runtime.GOOS (linux, darwin, windows, etc.)
Arch string // runtime.GOARCH (amd64, arm64, etc.)
// contains filtered or unexported fields
}
AgentInfo holds static information about the agent
type ClientMetrics ¶
type ClientMetrics struct {
// contains filtered or unexported fields
}
func NewClientMetrics ¶
func NewClientMetrics(agentInfo AgentInfo) *ClientMetrics
NewClientMetrics creates a new ClientMetrics instance
func (*ClientMetrics) Export ¶
func (c *ClientMetrics) Export(w io.Writer) error
Export exports metrics to the writer
func (*ClientMetrics) RecordConnectionStages ¶
func (c *ClientMetrics) RecordConnectionStages( ctx context.Context, remotePubKey string, connectionType ConnectionType, isReconnection bool, timestamps ConnectionStageTimestamps, )
RecordConnectionStages calculates stage durations from timestamps and records them. remotePubKey is the remote peer's WireGuard public key; it will be hashed for anonymisation.
func (*ClientMetrics) RecordLoginDuration ¶
func (c *ClientMetrics) RecordLoginDuration(ctx context.Context, duration time.Duration, success bool)
RecordLoginDuration records how long the login to management server took
func (*ClientMetrics) RecordSyncDuration ¶
func (c *ClientMetrics) RecordSyncDuration(ctx context.Context, duration time.Duration)
RecordSyncDuration records the duration of sync message processing
func (*ClientMetrics) StartPush ¶
func (c *ClientMetrics) StartPush(ctx context.Context, config PushConfig)
StartPush starts periodic pushing of metrics with the given configuration Precedence: PushConfig.ServerAddress > remote config server_url
func (*ClientMetrics) StopPush ¶
func (c *ClientMetrics) StopPush()
func (*ClientMetrics) UpdateAgentInfo ¶
func (c *ClientMetrics) UpdateAgentInfo(agentInfo AgentInfo, publicKey string)
UpdateAgentInfo updates the agent information (e.g., when switching profiles). publicKey is the WireGuard public key; it will be hashed for anonymisation.
type ConnectionStageTimestamps ¶
type ConnectionStageTimestamps struct {
SignalingReceived time.Time // First signal received from remote peer (both initial and reconnection)
ConnectionReady time.Time
WgHandshakeSuccess time.Time
}
ConnectionStageTimestamps holds timestamps for each connection stage
func (ConnectionStageTimestamps) String ¶
func (c ConnectionStageTimestamps) String() string
String returns a human-readable representation of the connection stage timestamps
type ConnectionType ¶
type ConnectionType string
ConnectionType represents the type of peer connection
const ( // ConnectionTypeICE represents a direct peer-to-peer connection using ICE ConnectionTypeICE ConnectionType = "ice" // ConnectionTypeRelay represents a relayed connection ConnectionTypeRelay ConnectionType = "relay" )
func (ConnectionType) String ¶
func (c ConnectionType) String() string
String returns the string representation of the connection type
type DeploymentType ¶
type DeploymentType int
DeploymentType represents the type of NetBird deployment
const ( // DeploymentTypeUnknown represents an unknown or uninitialized deployment type DeploymentTypeUnknown DeploymentType = iota // DeploymentTypeCloud represents a cloud-hosted NetBird deployment DeploymentTypeCloud // DeploymentTypeSelfHosted represents a self-hosted NetBird deployment DeploymentTypeSelfHosted )
func DetermineDeploymentType ¶
func DetermineDeploymentType(managementURL string) DeploymentType
DetermineDeploymentType determines if the deployment is cloud or self-hosted based on the management URL string
func (DeploymentType) String ¶
func (d DeploymentType) String() string
String returns the string representation of the deployment type
type Push ¶
type Push struct {
// contains filtered or unexported fields
}
Push handles periodic pushing of metrics
func NewPush ¶
func NewPush(metrics metricsImplementation, configManager remoteConfigProvider, config PushConfig, agentVersion string) (*Push, error)
NewPush creates a new Push instance with configuration resolution
type PushConfig ¶
type PushConfig struct {
// ServerAddress is the metrics server URL. If nil, uses remote config server_url.
ServerAddress *url.URL
// Interval is how often to push metrics. If 0, uses remote config interval or defaultPushInterval.
Interval time.Duration
// ForceSending skips remote configuration fetch and version checks, pushing unconditionally.
ForceSending bool
}
PushConfig holds configuration for metrics push
func PushConfigFromEnv ¶
func PushConfigFromEnv() PushConfig
PushConfigFromEnv builds a PushConfig from environment variables.