monitor

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: GPL-3.0, LGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package monitor provides event-driven monitoring of Docker containers and systemd services inside them. It complements the poll-based probes in internal/probe by pushing state transitions through channels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DockerEventsArgs

func DockerEventsArgs(clusterName string) []string

DockerEventsArgs returns the docker CLI arguments for streaming container events for the clusters of the given name, of every realm (DockerRealmEventsArgs). Only the actions in dockerActionMap are asked for: every docker exec of the readiness probes would otherwise send exec_create, exec_start and exec_die events to parse and drop.

func DockerRealmEventsArgs

func DockerRealmEventsArgs(realm, clusterName string) []string

DockerRealmEventsArgs is DockerEventsArgs for the cluster of one realm, or of every realm when realm is empty. The daemon requires both label filters to match, so the events of a same-named cluster of another realm do not reach the stream.

func SystemdMonitorArgs

func SystemdMonitorArgs(container docker.ContainerName) []string

SystemdMonitorArgs returns the docker CLI arguments for streaming systemd unit state changes from inside a container. busctl ends with the docker CLI (docker.TiedExecArgs), which Process.Close kills: it would otherwise stay on the node's bus as a monitor until the node stops.

Types

type DockerMonitor

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

DockerMonitor reads a docker events JSON stream and emits Events.

func NewDockerMonitor

func NewDockerMonitor(containerPrefix string) *DockerMonitor

NewDockerMonitor creates a monitor for the given cluster. The container prefix is used to extract short node names from full container names.

func (*DockerMonitor) Run

func (m *DockerMonitor) Run(ctx context.Context, r io.Reader, ch chan<- Event) error

Run reads docker events --format '{{json .}}' from r and sends the events of the cluster's containers to ch (see scanEvents).

type Event

type Event struct {
	Kind      EventKind
	Node      string               // short name: "controller", "worker-0"
	Container docker.ContainerName // full container name
	Unit      string               // systemd unit name (empty for container events)
	Time      time.Time
	Detail    string // human-readable detail (exit code, error message, etc.)
	Err       error  // non-nil for EventMonitorError
}

Event represents a single state change observed by a monitor.

type EventKind

type EventKind string

EventKind identifies the category of a monitored event.

const EventContainerDie EventKind = "container.die"

EventContainerDie indicates a container has exited.

const EventContainerOOM EventKind = "container.oom"

EventContainerOOM indicates a container was killed by the OOM killer.

const EventContainerPause EventKind = "container.pause"

EventContainerPause indicates a container was paused.

const EventContainerStart EventKind = "container.start"

EventContainerStart indicates a container has started.

const EventContainerUnpause EventKind = "container.unpause"

EventContainerUnpause indicates a container was unpaused.

const EventMonitorError EventKind = "monitor.error"

EventMonitorError indicates that a monitor stopped while the watcher runs: it failed to start, its stream failed, or its stream ended. Its events are missing from then on: those of the container it names, or those of every container when it names none (the docker events stream).

const EventUnitActive EventKind = "unit.active"

EventUnitActive indicates a systemd unit reached ActiveState=active.

const EventUnitFailed EventKind = "unit.failed"

EventUnitFailed indicates a systemd unit reached ActiveState=failed.

type NodeTarget

type NodeTarget struct {
	ShortName string
	Container docker.ContainerName
}

NodeTarget identifies a node to monitor.

type SystemdMonitor

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

SystemdMonitor reads busctl monitor output from inside a container and emits Events for systemd unit state changes.

func NewSystemdMonitor

func NewSystemdMonitor(node string, container docker.ContainerName) *SystemdMonitor

NewSystemdMonitor creates a monitor for a single node container.

func (*SystemdMonitor) Run

func (m *SystemdMonitor) Run(ctx context.Context, r io.Reader, ch chan<- Event) error

Run reads busctl monitor --json=short from r and sends the unit state changes it reports to ch (see scanEvents).

type Watcher

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

Watcher monitors a sind cluster for state changes across all nodes. It manages the lifecycle of docker events and per-node systemd monitors, and broadcasts events to subscribers.

func NewRealmWatcher

func NewRealmWatcher(client *docker.Client, realm, containerPrefix, clusterName string) *Watcher

NewRealmWatcher is NewWatcher for the cluster of one realm, or of every realm when realm is empty.

func NewWatcher

func NewWatcher(client *docker.Client, containerPrefix, clusterName string) *Watcher

NewWatcher creates a Watcher for the given cluster. The client starts its long-lived streams (docker events, busctl monitor through docker exec), with the client's docker command (docker.Client.Start). Its docker events stream asks for the events of the clusters of that name in every realm; NewRealmWatcher asks for those of one realm.

func (*Watcher) AddNodes

func (w *Watcher) AddNodes(nodes []NodeTarget)

AddNodes starts systemd monitors for the given nodes. Call this after Start and after the node containers have been created so that systemd state changes can accelerate readiness probing. The monitors run on the context Start was given, until the watcher stops, so that they also serve the waits that follow the caller's own (e.g. for the Slurm daemons). Before a successful Start, AddNodes does nothing.

func (*Watcher) Start

func (w *Watcher) Start(ctx context.Context, nodes []NodeTarget) error

Start begins monitoring. It starts the docker events stream, spawns systemd monitors for each given node, and starts the broadcast loop. Cancel the context to stop all monitors, those AddNodes starts later included.

func (*Watcher) Subscribe

func (w *Watcher) Subscribe() <-chan Event

Subscribe returns a channel that receives a copy of every event. The channel is closed when the Watcher stops. The caller should drain the channel: the broadcast loop drops an event that a full channel has no room for, and for a monitor error, which a subscriber must not miss, the oldest event the channel holds instead.

func (*Watcher) SubscribeTo

func (w *Watcher) SubscribeTo(container docker.ContainerName) <-chan Event

SubscribeTo is Subscribe for the events of one container, or of every container when it is empty. A readiness wait for one node subscribes to its container only: while many nodes boot, the other nodes' events would otherwise fill its buffer and crowd out its own. A subscription to one container also receives the monitor errors of the whole watcher (those without a container), as its container's events are missing after one.

func (*Watcher) Unsubscribe

func (w *Watcher) Unsubscribe(ch <-chan Event)

Unsubscribe removes a previously subscribed channel and closes it.

func (*Watcher) Wait

func (w *Watcher) Wait()

Wait blocks until all monitor goroutines have exited and closes all remaining subscriber channels. Wait and Unsubscribe may run in either order, or at the same time: each takes the watcher's lock and removes the channels it closes, so each channel is closed once.

Jump to

Keyboard shortcuts

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