|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a fork of the Prometheus Node Exporter that includes an additional **gateway collector** for Algod with buffering and other features. The Node Exporter is a Prometheus exporter for hardware and OS metrics exposed by *NIX kernels, written in Go with pluggable metric collectors. |
| 8 | + |
| 9 | +The key distinguishing feature of this fork is the `gateway.go` collector in the `collector/` directory, which provides enhanced functionality for Algorand's needs. |
| 10 | + |
| 11 | +## Development Commands |
| 12 | + |
| 13 | +### Building |
| 14 | +```bash |
| 15 | +make # Build with all checks (style, vet, staticcheck, checkmetrics, build, package, test) |
| 16 | +make build # Build binaries only |
| 17 | +make package # Create tarball package |
| 18 | +``` |
| 19 | + |
| 20 | +### Testing |
| 21 | +```bash |
| 22 | +make test # Run all tests |
| 23 | +make test-short # Run short tests only |
| 24 | +make test-e2e # Run end-to-end tests (Linux only) |
| 25 | +make test-32bit # Cross-architecture testing (when supported) |
| 26 | +``` |
| 27 | + |
| 28 | +### Code Quality |
| 29 | +```bash |
| 30 | +make style # Check code formatting |
| 31 | +make vet # Run go vet |
| 32 | +make staticcheck # Run staticcheck linter |
| 33 | +make checkmetrics # Validate metrics with promtool |
| 34 | +make format # Format code |
| 35 | +``` |
| 36 | + |
| 37 | +### Docker |
| 38 | +```bash |
| 39 | +make docker # Build Docker image |
| 40 | +make test-docker # Test Docker image |
| 41 | +``` |
| 42 | + |
| 43 | +## Code Architecture |
| 44 | + |
| 45 | +### Core Components |
| 46 | + |
| 47 | +1. **Main Entry Point** (`node_exporter.go`): HTTP server that exposes metrics at `/metrics` endpoint |
| 48 | +2. **Collector Framework** (`collector/collector.go`): Plugin architecture for metric collectors |
| 49 | +3. **Gateway Collector** (`collector/gateway.go`): Algorand-specific collector with buffering and POST handling |
| 50 | +4. **Individual Collectors** (`collector/*_*.go`): Platform-specific metric collectors |
| 51 | + |
| 52 | +### Collector System |
| 53 | + |
| 54 | +The Node Exporter uses a plugin-based collector system: |
| 55 | +- Collectors are registered via `registerCollector()` with default enabled/disabled state |
| 56 | +- Each collector implements the `Collector` interface with `Update(ch chan<- prometheus.Metric) error` |
| 57 | +- Collectors can be enabled/disabled via `--collector.<name>` and `--no-collector.<name>` flags |
| 58 | +- The main collector orchestrates concurrent collection from all enabled collectors |
| 59 | + |
| 60 | +### Gateway Collector Architecture |
| 61 | + |
| 62 | +The gateway collector (`collector/gateway.go`) provides unique functionality: |
| 63 | +- Acts as HTTP middleware, intercepting POST requests to `/metrics` |
| 64 | +- Parses Prometheus format metrics from POST body |
| 65 | +- Maintains internal counters and gauges with automatic expiration |
| 66 | +- Implements buffering with configurable sample intervals |
| 67 | +- Provides metric lifecycle management (creation, updating, expiration) |
| 68 | + |
| 69 | +## Platform Support |
| 70 | + |
| 71 | +Collectors have varying support across operating systems: |
| 72 | +- **Linux**: Full support for most collectors |
| 73 | +- **Darwin/macOS**: Limited support for core metrics |
| 74 | +- **BSD variants**: Platform-specific implementations |
| 75 | +- **Windows**: Use WMI exporter instead |
| 76 | + |
| 77 | +## Build System |
| 78 | + |
| 79 | +- Uses Go modules (`go.mod`) with Go 1.23+ |
| 80 | +- Makefile-based build system with `Makefile.common` for shared rules |
| 81 | +- Cross-compilation support via `GOOS`/`GOARCH` environment variables |
| 82 | +- CGO usage controlled by `.promu-cgo.yml` vs `.promu-no-cgo.yml` |
| 83 | +- CI/CD via GitHub Actions (`.github/workflows/build.yml`) |
| 84 | + |
| 85 | +## Testing Infrastructure |
| 86 | + |
| 87 | +- Extensive fixture-based testing in `collector/fixtures/` |
| 88 | +- Mock `/proc` and `/sys` filesystem data for reproducible tests |
| 89 | +- End-to-end testing with expected output validation |
| 90 | +- Platform-specific test execution based on build environment |
| 91 | + |
| 92 | +## Key Design Principles |
| 93 | + |
| 94 | +1. **Machine Metrics Only**: Focus on hardware/OS metrics, not application metrics |
| 95 | +2. **No External Commands**: Use only system calls, proc/sys files, and local sockets |
| 96 | +3. **No Root Privileges**: All metrics must be accessible without elevated permissions |
| 97 | +4. **Hardware Agnostic**: Expose raw values without vendor-specific transformations |
| 98 | +5. **Performance First**: Concurrent collection with minimal overhead |
0 commit comments