resource

package
v0.0.0-...-45e10be Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package resource applies resource constraints to processes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(constraint Constraint) error

Apply applies the provided resources constraints to the process specified by the PID and name. If a constraint is missing, then that constraint is simply skipped.

func NewOOMWatcher

func NewOOMWatcher(ctx context.Context, constraint Constraint, interval time.Duration) (events.Watcher, error)

NewOOMWatcher sets a new OOM watcher for the given process. This will trigger events when the process is killed due to OOM.

func RemoveConstraint

func RemoveConstraint(ctx context.Context, name string) error

RemoveConstraint removes and cleans up the resource constraints set by Apply for a given process. The name is the full name of the process. For plugins, this is the value returned by FullName(). The statePath is the path to the state of the process. This is mainly used by the windows implementation for saving the JobObject handles.

Types

type Constraint

type Constraint struct {
	// PID is the PID of the process.
	PID int
	// Name is the name of the process or plugin.
	Name string
	// MaxMemoryUsage is the maximum memory usage of the process, in bytes.
	MaxMemoryUsage int64
	// MaxCPUUsage is the maximum CPU usage of the process.
	MaxCPUUsage int32
}

Constraint is a resource constraint.

type ConstraintClient

type ConstraintClient interface {
	// Apply applies the provided resources constraints to the process specified
	// by the PID and name.
	Apply(constraint Constraint) error
	// RemoveConstraint removes and cleans up the resource constraints set by
	// Apply for a given process.
	RemoveConstraint(ctx context.Context, name string) error
	// NewOOMWatcher initializes a OOM watcher for the given process. On
	// success, it returns the watcher ID that can be used to subscribe the
	// watcher events.
	NewOOMWatcher(ctx context.Context, constraint Constraint, interval time.Duration) (events.Watcher, error)
}

ConstraintClient is the interface for applying resource constraints to processes.

var Client ConstraintClient

Client is the default client for applying resource constraints.

type OOMEvent

type OOMEvent struct {
	// Name is the name of the process killed by OOM killer.
	Name string
	// Timestamp is the time when the OOM event was observed.
	Timestamp time.Time
}

OOMEvent identifies an event triggered when a process is killed due to OOM.

Jump to

Keyboard shortcuts

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