node

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogStdout = "stdout"
	LogStderr = "stderr"
)

Log streams name the container file descriptor a line arrived on.

Variables

View Source
var (
	// ErrMemTotalNotFound indicates that the MemTotal line could not be found in /proc/meminfo.
	ErrMemTotalNotFound = errors.New("memTotal field not found in /proc/meminfo")
	// ErrNoCPUMHzFound indicates that no cpu MHz entries were found in /proc/cpuinfo.
	ErrNoCPUMHzFound = errors.New("no 'cpu MHz' entries found in /proc/cpuinfo")
)
View Source
var ErrNoCPULine = errors.New("cpu line not found in /proc/stat")

ErrNoCPULine indicates that the aggregate cpu line could not be found in /proc/stat.

Functions

func GetCPUFreqMHz

func GetCPUFreqMHz() (float64, error)

GetCPUFreqMHz reads the aggregate CPU frequency in MHz across all active CPU cores listed in /proc/cpuinfo.

func GetTotalMemoryMB

func GetTotalMemoryMB() (uint64, error)

GetTotalMemoryMB reads /proc/meminfo from the host procfs and returns total physical system memory converted from KiB to MiB.

func PersistPosition

func PersistPosition(lat, lon float64) error

PersistPosition stores a live position fix into the node config so the next boot publishes it. The file is storage, not an interface: live updates arrive over IPC and call this; nothing polls the file back. Load-modify-write preserves anchors, the anchor flag, and identity.

Types

type AnchorEntry

type AnchorEntry struct {
	// Name labels the anchor for operators (depot, rim-mast). Unused by code.
	Name string         `json:"name,omitempty"`
	Addr netip.AddrPort `json:"address"`
	Lat  float64        `json:"lat"`
	Lon  float64        `json:"lon"`
}

AnchorEntry is one rendezvous anchor: a stable reachable address plus the coordinates that order it against the others.

func (AnchorEntry) AnchorPoint

func (a AnchorEntry) AnchorPoint() (geo.Point, bool)

AnchorPoint returns the entry's coordinates, or false when they are outside the planet and must not order anything.

type HostPressure

type HostPressure struct {
	CPU  uint8
	Mem  uint8
	Disk uint8
}

HostPressure holds node utilization as 0-100 percents.

type LogLine

type LogLine struct {
	At     time.Time
	Stream string
	Text   string
}

LogLine is one timestamped output line with its stream.

type LogRing

type LogRing struct {
	// contains filtered or unexported fields
}

LogRing is a fixed-size round-robin of output lines: appends overwrite the oldest once full. Self-locked: container IO goroutines write while the reconciler and IPC handlers read. Use lines() for snapshots; follow-style polling compares At against the last printed line.

func (*LogRing) Write

func (r *LogRing) Write(p []byte) (int, error)

Write appends bytes, flushing complete newline-terminated lines into the ring. Partial lines wait in pending for the next write; a stream that never terminates its last line keeps it pending, never loses it.

type NodeConfig

type NodeConfig struct {
	// MemberlistAddress is the local bind address for gossip.
	MemberlistAddress netip.AddrPort `json:"memberlist_address"`
	// AdvertiseAddress is an optional IP other peers should dial. The port
	// always comes from MemberlistAddress (bind). Empty means the runtime
	// picks one from the bind address or a non-loopback interface.
	AdvertiseAddress netip.Addr `json:"advertise_address"`
	ID               uuid.UUID  `json:"id"`
	// Anchor marks this node as a rendezvous anchor: stable, reachable,
	// and safe for newcomers to join. Provisioned with concord --anchor.
	Anchor bool `json:"anchor,omitempty"`
	// Position is this node's geographic position, or nil when unknown.
	// Anchors use it to order nearest-first; without it the anchor list
	// order decides. Operator-provisioned; anchors are stationary so
	// theirs never goes stale.
	Position *geo.Point `json:"position,omitempty"`
	// Anchors are rendezvous addresses tried in order (nearest first when
	// Position is known). Empty means LAN-only discovery via mDNS.
	Anchors []AnchorEntry `json:"anchors,omitempty"`
}

func LoadOrCreateNodeConfig

func LoadOrCreateNodeConfig() (config *NodeConfig, err error)

LoadOrCreateNodeConfig creates or loads the config for this node. The path is auto-determined, you cannot specify it. In practice configuration directory of the user gets used.

func UpdateNodeConfig

func UpdateNodeConfig(config *NodeConfig) (_ *NodeConfig, err error)

UpdateNodeConfig returns a pointer to the written result if the update was successful, otherwise it returns an error.

type Sampler

type Sampler struct {
	// contains filtered or unexported fields
}

