monitoring

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package monitoring contains utilities for gathering data about resource usage in order to monitor client-side resource usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregateResourceUsage

func AggregateResourceUsage(prevRU *ResourceUsage, currRU *ResourceUsage, numRUCalls int, aggRU *mpb.AggregatedResourceUsage, commandFinished bool) error

AggregateResourceUsage is a helper function for aggregating resource-usage data across multiple resource-usage queries. It should be called once, in sequence, for each ResourceUsage result.

'numRUCalls' is the number of resource-usage samples aggregated into one AggregatedResourceUsage proto; it is used to compute mean metrics. 'aggRU' is only updated if no error is encountered.

We don't get memory usage data from finished commands. The commandFinished bool argument makes this function skip memory usage aggregation.

func AggregateResourceUsageForFinishedCmd

func AggregateResourceUsageForFinishedCmd(initialRU, finalRU *ResourceUsage) (*mpb.AggregatedResourceUsage, error)

AggregateResourceUsageForFinishedCmd computes resource-usage for a finished process, given resource-usage before and after the process ran.

func SendProtoToServer

func SendProtoToServer(ctx context.Context, pb proto.Message, msgType string, sc service.Context) error

SendProtoToServer wraps a proto in a fspb.Message and sends it to the server.

Types

type ResourceUsage

type ResourceUsage struct {
	// When the resource-usage data was retrieved.
	Timestamp time.Time

	// Amount of CPU time scheduled for a process so far in user mode.
	UserCPUMillis float64

	// Amount of CPU time scheduled for a process so far in kernel mode.
	SystemCPUMillis float64

	// Resident set size for a process.
	ResidentMemory int64

	// Number of open file descriptors.
	NumFDs int32
}

ResourceUsage contains resource-usage data for a single process.

type ResourceUsageFetcher

type ResourceUsageFetcher struct{}

ResourceUsageFetcher obtains resource-usage data for a process from the OS.

func (ResourceUsageFetcher) DebugStatusForPID

func (f ResourceUsageFetcher) DebugStatusForPID(pid int) (string, error)

DebugStatusForPID returns a string containing extra debug info about resource-usage that may not be captured in ResourceUsage. This is only possible for running processes.

func (ResourceUsageFetcher) ResourceUsageForPID

func (f ResourceUsageFetcher) ResourceUsageForPID(pid int) (*ResourceUsage, error)

ResourceUsageForPID returns a ResourceUsage struct with information from /proc/<PID>/stat and /proc/<PID>/statm . This is only possible with running processes, an error will be returned if the corresponding procfs entry is not present.

func (ResourceUsageFetcher) ResourceUsageFromFinishedCmd

func (f ResourceUsageFetcher) ResourceUsageFromFinishedCmd(cmd *exec.Cmd) *ResourceUsage

ResourceUsageFromFinishedCmd returns a ResourceUsage struct with information from exec.Cmd.ProcessState. NOTE that this is only possible after the process has finished and has been waited for, and will most probably panic otherwise. This function doesn't fill in ResourceUsage.ResidentMemory.

type ResourceUsageMonitor

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

ResourceUsageMonitor computes resource-usage metrics for a process and delivers them periodically via a channel.

func New

New returns a new ResourceUsageMonitor. Once created, it must be started with Run().

func (*ResourceUsageMonitor) Run

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

Run is the business method of the resource-usage monitor. It blocks until ctx is canceled.

type ResourceUsageMonitorParams

type ResourceUsageMonitorParams struct {
	// What we are monitoring. Typically a service name, or 'system' for the
	// Fleetspeak client itself.
	Scope string

	// The version string of the service that we are monitoring, if known.
	Version string

	// The process id that we are monitoring.
	Pid int

	// If nonzero, the monitored process should be killed if it exceeds this
	// memory limit, in bytes.
	MemoryLimit int64

	// The time that the processes was started (if known).
	ProcessStartTime time.Time

	// The longest time to wait between samples.
	MaxSamplePeriod time.Duration

	// The number of resource-usage query results that get aggregated into
	// a single resource-usage report sent to Fleetspeak servers.
	SampleSize int

	// If set, the resource monitor will report errors on this channel. If unset,
	// errors will be logged.
	Err chan<- error
	// contains filtered or unexported fields
}

ResourceUsageMonitorParams contains parameters that might be set when creating a ResourceUsageMonitor.

Jump to

Keyboard shortcuts

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