resource

package
v1.3.2-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 18 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 resource is a generated GoMock package.

Index

Constants

View Source
const (
	DefaultCPUSyncTimeout = 5 * time.Second
	DefaultProcStatPath   = "/proc/stat"
)
View Source
const (
	DefaultMemorySyncTimeout = 5 * time.Second
	DefaultProcMemInfoPath   = "/proc/meminfo"
)
View Source
const (
	CPUMonitorType    = "CPU"
	DiskMonitorType   = "Disk"
	MemoryMonitorType = "Memory"

	DefaultSamplingInterval = 1 * time.Minute
)
View Source
const (
	DefaultDiskSyncTimeout = 5 * time.Second
)

Variables

Functions

This section is empty.

Types

type Alert

type Alert struct {
	v1beta1.ResourceAlertRule
	// contains filtered or unexported fields
}

func NewAlert

func NewAlert(rule v1beta1.ResourceAlertRule) (*Alert, error)

func (*Alert) IsFiring

func (a *Alert) IsFiring() bool

func (*Alert) Sync

func (a *Alert) Sync(usagePercentage int64)

func (*Alert) UpdateRule

func (a *Alert) UpdateRule(rule v1beta1.ResourceAlertRule) error

UpdateRule updates the alert rule and duration.

type AlertSeverity

type AlertSeverity struct {
	Status v1beta1.DeviceResourceStatusType
	Level  int
}

type Alerts

type Alerts struct {
	DiskUsage   []v1beta1.ResourceAlertRule
	CPUUsage    []v1beta1.ResourceAlertRule
	MemoryUsage []v1beta1.ResourceAlertRule
}

type CPUMonitor

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

func NewCPUMonitor

func NewCPUMonitor(
	log *log.PrefixLogger,
) *CPUMonitor

func (*CPUMonitor) Alerts

func (m *CPUMonitor) Alerts() []v1beta1.ResourceAlertRule

func (*CPUMonitor) Run

func (m *CPUMonitor) Run(ctx context.Context)

func (*CPUMonitor) Update

func (m *CPUMonitor) Update(monitor *v1beta1.ResourceMonitor) (bool, error)

type CPUUsage

type CPUUsage struct {
	// CPU // 0 skipped
	User      float64 // 1
	Nice      float64 // 2
	System    float64 // 3
	Idle      float64 // 4
	Iowait    float64 // 5
	Irq       float64 // 6
	Softirq   float64 // 7
	Steal     float64 // 8
	Guest     float64 // 9
	GuestNice float64 // 10

	UsedPercent int64
	// contains filtered or unexported fields
}

CPUUsage represents the tracked CPU usage of this device.

func (*CPUUsage) ActiveTime added in v0.6.0

func (u *CPUUsage) ActiveTime() float64

func (*CPUUsage) Error

func (u *CPUUsage) Error() error

func (*CPUUsage) TotalTime added in v0.6.0

func (u *CPUUsage) TotalTime() float64

type Collector added in v0.6.0

type Collector[T any] interface {
	CollectUsage(ctx context.Context, usage *T) error
}

type DiskMonitor

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

func NewDiskMonitor

func NewDiskMonitor(
	log *log.PrefixLogger,
) *DiskMonitor

func (*DiskMonitor) Alerts

func (m *DiskMonitor) Alerts() []v1beta1.ResourceAlertRule

func (*DiskMonitor) CollectUsage

func (m *DiskMonitor) CollectUsage(ctx context.Context, usage *DiskUsage) error

func (*DiskMonitor) Run

func (m *DiskMonitor) Run(ctx context.Context)

func (*DiskMonitor) Update

func (m *DiskMonitor) Update(monitor *v1beta1.ResourceMonitor) (bool, error)

type DiskUsage

type DiskUsage struct {
	Inodes      uint64
	Total       uint64
	Free        uint64
	Used        uint64
	UsedPercent int64
	// contains filtered or unexported fields
}

DiskUsage represents the tracked Disk usage of this device.

type Manager

type Manager interface {
	Run(ctx context.Context)
	Update(monitor *v1beta1.ResourceMonitor) (bool, error)
	// ResetAlertDefaults clears all alerts and resets the monitors to their default state.
	ResetAlertDefaults() error
	Alerts() *Alerts
	BeforeUpdate(ctx context.Context, desired *v1beta1.DeviceSpec) error
	IsCriticalAlert(monitorType MonitorType) bool
	status.Exporter
}

