Documentation
¶
Index ¶
- Constants
- Variables
- func GetCPUFreqMHz() (float64, error)
- func GetTotalMemoryMB() (uint64, error)
- func PersistPosition(lat, lon float64) error
- type AnchorEntry
- type HostPressure
- type LogLine
- type LogRing
- type NodeConfig
- type Sampler
- func (s *Sampler) CaptureTrend()
- func (s *Sampler) DropWorkload(id uuid.UUID)
- func (s *Sampler) LastHost() HostPressure
- func (s *Sampler) LastPosition() *geo.Point
- func (s *Sampler) LogLines(id uuid.UUID) []LogLine
- func (s *Sampler) LogWriter(id uuid.UUID, stream string) io.Writer
- func (s *Sampler) RecordPosition(pos geo.Point)
- func (s *Sampler) SampleHost() (HostPressure, error)
- func (s *Sampler) SampleWorkload(id uuid.UUID, cpuTotal, memUsageBytes, memLimitBytes uint64, now time.Time) WorkloadSample
- func (s *Sampler) SetTrackLog(t *TrackLog)
- func (s *Sampler) Trail() []trailPoint
- func (s *Sampler) Trend(id uuid.UUID) (cpu, mem uint8, n int)
- func (s *Sampler) Workloads() map[uuid.UUID]WorkloadSample
- type TrackLog
- type WorkloadSample
Constants ¶
const ( LogStdout = "stdout" LogStderr = "stderr" )
Log streams name the container file descriptor a line arrived on.
Variables ¶
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") )
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 ¶
GetCPUFreqMHz reads the aggregate CPU frequency in MHz across all active CPU cores listed in /proc/cpuinfo.
func GetTotalMemoryMB ¶
GetTotalMemoryMB reads /proc/meminfo from the host procfs and returns total physical system memory converted from KiB to MiB.
func PersistPosition ¶
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 ¶
HostPressure holds node utilization as 0-100 percents.
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.
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 (*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 ¶
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 ¶
LastPosition returns the latest valid position fix, or nil when none was ever recorded. Freshest fix, not trail-gated.
func (*Sampler) LogLines ¶
LogLines returns one workload's stdout and stderr lines merged oldest-first. Unknown ids report nothing.
func (*Sampler) LogWriter ¶
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 ¶
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 ¶
SetTrackLog attaches the durable trail sink. Nil detaches.
func (*Sampler) Trail ¶
func (s *Sampler) Trail() []trailPoint
Trail returns the recorded positions oldest-first.
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 ¶
OpenTrackLog opens (creating when absent) the local track log for appends.
type WorkloadSample ¶
WorkloadSample holds per-workload utilization. MemPercent is 0 when the workload has no memory limit; MemUsageMB always reports.