Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,70 @@ on:
push:
branches: [ master ]
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, macos-13, macos-14] # linux-x86_64, darwin-x86_64, darwin-arm64
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-13, macos-14] # linux-x86_64, linux-arm64, darwin-x86_64, darwin-arm64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.23.6'
go-version: '1.23.11'
- run: make test
- run: make package
- run: shasum -a 256 node_exporter node_exporter*.tar.gz
- run: shasum -a 256 node_exporter node_exporter*.tar.gz | tee checksums-${{ matrix.os }}.txt
- uses: actions/upload-artifact@v4
with:
name: package-${{ matrix.os }}
path: "*.tar.gz"
- uses: actions/upload-artifact@v4
with:
name: checksums-${{ matrix.os }}
path: "checksums-${{ matrix.os }}.txt"

create-universal-binary:
runs-on: macos-14
needs: build
steps:
- uses: actions/checkout@v4
- name: Download macOS x86_64 artifact
uses: actions/download-artifact@v4
with:
name: package-macos-13
path: ./macos-x86_64
- name: Download macOS arm64 artifact
uses: actions/download-artifact@v4
with:
name: package-macos-14
path: ./macos-arm64
- name: Extract binaries
run: |
cd macos-x86_64 && tar -xzf *.tar.gz
cd ../macos-arm64 && tar -xzf *.tar.gz
- name: Create universal binary
run: |
lipo -create -output node_exporter_universal \
macos-x86_64/node_exporter \
macos-arm64/node_exporter
- name: Verify universal binary
run: |
file node_exporter_universal
lipo -info node_exporter_universal
- name: Package universal binary
run: |
mv node_exporter_universal node_exporter
PACKAGE_NAME=node_exporter-stable-darwin-universal.tar.gz
tar -czvf ${PACKAGE_NAME} node_exporter
- name: Generate checksum
run: shasum -a 256 node_exporter node_exporter*.tar.gz | tee checksums-darwin-universal.txt
- uses: actions/upload-artifact@v4
with:
name: package-darwin-universal
path: "*.tar.gz"
- uses: actions/upload-artifact@v4
with:
name: checksums-darwin-universal
path: "checksums-darwin-universal.txt"
98 changes: 98 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

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.

The key distinguishing feature of this fork is the `gateway.go` collector in the `collector/` directory, which provides enhanced functionality for Algorand's needs.

## Development Commands

### Building
```bash
make # Build with all checks (style, vet, staticcheck, checkmetrics, build, package, test)
make build # Build binaries only
make package # Create tarball package
```

### Testing
```bash
make test # Run all tests
make test-short # Run short tests only
make test-e2e # Run end-to-end tests (Linux only)
make test-32bit # Cross-architecture testing (when supported)
```

### Code Quality
```bash
make style # Check code formatting
make vet # Run go vet
make staticcheck # Run staticcheck linter
make checkmetrics # Validate metrics with promtool
make format # Format code
```

### Docker
```bash
make docker # Build Docker image
make test-docker # Test Docker image
```

## Code Architecture

### Core Components

1. **Main Entry Point** (`node_exporter.go`): HTTP server that exposes metrics at `/metrics` endpoint
2. **Collector Framework** (`collector/collector.go`): Plugin architecture for metric collectors
3. **Gateway Collector** (`collector/gateway.go`): Algorand-specific collector with buffering and POST handling
4. **Individual Collectors** (`collector/*_*.go`): Platform-specific metric collectors

### Collector System

The Node Exporter uses a plugin-based collector system:
- Collectors are registered via `registerCollector()` with default enabled/disabled state
- Each collector implements the `Collector` interface with `Update(ch chan<- prometheus.Metric) error`
- Collectors can be enabled/disabled via `--collector.<name>` and `--no-collector.<name>` flags
- The main collector orchestrates concurrent collection from all enabled collectors

### Gateway Collector Architecture

The gateway collector (`collector/gateway.go`) provides unique functionality:
- Acts as HTTP middleware, intercepting POST requests to `/metrics`
- Parses Prometheus format metrics from POST body
- Maintains internal counters and gauges with automatic expiration
- Implements buffering with configurable sample intervals
- Provides metric lifecycle management (creation, updating, expiration)

## Platform Support

Collectors have varying support across operating systems:
- **Linux**: Full support for most collectors
- **Darwin/macOS**: Limited support for core metrics
- **BSD variants**: Platform-specific implementations
- **Windows**: Use WMI exporter instead

## Build System

- Uses Go modules (`go.mod`) with Go 1.23+
- Makefile-based build system with `Makefile.common` for shared rules
- Cross-compilation support via `GOOS`/`GOARCH` environment variables
- CGO usage controlled by `.promu-cgo.yml` vs `.promu-no-cgo.yml`
- CI/CD via GitHub Actions (`.github/workflows/build.yml`)

## Testing Infrastructure

- Extensive fixture-based testing in `collector/fixtures/`
- Mock `/proc` and `/sys` filesystem data for reproducible tests
- End-to-end testing with expected output validation
- Platform-specific test execution based on build environment

## Key Design Principles

1. **Machine Metrics Only**: Focus on hardware/OS metrics, not application metrics
2. **No External Commands**: Use only system calls, proc/sys files, and local sockets
3. **No Root Privileges**: All metrics must be accessible without elevated permissions
4. **Hardware Agnostic**: Expose raw values without vendor-specific transformations
5. **Performance First**: Concurrent collection with minimal overhead