func NewManager

func NewManager(
	log *log.PrefixLogger,
) Manager

NewManager creates a new resource Manager.

type MemoryMonitor

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

func NewMemoryMonitor

func NewMemoryMonitor(
	log *log.PrefixLogger,
) *MemoryMonitor

func (*MemoryMonitor) Alerts

func (m *MemoryMonitor) Alerts() []v1beta1.ResourceAlertRule

func (*MemoryMonitor) CollectUsage

func (m *MemoryMonitor) CollectUsage(ctx context.Context, usage *MemoryUsage) error

func (*MemoryMonitor) Run

func (m *MemoryMonitor) Run(ctx context.Context)

func (*MemoryMonitor) Update

func (m *MemoryMonitor) Update(monitor *v1beta1.ResourceMonitor) (bool, error)

type MemoryUsage

type MemoryUsage struct {
	MemTotal     uint64
	MemFree      uint64
	Buffers      uint64
	Cached       uint64
	SReclaimable uint64
	Shmem        uint64

	UsedPercent int64
	// contains filtered or unexported fields
}

MemoryUsage represents the memory usage of this device

type MockCollector added in v0.6.0

type MockCollector[T any] struct {
	// contains filtered or unexported fields
}

MockCollector is a mock of Collector interface.

func NewMockCollector added in v0.6.0

func NewMockCollector[T any](ctrl *gomock.Controller) *MockCollector[T]

NewMockCollector creates a new mock instance.

func (*MockCollector[T]) CollectUsage added in v0.6.0

func (m *MockCollector[T]) CollectUsage(ctx context.Context, usage *T) error

CollectUsage mocks base method.

func (*MockCollector[T]) EXPECT added in v0.6.0

func (m *MockCollector[T]) EXPECT() *MockCollectorMockRecorder[T]

EXPECT returns an object that allows the caller to indicate expected use.

type MockCollectorMockRecorder added in v0.6.0

type MockCollectorMockRecorder[T any] struct {
	// contains filtered or unexported fields
}

MockCollectorMockRecorder is the mock recorder for MockCollector.

func (*MockCollectorMockRecorder[T]) CollectUsage added in v0.6.0

func (mr *MockCollectorMockRecorder[T]) CollectUsage(ctx, usage any) *gomock.Call

CollectUsage indicates an expected call of CollectUsage.

type MockManager

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

MockManager is a mock of Manager interface.

func NewMockManager

func NewMockManager(ctrl *gomock.Controller) *MockManager

NewMockManager creates a new mock instance.

func (*MockManager) Alerts

func (m *MockManager) Alerts() *Alerts

Alerts mocks base method.

func (*MockManager) BeforeUpdate added in v1.0.0

func (m *MockManager) BeforeUpdate(ctx context.Context, desired *v1beta1.DeviceSpec) error

BeforeUpdate mocks base method.

func (*MockManager) EXPECT

func (m *MockManager) EXPECT() *MockManagerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockManager) IsCriticalAlert added in v1.0.0

func (m *MockManager) IsCriticalAlert(monitorType MonitorType) bool

IsCriticalAlert mocks base method.

func (*MockManager) ResetAlertDefaults

func (m *MockManager) ResetAlertDefaults() error

ResetAlertDefaults mocks base method.

func (*MockManager) Run

func (m *MockManager) Run(ctx context.Context)

Run mocks base method.

func (*MockManager) Status added in v0.4.0

func (m *MockManager) Status(arg0 context.Context, arg1 *v1beta1.DeviceStatus, arg2 ...status.CollectorOpt) error

Status mocks base method.

func (*MockManager) Update

func (m *MockManager) Update(monitor *v1beta1.ResourceMonitor) (bool, error)

Update mocks base method.

type MockManagerMockRecorder

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

MockManagerMockRecorder is the mock recorder for MockManager.

func (*MockManagerMockRecorder) Alerts

func (mr *MockManagerMockRecorder) Alerts() *gomock.Call

Alerts indicates an expected call of Alerts.

func (*MockManagerMockRecorder) BeforeUpdate added in v1.0.0

func (mr *MockManagerMockRecorder) BeforeUpdate(ctx, desired any) *gomock.Call

BeforeUpdate indicates an expected call of BeforeUpdate.

