### Development Workflow: Initial Setup Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Set up the development environment by installing dependencies and configuring pre-commit hooks before the first commit. ```bash # Set up development environment make deps make setup-precommit # Verify everything works make check ``` -------------------------------- ### Start Development Mode with Live Reload Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/contributing.md Install 'air' for live reload and start the development server using 'make dev'. ```bash # Install air for live reload go install github.com/air-verse/air@latest # Start development mode make dev ``` -------------------------------- ### Development Environment Setup Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Sets up the development environment by cloning the repository, downloading dependencies, and installing development tools and git hooks. ```bash # Clone repository git clone https://github.com/matanbaruch/netbird-api-exporter.git cd netbird-api-exporter # Install development dependencies go mod download # Install development tools go install golang.org/x/tools/cmd/goimports@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest # Set up git hooks (optional) cp scripts/pre-commit .git/hooks/ chmod +x .git/hooks/pre-commit ``` -------------------------------- ### Pre-commit Framework Installation Options Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Install the pre-commit tool using pip, pipx, Homebrew, or apt. ```bash pip install pre-commit ``` ```bash pipx install pre-commit ``` ```bash brew install pre-commit # macOS ``` ```bash apt install pre-commit # Ubuntu/Debian ``` -------------------------------- ### Pre-commit Framework Configuration Example Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Example configuration for the .pre-commit-config.yaml file, setting up a local hook for 'go fmt'. ```yaml repos: - repo: local hooks: - id: go-fmt name: "go fmt" entry: make fmt language: system files: '\.go$' pass_filenames: false ``` -------------------------------- ### Install Go on Windows Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Installs Go on Windows using Chocolatey. ```bash choco install golang ``` -------------------------------- ### Install Binary and Verify Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/systemd.md Copies the compiled binary to a system location and verifies the installation by checking the version. ```bash # Copy to system location sudo cp /tmp/netbird-api-exporter /usr/local/bin/ sudo chmod +x /usr/local/bin/netbird-api-exporter # Verify installation /usr/local/bin/netbird-api-exporter --version ``` -------------------------------- ### Install Go on Linux Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Installs Go version 1.21.5 on Linux systems and adds it to the PATH. ```bash wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin ``` -------------------------------- ### Pre-commit Framework: Install Hooks Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md After installing the pre-commit tool, run this command to install the git hooks. ```bash pre-commit install ``` -------------------------------- ### Install Go on macOS Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Installs Go on macOS using Homebrew. ```bash brew install go ``` -------------------------------- ### Create Configuration File Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Creates a `config.env` file with example development configuration settings. ```bash # Create config file cat > config.env << 'EOF' NETBIRD_API_TOKEN=nb_api_your_token_here NETBIRD_API_URL=https://api.netbird.io LISTEN_ADDRESS=:8080 METRICS_PATH=/metrics LOG_LEVEL=debug EOF ``` -------------------------------- ### Install Dependencies Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/contributing.md Install project dependencies using the provided Makefile. ```bash make deps ``` -------------------------------- ### Verify Go Installation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Checks the installed Go version. ```bash go version ``` -------------------------------- ### Copy Environment File Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/contributing.md Copy the example environment file to create your local configuration. ```bash cp env.example .env ``` -------------------------------- ### Install Dependencies Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/README.md Install all necessary Ruby gems for local documentation development using Bundler. This command should be run after navigating to the 'docs' directory. ```bash bundle install ``` -------------------------------- ### Basic Helm Installation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the NetBird API Exporter chart from an OCI registry or a local directory. Ensure you provide your NetBird API token. ```bash # From OCI registry (recommended) helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --set netbird.apiToken="nb_token_xxx" # From local directory helm install netbird-api-exporter ./charts/netbird-api-exporter \ --set netbird.apiToken="nb_token_xxx" ``` -------------------------------- ### Update Go Installation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Removes the existing Go installation and installs a new version from a downloaded archive. ```bash # Update Go if needed sudo rm -rf /usr/local/go wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/README.md Start a local Jekyll server to preview the documentation. The site will be accessible at http://localhost:4000. ```bash bundle exec jekyll serve ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/CONTRIBUTING.md Copy the example environment file and edit it with your NetBird API token and other necessary configurations. ```bash cp env.example .env ``` ```env NETBIRD_API_TOKEN=your_token_here NETBIRD_API_URL=https://api.netbird.io LISTEN_ADDRESS=:8080 METRICS_PATH=/metrics LOG_LEVEL=debug ``` -------------------------------- ### Set Up Pre-commit Hooks Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/CONTRIBUTING.md Install and set up pre-commit hooks to ensure code quality and consistency before committing. ```bash make setup-precommit ``` -------------------------------- ### Create Startup Script Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Creates a bash script to load configuration and start the NetBird API Exporter. ```bash # Create startup script sudo tee /opt/netbird-api-exporter/start.sh > /dev/null << 'EOF' #!/bin/bash # Load configuration set -a source /opt/netbird-api-exporter/config.env set +a # Start exporter exec /opt/netbird-api-exporter/netbird-api-exporter EOF sudo chmod +x /opt/netbird-api-exporter/start.sh ``` -------------------------------- ### Start and Enable systemd Service Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/systemd.md Manages the NetBird API Exporter systemd service by reloading the daemon, enabling it to start on boot, starting the service, and checking its status. ```bash # Reload systemd to read the new service sudo systemctl daemon-reload # Enable service to start at boot sudo systemctl enable netbird-api-exporter # Start the service sudo systemctl start netbird-api-exporter # Check status sudo systemctl status netbird-api-exporter ``` -------------------------------- ### Changelog Script Examples Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/CLAUDE.md Examples demonstrating how to use the changelog script for different types of changes, including features, bug fixes, breaking changes, and security fixes. ```bash # New features ./scripts/update-changelog.sh feature "Add support for custom metrics endpoint" # Bug fixes ./scripts/update-changelog.sh bugfix "Fix memory leak in DNS exporter (#123)" # Breaking changes ./scripts/update-changelog.sh breaking "Remove deprecated --old-flag parameter" # Security fixes ./scripts/update-changelog.sh security "Fix potential path traversal vulnerability" ``` -------------------------------- ### Changelog Script Examples Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/AGENTS.md Examples demonstrating how to use the changelog script for different types of changes, including features, bug fixes, breaking changes, and security fixes. ```bash # New features ./scripts/update-changelog.sh feature "Add support for custom metrics endpoint" ``` ```bash # Bug fixes ./scripts/update-changelog.sh bugfix "Fix memory leak in DNS exporter (#123)" ``` ```bash # Breaking changes ./scripts/update-changelog.sh breaking "Remove deprecated --old-flag parameter" ``` ```bash # Security fixes ./scripts/update-changelog.sh security "Fix potential path traversal vulnerability" ``` -------------------------------- ### Install Helm Chart with values.yaml Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md Install or upgrade the NetBird API Exporter using Helm with a custom values.yaml file. ```bash # Create values.yaml cat < values.yaml netbird: apiToken: "your_token_here" apiUrl: "https://api.netbird.io" service: type: ClusterIP port: 8080 serviceMonitor: enabled: true # if using Prometheus operator EOF # Install the chart helm upgrade --install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ -f values.yaml ``` -------------------------------- ### Main Application Entry Point Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/ARCHITECTURE.md The main.go file serves as the clean entry point for the application. It handles configuration management, HTTP server setup, graceful shutdown, and health checks. ```go # Clean and focused application entry point: # Configuration management via environment variables # HTTP server setup with configurable endpoints # Graceful shutdown handling # Health check endpoints # Structured logging setup ``` -------------------------------- ### Build and Run Go Binary Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md Install dependencies, build the Go binary, and run the exporter. Set the NETBIRD_API_TOKEN environment variable before building and running. ```bash go mod download ``` ```bash export NETBIRD_API_TOKEN=your_token_here go build -o netbird-api-exporter ./netbird-api-exporter ``` -------------------------------- ### Helm Install Command Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Command to install the NetBird API Exporter Helm chart from a container registry. Ensure you have Helm v3 installed. ```bash # Install helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ -f values.yaml ``` -------------------------------- ### Install NetBird API Exporter from OCI Registry (Latest Version) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the latest version of the chart directly from the OCI registry. Remember to substitute 'your-netbird-api-token' with your valid NetBird API token. ```bash helm install my-netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --set netbird.apiToken="your-netbird-api-token" ``` -------------------------------- ### Install NetBird API Exporter from Local Directory Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the chart from a local directory after cloning the repository. This method requires you to have the chart source code locally. Replace 'your-netbird-api-token' with your actual token. ```bash # Clone the repository git clone https://github.com/matanbaruch/netbird-api-exporter.git cd netbird-api-exporter # Install the chart helm install my-netbird-api-exporter ./charts/netbird-api-exporter \ --set netbird.apiToken="your-netbird-api-token" ``` -------------------------------- ### Troubleshooting: Check Hook Installation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Verify if the pre-commit hook script is installed in the .git/hooks directory. ```bash ls -la .git/hooks/pre-commit ``` -------------------------------- ### Production Helm Installation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the NetBird API Exporter chart using a production-specific values file. This is useful for managing complex configurations. ```bash # From OCI registry (recommended) helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --values ./values-production.yaml # From local directory helm install netbird-api-exporter ./charts/netbird-api-exporter \ --values ./charts/netbird-api-exporter/values-production.yaml ``` -------------------------------- ### Install Chart from OCI Registry (Latest Version) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Install the latest version of the NetBird API Exporter Helm chart from the OCI registry. Replace 'nb_api_your_token_here' with your actual NetBird API token. ```bash helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --set netbird.apiToken="nb_api_your_token_here" ``` -------------------------------- ### Install NetBird API Exporter via Helm Chart (OCI) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md Install or upgrade the NetBird API Exporter using Helm, specifying the API token directly. ```bash helm upgrade --install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --set netbird.apiToken=your_token_here ``` -------------------------------- ### Install Helm Chart with Command Line Values Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Install the NetBird API Exporter Helm chart using command-line arguments for quick testing. This method allows overriding default values directly. ```bash helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --set netbird.apiToken="nb_api_your_token_here" \ --set netbird.apiUrl="https://api.netbird.io" \ --set service.type="LoadBalancer" ``` -------------------------------- ### Start Docker Compose Stack Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker-compose.md Command to start all services defined in the Docker Compose file in detached mode. ```bash docker-compose -f docker-compose.monitoring.yml up -d ``` -------------------------------- ### Install NetBird API Exporter from OCI Registry (Specific Version) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the chart from the OCI registry using a specific version. Ensure you replace 'your-netbird-api-token' with your actual NetBird API token. ```bash helm install my-netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --set netbird.apiToken="your-netbird-api-token" ``` -------------------------------- ### Install Chart from OCI Registry (Specific Version) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Install the NetBird API Exporter Helm chart from the OCI registry with a specific version. Ensure you replace 'nb_api_your_token_here' with your actual NetBird API token. ```bash helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --set netbird.apiToken="nb_api_your_token_here" ``` -------------------------------- ### Example Go Test Structure Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/contributing.md Illustrates a typical structure for unit tests in Go, including table-driven tests and mocking external dependencies. ```go func TestPeerExporter_CollectMetrics(t *testing.T) { tests := []struct { name string peers []netbird.Peer expected int }{ { name: "empty peers", peers: []netbird.Peer{}, expected: 0, }, // Add more test cases } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Test implementation }) } } ``` -------------------------------- ### Structured Logging with Logrus Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/contributing.md Example of using logrus for structured logging with fields to provide context. ```go log.WithFields(logrus.Fields{ "metric": "peers_total", "count": len(peers), }).Info("Collected peers metric") ``` -------------------------------- ### Enable and Use Memory Profiling Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Starts the exporter with pprof enabled and then uses go tool pprof to analyze heap memory usage. ```bash # Enable memory profiling ./netbird-api-exporter --enable-pprof & go tool pprof http://localhost:8080/debug/pprof/heap ``` -------------------------------- ### Install or Upgrade NetBird API Exporter Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Use this command to install a new release or upgrade an existing one to version 0.1.6. Ensure you have a values.yaml file for custom configurations. ```bash helm upgrade --install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ -f values.yaml ``` -------------------------------- ### Install NetBird API Exporter with Custom Values (Local) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the chart from a local directory using a custom values file. This is useful for applying specific configurations to your deployment. ```bash helm install my-netbird-api-exporter ./charts/netbird-api-exporter \ --values my-values.yaml ``` -------------------------------- ### Describe Pod for Detailed Information Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Get detailed information about a specific Kubernetes pod, useful for troubleshooting startup issues. ```bash kubectl describe pod ``` -------------------------------- ### Build NetBird API Exporter from Source Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/systemd.md Builds the NetBird API Exporter binary from source code. This requires Go 1.21+ to be installed on the system. ```bash # Clone repository git clone https://github.com/matanbaruch/netbird-api-exporter.git cd netbird-api-exporter # Build binary go build -o /tmp/netbird-api-exporter . ``` -------------------------------- ### Callout Examples Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/README.md Demonstrates how to use callouts for important notes, warnings, and general information within the documentation pages. ```markdown {: .important } > This is an important note ``` ```markdown {: .warning } > This is a warning ``` ```markdown {: .note } > This is a note ``` -------------------------------- ### Install NetBird API Exporter with Custom Values (OCI) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the chart from the OCI registry using a custom values file. This allows for more advanced configuration. Ensure 'my-values.yaml' contains your desired settings. ```bash helm install my-netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --values my-values.yaml ``` -------------------------------- ### Verify Installation with Health Check and Metrics Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker-compose.md Check if the exporter is running by accessing its health endpoint and metrics endpoint. ```bash # Health check curl http://localhost:8080/health # View metrics curl http://localhost:8080/metrics ``` -------------------------------- ### Troubleshooting: Check Pre-commit Version Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Verify that the pre-commit tool is installed and accessible by checking its version. ```bash pre-commit --version ``` -------------------------------- ### Install NetBird API Exporter with ExternalSecret Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the chart with ExternalSecret integration enabled for managing the NetBird API token securely. This example uses AWS Secrets Manager. Ensure you have the External Secret Operator installed and a SecretStore configured. ```yaml apiVersion: external-secrets.io/v1beta1 kind: SecretStore metadata: name: aws-secrets-manager spec: provider: aws: service: SecretsManager region: us-west-2 auth: jwt: serviceAccountRef: name: external-secrets-sa ``` ```bash # Install with ExternalSecret helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --set externalSecret.enabled=true \ --set externalSecret.secretStoreRef.name=aws-secrets-manager \ --set-json 'externalSecret.data=[{"secretKey":"netbird-api-token","remoteRef":{"key":"netbird/api-token"}}]' ``` -------------------------------- ### Run Helm Tests Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Execute the included Helm tests to verify the chart's installation and configuration. ```bash helm test netbird-api-exporter ``` -------------------------------- ### CI Integration: Run Checks with Make Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Example of how to run the same checks performed by pre-commit hooks within a CI environment, using make targets. ```yaml # Example GitHub Actions - name: Run checks run: | make fmt make lint make test ``` -------------------------------- ### Deploy NetBird API Exporter to Production Environment Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Install or upgrade the NetBird API Exporter in the 'production' namespace using the production values file. ```bash helm upgrade --install netbird-api-exporter-prod \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ -f values-prod.yaml \ --namespace production ``` -------------------------------- ### Deploy NetBird API Exporter to Staging Environment Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Install or upgrade the NetBird API Exporter in the 'staging' namespace using the staging values file. ```bash helm upgrade --install netbird-api-exporter-staging \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ -f values-staging.yaml \ --namespace staging ``` -------------------------------- ### Deploy NetBird API Exporter to Development Environment Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Install or upgrade the NetBird API Exporter in the 'development' namespace using the development values file. ```bash helm upgrade --install netbird-api-exporter-dev \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ -f values-dev.yaml \ --namespace development ``` -------------------------------- ### Verify Binary Attestation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/ARCHITECTURE.md Use this command to verify the attestation of a binary artifact. Ensure you have the GitHub CLI installed and are authenticated. ```bash gh attestation verify netbird-api-exporter-linux-amd64 --owner matanbaruch ``` -------------------------------- ### Run NetBird Exporter with Debug Logging Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker.md Starts the NetBird API exporter container with debug logging enabled and shows how to view the debug logs. ```bash # Run with debug logging docker run -d \ --name netbird-api-exporter \ -p 8080:8080 \ -e NETBIRD_API_TOKEN="nb_api_your_token_here" \ -e LOG_LEVEL="debug" \ ghcr.io/matanbaruch/netbird-api-exporter:latest # View debug logs docker logs -f netbird-api-exporter ``` -------------------------------- ### Build and Run Docker Image from Source Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md Build the Docker image from source and then run it. Replace 'your_token_here' with your NetBird API token. ```bash docker build -t netbird-api-exporter . docker run -d \ -p 8080:8080 \ -e NETBIRD_API_TOKEN=your_token_here \ --name netbird-api-exporter \ netbird-api-exporter ``` -------------------------------- ### Configure Helm Chart with values.yaml Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md Create a values.yaml file to configure the NetBird API Exporter for Helm installation, including API token and service settings. ```yaml netbird: apiToken: "your_token_here" apiUrl: "https://api.netbird.io" service: type: ClusterIP port: 8080 serviceMonitor: enabled: true # if using Prometheus operator ``` -------------------------------- ### Cross-Platform Builds Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Demonstrates building the binary for various operating systems and architectures using GOOS and GOARCH environment variables. ```bash # Linux AMD64 GOOS=linux GOARCH=amd64 go build -o netbird-api-exporter-linux-amd64 . # Linux ARM64 GOOS=linux GOARCH=arm64 go build -o netbird-api-exporter-linux-arm64 . # macOS AMD64 GOOS=darwin GOARCH=amd64 go build -o netbird-api-exporter-darwin-amd64 . # macOS ARM64 (Apple Silicon) GOOS=darwin GOARCH=arm64 go build -o netbird-api-exporter-darwin-arm64 . # Windows AMD64 GOOS=windows GOARCH=amd64 go build -o netbird-api-exporter-windows-amd64.exe . # Build all platforms using Make make build-all ``` -------------------------------- ### Example API Response for Peers Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/authentication.md This is a truncated example of the expected JSON response when successfully querying the NetBird API for peer information. ```json { "peers": [ { "id": "peer-123", "name": "my-peer", "ip": "100.64.0.1", "connected": true, ... } ] } ``` -------------------------------- ### Create Deployment Directory and Copy Binary Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Creates the deployment directory and copies the built exporter binary into it. ```bash # Create deployment directory sudo mkdir -p /opt/netbird-api-exporter sudo cp netbird-api-exporter /opt/netbird-api-exporter/ ``` -------------------------------- ### Install Coverage Check Pre-commit Hook Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/coverage-monitoring.md Installs the necessary pre-commit hook to ensure code coverage checks are performed before committing changes. ```bash make install-hooks ``` -------------------------------- ### Build NetBird Exporter Docker Image from Source Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker.md Instructions to clone the repository, build a local Docker image, and run it. ```bash # Clone repository git clone https://github.com/matanbaruch/netbird-api-exporter.git cd netbird-api-exporter # Build image docker build -t netbird-api-exporter:local . # Run locally built image docker run -d \ --name netbird-api-exporter \ -p 8080:8080 \ --env-file netbird-exporter.env \ netbird-api-exporter:local ``` -------------------------------- ### Start NetBird API Exporter with Docker Compose Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker-compose.md Start the NetBird API Exporter container in detached mode using Docker Compose. ```bash docker-compose up -d ``` -------------------------------- ### Build and Test Project Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/contributing.md Build the project, run tests, and execute all checks including linting. ```bash # Build the project make build # Run tests make test # Run all checks (tests + linting) make check ``` -------------------------------- ### Verify NetBird API Exporter Installation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/systemd.md Verifies the NetBird API Exporter installation by checking if the service is active and by testing its health and metrics endpoints via curl. ```bash # Check service status sudo systemctl is-active netbird-api-exporter # Test health endpoint curl http://localhost:8080/health # Test metrics endpoint curl http://localhost:8080/metrics ``` -------------------------------- ### Production Build with Optimizations Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Creates an optimized production build using Go's linker flags for smaller binary size. ```bash # Production build with optimizations go build -ldflags="-s -w" -o netbird-api-exporter . # Or using Make make build-prod ``` -------------------------------- ### Helm Installation with Prometheus Operator Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/README.md Install the NetBird API Exporter chart and enable Prometheus ServiceMonitor integration. This allows Prometheus to automatically discover and scrape metrics. ```bash # From OCI registry (recommended) helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --set netbird.apiToken="nb_token_xxx" \ --set serviceMonitor.enabled=true \ --set serviceMonitor.additionalLabels.release=prometheus # From local directory helm install netbird-api-exporter ./charts/netbird-api-exporter \ --set netbird.apiToken="nb_token_xxx" \ --set serviceMonitor.enabled=true \ --set serviceMonitor.additionalLabels.release=prometheus ``` -------------------------------- ### Example Prometheus Queries Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md These are example Prometheus queries for monitoring NetBird metrics. They can be used to track router counts, resource counts, and network scrape error rates. ```Prometheus sum(netbird_network_routers_count) ``` ```Prometheus sum(netbird_network_resources_count) ``` ```Prometheus rate(netbird_networks_scrape_errors_total[5m]) ``` -------------------------------- ### Build with Version Information Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Builds the binary and embeds version, build time, and Git commit information using linker flags. ```bash VERSION=$(git describe --tags --always --dirty) BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ') GIT_COMMIT=$(git rev-parse --short HEAD) go build \ -ldflags="-s -w -X main.Version=$VERSION -X main.BuildTime=$BUILD_TIME -X main.GitCommit=$GIT_COMMIT" \ -o netbird-api-exporter . ``` -------------------------------- ### Useful Make Commands for Development Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/contributing.md Lists common `make` commands for development, including building, running with Docker Compose, and viewing logs. Essential for setting up and managing the development environment. ```bash make help # Show all available commands make dev # Development mode with live reload make docker-compose-up # Run with Docker Compose make docker-compose-logs # View container logs make build-all # Build for multiple platforms make security # Run security scan ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/README.md Manually build the Jekyll static site for deployment. The output will be generated in the '_site/' directory. ```bash # Build the site cd docs bundle exec jekyll build ``` -------------------------------- ### Download Go Modules and Build Binary Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md Commands to download Go module dependencies and build the NetBird API Exporter binary from source. ```bash go mod download go build -o netbird-api-exporter ``` -------------------------------- ### Use Direct Module Download Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Configures Go to download modules directly, bypassing any proxy, to troubleshoot download issues. ```bash # Use direct module download GOPROXY=direct go mod download ``` -------------------------------- ### Troubleshoot Container Startup Issues Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker.md Commands to check container logs and configuration for troubleshooting startup problems. Common causes include invalid tokens, port conflicts, or resource limits. ```bash # Check container logs docker logs netbird-api-exporter # Check container configuration docker inspect netbird-api-exporter # Common causes: # - Invalid API token # - Port already in use # - Resource constraints ``` -------------------------------- ### Create Configuration File Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Creates the configuration file for the NetBird API Exporter with essential settings. ```bash # Create configuration sudo tee /opt/netbird-api-exporter/config.env > /dev/null << 'EOF' NETBIRD_API_TOKEN=nb_api_your_token_here NETBIRD_API_URL=https://api.netbird.io LISTEN_ADDRESS=:8080 METRICS_PATH=/metrics LOG_LEVEL=info EOF ``` -------------------------------- ### Install Helm Chart Referencing Existing Secret Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Install the NetBird API Exporter Helm chart from the OCI registry, referencing an existing Kubernetes secret for the API token. Replace 'netbird-api-secret' if you used a different secret name. ```bash helm install netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ --set netbird.existingSecret="netbird-api-secret" ``` -------------------------------- ### Manual Testing: All Hooks with Pre-commit Framework Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Run all configured pre-commit hooks on all files in the repository using the pre-commit framework. ```bash pre-commit run --all-files ``` -------------------------------- ### Run Docker Image Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/README.md Run the pre-built Docker image from GitHub packages. Ensure you replace 'your_token_here' with your actual NetBird API token. ```bash docker run -d \ -p 8080:8080 \ -e NETBIRD_API_TOKEN=your_token_here \ --name netbird-api-exporter \ ghcr.io/matanbaruch/netbird-api-exporter:latest ``` -------------------------------- ### Verify Exporter Installation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Tests the health and metrics endpoints of the running NetBird API Exporter. ```bash # Test health endpoint curl http://localhost:8080/health # Test metrics endpoint curl http://localhost:8080/metrics ``` -------------------------------- ### Directory Structure Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/ARCHITECTURE.md The project follows a standard Go project structure with dedicated directories for core packages, exporters, Kubernetes deployments, documentation, and configuration files. ```bash netbird-api-exporter/ ├── main.go # Clean application entry point ├── pkg/ # Core application packages │ ├── netbird/ # NetBird API client and types │ │ ├── client.go # Base HTTP client for NetBird API │ │ └── types.go # Shared data structures (Peer, Group, User, etc.) │ ├── exporters/ # Prometheus exporters for different APIs │ │ ├── exporter.go # Main composite exporter │ │ ├── peers.go # Peers API exporter │ │ ├── groups.go # Groups API exporter │ │ ├── users.go # Users API exporter │ │ ├── networks.go # Networks API exporter │ │ ├── dns.go # DNS API exporter │ │ └── *_test.go # Comprehensive test suite for each exporter │ └── utils/ # Utility functions │ └── config.go # Configuration helpers ├── charts/ # Kubernetes deployment │ └── netbird-api-exporter/ # Helm chart for K8s deployment │ └── templates/ # K8s resource templates │ └── tests/ # Helm chart tests ├── docs/ # GitHub Pages documentation │ ├── _config.yml # Jekyll configuration │ ├── _sass/ # Styling for documentation │ ├── getting-started/ # Getting started guides │ ├── installation/ # Installation documentation │ ├── index.md # Documentation homepage │ └── *.md # Various documentation files ├── tmp/ # Temporary files (gitignored) ├── docker-compose.yml # Local development with Docker Compose ├── Dockerfile # Container image definition ├── env.example # Environment variables template ├── Makefile # Build and development automation ├── netbird-exporter.service # Systemd service file ├── prometheus.yml.example # Example Prometheus configuration ├── go.mod # Go module definition ├── go.sum # Go module checksums ├── LICENSE # Project license ├── README.md # Main project documentation ├── CONTRIBUTING.md # Contribution guidelines └── ARCHITECTURE.md # This file ``` -------------------------------- ### Normal Commit Workflow with Pre-commit Hooks Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Demonstrates the standard workflow: make changes, stage them, and commit. Hooks run automatically before the commit is finalized. ```bash # Make changes to Go files vim pkg/exporters/peer.go # Stage changes git add . # Commit (hooks run automatically) git commit -m "Add new feature" ``` -------------------------------- ### Run All Tests Command Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/CONTRIBUTING.md Execute all tests in the project using the make command. This is a prerequisite for submitting changes. ```bash make test ``` -------------------------------- ### Retrieve Helm Release Values Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Get the current configuration values applied to the netbird-api-exporter Helm release. ```bash helm get values netbird-api-exporter ``` -------------------------------- ### Static Binary Build for Linux Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Creates a statically linked binary for Linux with no external dynamic dependencies. ```bash # Static build for Linux CGO_ENABLED=0 GOOS=linux go build \ -a -installsuffix cgo \ -ldflags="-s -w -extldflags '-static'" \ -o netbird-api-exporter-static . # Verify static linking ldd netbird-api-exporter-static # Should output: "not a dynamic executable" ``` -------------------------------- ### Build Optimized Binary for Load Testing Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Builds an optimized binary for load testing using linker flags. ```bash # Build optimized binary for load testing go build -ldflags="-s -w" -o netbird-api-exporter . ``` -------------------------------- ### Build Production Binary Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Builds the production-ready binary for the NetBird API Exporter using a make command. ```bash # Build production binary make build-prod ``` -------------------------------- ### Describe Node for Resource Pressure Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Get detailed information about a node, including resource pressure, to diagnose scheduling issues. ```bash kubectl describe node ``` -------------------------------- ### Create Dedicated User and Directories Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/systemd.md Sets up a dedicated system user for the NetBird API Exporter and creates necessary directories for configuration and logs, ensuring correct ownership and permissions. ```bash # Create dedicated user (no login shell for security) sudo useradd --system --no-create-home --shell /bin/false netbird-api-exporter # Create configuration directory sudo mkdir -p /etc/netbird-api-exporter sudo chown netbird-api-exporter:netbird-api-exporter /etc/netbird-api-exporter sudo chmod 750 /etc/netbird-api-exporter # Create log directory (optional) sudo mkdir -p /var/log/netbird-api-exporter sudo chown netbird-api-exporter:netbird-api-exporter /var/log/netbird-api-exporter sudo chmod 755 /var/log/netbird-api-exporter ``` -------------------------------- ### Verify NetBird API Exporter Pod Status Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Check the status of the NetBird API Exporter pods after installation using kubectl. ```bash kubectl get pods -l app.kubernetes.io/name=netbird-api-exporter ``` -------------------------------- ### Run Grafana Docker Container Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker.md Starts Grafana as a detached Docker container, mapping port 3000 and setting the admin password. ```bash docker run -d \ --name grafana \ --network monitoring \ -p 3000:3000 \ -e GF_SECURITY_ADMIN_PASSWORD=admin \ --restart unless-stopped \ grafana/grafana:latest ``` -------------------------------- ### Run NetBird API Exporter with All Configuration Options Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker.md Demonstrates running the NetBird API Exporter with a comprehensive set of environment variables and Docker run options, including resource limits and security settings. ```bash docker run -d \ --name netbird-api-exporter \ -p 8080:8080 \ -e NETBIRD_API_TOKEN="nb_api_your_token_here" \ -e NETBIRD_API_URL="https://api.netbird.io" \ -e LISTEN_ADDRESS=":8080" \ -e METRICS_PATH="/metrics" \ -e LOG_LEVEL="info" \ --restart unless-stopped \ --memory="128m" \ --cpus="0.2" \ --read-only \ --user 65534:65534 \ --cap-drop ALL \ --security-opt no-new-privileges:true \ ghcr.io/matanbaruch/netbird-api-exporter:latest ``` -------------------------------- ### Advanced Configuration: Add Custom Hook Script Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Example of modifying the 'scripts/pre-commit' script to include custom checks, such as a security scan. ```bash # Add security scanning echo "🔒 Running security scan..." if ! make security; then echo "❌ Security scan failed" exit 1 fi ``` -------------------------------- ### Get Application URL (Ingress) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/templates/NOTES.txt Retrieves the application URL when Ingress is enabled. This is useful for accessing the exporter via a public URL. ```go-template {{- if .Values.ingress.enabled }} {{- range $host := .Values.ingress.hosts }} {{- range .paths }} http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} {{- end }} {{- end }} {{- end }} ``` -------------------------------- ### Navigate to Docs Directory Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/README.md Change the current directory to the 'docs' folder. This is a prerequisite for running local development commands. ```bash cd docs ``` -------------------------------- ### Docker Container Management Commands Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker.md Common Docker commands for managing containers, including starting, stopping, restarting, removing, and viewing status. ```bash # Start container docker start netbird-api-exporter # Stop container docker stop netbird-api-exporter # Restart container docker restart netbird-api-exporter # Remove container docker rm netbird-api-exporter # View container status docker ps -f name=netbird-api-exporter # Inspect container configuration docker inspect netbird-api-exporter ``` -------------------------------- ### Environment Variables for NetBird API Configuration Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/ARCHITECTURE.md Example environment variables for configuring the NetBird API client and the exporter's server settings. ```env # NetBird API Configuration NETBIRD_API_URL=https://api.netbird.io NETBIRD_API_TOKEN=your_token_here # Server Configuration LISTEN_ADDRESS=:8080 METRICS_PATH=/metrics # Logging LOG_LEVEL=info ``` -------------------------------- ### Troubleshooting: Auto-fix Common Lint Issues Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started/pre-commit-hooks.md Use 'make fmt' to automatically format Go code and fix common linting issues. ```bash make fmt ``` -------------------------------- ### Get Application URL (ClusterIP) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/templates/NOTES.txt Retrieves the application URL and sets up port-forwarding when using ClusterIP service type. Access is via localhost. ```bash export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "netbird-api-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT {{- end }} ``` -------------------------------- ### Create Release Artifacts Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Create a compressed tarball artifact for the release binaries. ```bash # Create release artifacts tar -czf netbird-api-exporter-v0.2.0-linux-amd64.tar.gz netbird-api-exporter-linux-amd64 ``` -------------------------------- ### Get Application URL (LoadBalancer) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/templates/NOTES.txt Retrieves the application URL when using LoadBalancer service type. It exports the LoadBalancer IP and service port. ```bash {{- else if contains "LoadBalancer" .Values.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "netbird-api-exporter.fullname" . }}' export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "netbird-api-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}) echo http://$SERVICE_IP:{{ .Values.service.port }} {{- else if contains "ClusterIP" .Values.service.type }} ``` -------------------------------- ### Verify Binary Attestations Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/SECURITY.md Download and verify binary attestations using the GitHub CLI. Replace [VERSION] with the specific release version you are verifying. ```bash # Download and verify binary attestations gh run download --repo netbird-io/netbird-api-exporter --name netbird-api-exporter-binaries-[VERSION] gh attestation verify netbird-api-exporter-linux-amd64 --owner netbird-io ``` -------------------------------- ### Generate Documentation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Generate API documentation using godoc for local viewing. ```bash # Generate documentation godoc -http=:6060 ``` -------------------------------- ### Build with Profiling Support Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Builds the exporter with linker flags for profiling support. ```bash # Build with profiling go build -ldflags="-s -w" -o netbird-api-exporter . ``` -------------------------------- ### Build Release Binaries Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Build all release binaries for the exporter. ```bash # Build release binaries make build-all ``` -------------------------------- ### Build for Production Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Builds the exporter for production environments using build tags. ```bash # Build for production go build -tags production -o netbird-api-exporter . ``` -------------------------------- ### Stop and Disable NetBird API Exporter Service Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/systemd.md Use these commands to stop the running NetBird API Exporter service and prevent it from starting on boot. ```bash sudo systemctl stop netbird-api-exporter sudo systemctl disable netbird-api-exporter ``` -------------------------------- ### Helm Upgrade with API Token Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/templates/NOTES.txt Demonstrates how to upgrade a Helm release and set the NetBird API token using the --set flag. ```bash helm upgrade {{ .Release.Name }} ./charts/netbird-api-exporter --set netbird.apiToken="your-token" ``` -------------------------------- ### Run NetBird Exporter Docker Container Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/docker.md Starts the NetBird API exporter as a detached Docker container. Ensure you have a 'netbird-exporter.env' file with necessary credentials. ```bash docker run -d \ --name netbird-api-exporter \ --network monitoring \ --env-file netbird-exporter.env \ --restart unless-stopped \ ghcr.io/matanbaruch/netbird-api-exporter:latest ``` -------------------------------- ### Check Binary Permissions Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Lists the file permissions of the exporter binary to diagnose startup issues. ```bash # Check binary permissions ls -la netbird-api-exporter ``` -------------------------------- ### Service Control Commands Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/systemd.md Common systemctl commands to manage the NetBird API Exporter service, including starting, stopping, restarting, and enabling/disabling auto-start. ```bash # Start service sudo systemctl start netbird-api-exporter # Stop service sudo systemctl stop netbird-api-exporter # Restart service sudo systemctl restart netbird-api-exporter # Reload configuration (restart required for env changes) sudo systemctl reload-or-restart netbird-api-exporter # Enable auto-start at boot sudo systemctl enable netbird-api-exporter # Disable auto-start at boot sudo systemctl disable netbird-api-exporter ``` -------------------------------- ### Retrieve Exporter Metrics Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/getting-started.md Access this endpoint to retrieve Prometheus metrics exposed by the NetBird API Exporter. The output should start with metric definitions and values. ```bash curl http://localhost:8080/metrics ``` -------------------------------- ### Get Application URL (NodePort) Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/charts/netbird-api-exporter/templates/NOTES.txt Retrieves the application URL when using NodePort service type. It exports the NodePort and Node IP to construct the URL. ```bash {{- else if contains "NodePort" .Values.service.type }} export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "netbird-api-exporter.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT {{- end }} ``` -------------------------------- ### Helm Upgrade Command Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/helm.md Command to upgrade an existing installation of the NetBird API Exporter Helm chart. Use this to apply new versions or configuration changes. ```bash # Upgrade helm upgrade netbird-api-exporter \ oci://ghcr.io/matanbaruch/netbird-api-exporter/charts/netbird-api-exporter \ --version 0.1.6 \ -f values.yaml ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/CONTRIBUTING.md Execute Go tests and generate a coverage report. This helps identify areas of the code not covered by tests. ```bash go test -cover ./... ``` -------------------------------- ### Make Changes and Test Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/installation/binary.md Make code changes and run tests and linters to ensure code quality. ```bash # Make changes and test make test make lint ``` -------------------------------- ### Verify Docker Image Attestation Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/SECURITY.md Use the GitHub CLI to verify the build provenance attestation for the latest Docker image. Ensure you have the GitHub CLI installed. ```bash # Install GitHub CLI if not already installed # See: https://cli.github.com/ # Verify Docker image attestation gh attestation verify oci://ghcr.io/netbird-io/netbird-api-exporter:latest --owner netbird-io ``` -------------------------------- ### Jekyll Page Front Matter Structure Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/README.md Example of the front matter required at the top of each documentation page. It defines layout, title, parent page, and navigation order. ```yaml --- layout: default title: Page Title parent: Parent Page (optional) nav_order: 1 has_children: true (optional) --- ``` -------------------------------- ### Prometheus Scrape Configuration Source: https://github.com/matanbaruch/netbird-api-exporter/blob/main/docs/index.md Add this configuration to your Prometheus setup to scrape metrics from the NetBird API Exporter. Ensure the target address matches your exporter's deployment. ```yaml scrape_configs: - job_name: 'netbird-api-exporter' static_configs: - targets: ['localhost:8080'] # Update with your exporter address scrape_interval: 30s metrics_path: /metrics ```