resource

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

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

func GetHighestSeverityResourceStatusFromAlerts

func GetHighestSeverityResourceStatusFromAlerts(resource string, alerts []v1alpha1.ResourceAlertRule) (v1alpha1.DeviceResourceStatusType, string)

GetHighestSeverityResourceStatusFromAlerts returns the highest severity statusDeviceResourceStatusType from a list of alerts along with the alert message. The alert message is auto generated if the alert description is empty.

Types

type Alert

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

func NewAlert

func NewAlert(rule v1alpha1.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 v1alpha1.ResourceAlertRule) error

UpdateRule updates the alert rule and duration.

type AlertSeverity

type AlertSeverity struct {
	Status v1alpha1.DeviceResourceStatusType
	Level  int
}

type Alerts

type Alerts struct {
	DiskUsage   []v1alpha1.ResourceAlertRule
	CPUUsage    []v1alpha1.ResourceAlertRule
	MemoryUsage []v1alpha1.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() []v1alpha1.ResourceAlertRule

func (*CPUMonitor) CollectUsage

func (m *CPUMonitor) CollectUsage(ctx context.Context, usage *CPUUsage) error

func (*CPUMonitor) Run

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

func (*CPUMonitor) Update

func (m *CPUMonitor) Update(monitor *v1alpha1.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) Error

func (u *CPUUsage) Error() error

type Controller

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

func NewController

func NewController(
	log *log.PrefixLogger,
	manager Manager,
) *Controller

func (*Controller) Sync

func (c *Controller) Sync(ctx context.Context, desired *v1alpha1.RenderedDeviceSpec) 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() []v1alpha1.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 *v1alpha1.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 *v1alpha1.ResourceMonitor) (bool, error)
	// ResetAlertDefaults clears all alerts and resets the monitors to their default state.
	ResetAlertDefaults() error
	Alerts() *Alerts
}

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 (*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 *v1alpha1.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 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) EXPECT

func (m *MockManager) EXPECT() *MockManagerMockRecorder

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

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) Update

func (m *MockManager) Update(monitor *v1alpha1.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) 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) 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() []v1alpha1.ResourceAlertRule

Alerts mocks base method.

func (*MockMonitor[T]) CollectUsage

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

CollectUsage 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 *v1alpha1.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]) CollectUsage

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

CollectUsage indicates an expected call of CollectUsage.

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 *v1alpha1.ResourceMonitor) (bool, error)
	CollectUsage(ctx context.Context, usage *T) error
	Alerts() []v1alpha1.ResourceAlertRule
}

type MonitorSpec

type MonitorSpec struct {
	v1alpha1.ResourceMonitorSpec

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

MonitorSpec is a wrapper around v1alpha1.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) ResetAlertDefaults

func (m *ResourceManager) ResetAlertDefaults() error

func (*ResourceManager) Run

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

func (*ResourceManager) Update

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

Jump to

Keyboard shortcuts

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