func (*MockManagerMockRecorder) IsCriticalAlert added in v1.0.0

func (mr *MockManagerMockRecorder) IsCriticalAlert(monitorType any) *gomock.Call

IsCriticalAlert indicates an expected call of IsCriticalAlert.

func (*MockManagerMockRecorder) ResetAlertDefaults

func (mr *MockManagerMockRecorder) ResetAlertDefaults() *gomock.Call

ResetAlertDefaults indicates an expected call of ResetAlertDefaults.

func (*MockManagerMockRecorder) Run

func (mr *MockManagerMockRecorder) Run(ctx any) *gomock.Call

Run indicates an expected call of Run.

func (*MockManagerMockRecorder) Status added in v0.4.0

func (mr *MockManagerMockRecorder) Status(arg0, arg1 any, arg2 ...any) *gomock.Call

Status indicates an expected call of Status.

func (*MockManagerMockRecorder) Update

func (mr *MockManagerMockRecorder) Update(monitor any) *gomock.Call

Update indicates an expected call of Update.

type MockMonitor

type MockMonitor[T any] struct {
	// contains filtered or unexported fields
}

MockMonitor is a mock of Monitor interface.

func NewMockMonitor

func NewMockMonitor[T any](ctrl *gomock.Controller) *MockMonitor[T]

NewMockMonitor creates a new mock instance.

func (*MockMonitor[T]) Alerts

func (m *MockMonitor[T]) Alerts() []v1beta1.ResourceAlertRule

Alerts mocks base method.

func (*MockMonitor[T]) EXPECT

func (m *MockMonitor[T]) EXPECT() *MockMonitorMockRecorder[T]

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMonitor[T]) Run

func (m *MockMonitor[T]) Run(ctx context.Context)

Run mocks base method.

func (*MockMonitor[T]) Update

func (m *MockMonitor[T]) Update(monitor *v1beta1.ResourceMonitor) (bool, error)

Update mocks base method.

type MockMonitorMockRecorder

type MockMonitorMockRecorder[T any] struct {
	// contains filtered or unexported fields
}

MockMonitorMockRecorder is the mock recorder for MockMonitor.

func (*MockMonitorMockRecorder[T]) Alerts

func (mr *MockMonitorMockRecorder[T]) Alerts() *gomock.Call

Alerts indicates an expected call of Alerts.

func (*MockMonitorMockRecorder[T]) Run

func (mr *MockMonitorMockRecorder[T]) Run(ctx any) *gomock.Call

Run indicates an expected call of Run.

func (*MockMonitorMockRecorder[T]) Update

func (mr *MockMonitorMockRecorder[T]) Update(monitor any) *gomock.Call

Update indicates an expected call of Update.

type Monitor

type Monitor[T any] interface {
	Run(ctx context.Context)
	Update(monitor *v1beta1.ResourceMonitor) (bool, error)
	Alerts() []v1beta1.ResourceAlertRule
}

type MonitorSpec

type MonitorSpec struct {
	v1beta1.ResourceMonitorSpec

	// Path is the absolute path used for the disk monitor.
	Path string `json:"path,omitempty"`
}

MonitorSpec is a wrapper around v1beta1.ResourceMonitorSpec that includes additional fields for all monitors.

type MonitorType

type MonitorType string

type ResourceManager

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

func (*ResourceManager) Alerts

func (m *ResourceManager) Alerts() *Alerts

func (*ResourceManager) BeforeUpdate added in v1.0.0

func (m *ResourceManager) BeforeUpdate(ctx context.Context, desired *v1beta1.DeviceSpec) error

BeforeUpdate syncs resource monitors with the desired spec.

func (*ResourceManager) IsCriticalAlert added in v1.0.0

func (m *ResourceManager) IsCriticalAlert(monitorType MonitorType) bool

IsCriticalAlert checks if there is a critical level alert for the specified resource type.

func (*ResourceManager) ResetAlertDefaults

func (m *ResourceManager) ResetAlertDefaults() error

func (*ResourceManager) Run

func (m *ResourceManager) Run(ctx context.Context)

func (*ResourceManager) Status added in v0.4.0

Status returns the device status based on the resource monitors and for the device summary.

func (*ResourceManager) Update

func (m *ResourceManager) Update(monitor *v1beta1.ResourceMonitor) (bool, error)

Jump to

Keyboard shortcuts

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