Sampler turns cumulative host and cgroup counters into percents. It keeps the previous readings, so the first sample of anything reports CPU 0 and only later samples carry deltas. It is safe for concurrent use: the fast beat writes while inspection endpoints read.

func NewSampler

func NewSampler() *Sampler

NewSampler creates an empty pressure sampler.

func (*Sampler) CaptureTrend

func (s *Sampler) CaptureTrend()

CaptureTrend appends the latest readings to their trend series. Call it on a slow beat, not per sample: history is trend context at 5s granularity while latest values stay on the fast beat.

func (*Sampler) DropWorkload

func (s *Sampler) DropWorkload(id uuid.UUID)

DropWorkload forgets a workload's counters, latest sample, trend, and logs.

func (*Sampler) LastHost

func (s *Sampler) LastHost() HostPressure

LastHost returns the most recently sampled trio, or zeros before the first sample.

func (*Sampler) LastPosition

func (s *Sampler) LastPosition() *geo.Point

LastPosition returns the latest valid position fix, or nil when none was ever recorded. Freshest fix, not trail-gated.

func (*Sampler) LogLines

func (s *Sampler) LogLines(id uuid.UUID) []LogLine

LogLines returns one workload's stdout and stderr lines merged oldest-first. Unknown ids report nothing.

func (*Sampler) LogWriter

func (s *Sampler) LogWriter(id uuid.UUID, stream string) io.Writer

LogWriter returns the ring writer for one workload's stream, creating the workload's rings on first use. Safe to hand to container IO goroutines; lines land timestamped and bounded.

func (*Sampler) RecordPosition

func (s *Sampler) RecordPosition(pos geo.Point)

RecordPosition appends to the position trail when the node moved at least trailMoveKM since the last recorded point. The first valid position always records. Invalid positions never record, and neither does the exact zero point: zeros mean unknown across gossip, gauges, and node list, so recording them would plant a Null Island waypoint no node ever visited. Gated points land in the ring and the track log together, so the file always holds everything the ring does and more.

func (*Sampler) SampleHost

func (s *Sampler) SampleHost() (HostPressure, error)

SampleHost reads /proc/stat, /proc/meminfo, and disk usage, and returns the node trio. The first call establishes the CPU baseline and reports CPU 0; memory and disk report immediately.

func (*Sampler) SampleWorkload

func (s *Sampler) SampleWorkload(id uuid.UUID, cpuTotal, memUsageBytes, memLimitBytes uint64, now time.Time) WorkloadSample

SampleWorkload records cumulative cgroup counters for one workload and returns its utilization. cpuTotal is nanoseconds of CPU consumed, memUsageBytes and memLimitBytes come from cgroup memory stats and the spec. The first call for an id reports CPU 0. A counter going backwards (cgroup recreated) also reports 0 instead of wrapping.

func (*Sampler) SetTrackLog

func (s *Sampler) SetTrackLog(t *TrackLog)

SetTrackLog attaches the durable trail sink. Nil detaches.

func (*Sampler) Trail

func (s *Sampler) Trail() []trailPoint

Trail returns the recorded positions oldest-first.

func (*Sampler) Trend

func (s *Sampler) Trend(id uuid.UUID) (cpu, mem uint8, n int)

Trend folds a workload's series into mean CPU and memory percents plus the samples folded. Unknown ids report zeros.

func (*Sampler) Workloads

func (s *Sampler) Workloads() map[uuid.UUID]WorkloadSample

Workloads returns a copy of the latest per-workload samples.

type TrackLog

type TrackLog struct {
	// contains filtered or unexported fields
}

TrackLog is the durable position trail: an append-only local file holding every gated trail point oldest-first. It is the full history the in-memory 720-point ring cannot keep: restarts and ring overwrite lose nothing here. Node-local only, never synced, never in the journal, in the same tradition as journal.jsonl: operators grep it, nothing converges on it. Rotation and archival are operator-owned, same as the journal.

func OpenTrackLog

func OpenTrackLog() (*TrackLog, error)

OpenTrackLog opens (creating when absent) the local track log for appends.

func (*TrackLog) Append

func (t *TrackLog) Append(at time.Time, lat, lon float64) error

Append writes one trail point as a single JSON line and fsyncs before return, so a crash keeps everything up to the last recorded move. One write per 10m move is journal-scale traffic, not a hot path.

func (*TrackLog) Close

func (t *TrackLog) Close() error

Close releases the track log file.

type WorkloadSample

type WorkloadSample struct {
	CPUPercent uint8
	MemPercent uint8
	MemUsageMB uint64
}

WorkloadSample holds per-workload utilization. MemPercent is 0 when the workload has no memory limit; MemUsageMB always reports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL