process

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0 Package process provides all the tools and functionality for sampling processes. It is divided in three main components: - Snapshot: provides OS-level information of a process at a given spot - Harvester: manages process Snapshots to create actual Process Samples with the actual metrics. - Sampler: uses the harvester to coordinate the creation of the Process Samples dataset, as being reported to NR

Package process provides all the tools and functionality for sampling processes. It is divided in three main components: - Snapshot: provides OS-level information of a process at a given spot - Harvester: manages process Snapshots to create actual Process Samples with the actual metrics. - Sampler: uses the harvester to coordinate the creation of the Process Samples dataset, as being reported to NR

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProcessSampler

func NewProcessSampler(ctx agent.AgentContext) sampler.Sampler

NewProcessSampler creates and returns a new process Sampler, given an agent context.

Types

type CPUInfo

type CPUInfo struct {
	// Percent is the total CPU usage percent
	Percent float64
	// User is the CPU user time
	User float64
	// System is the CPU system time
	System float64
}

CPUInfo represents CPU usage statistics at a given point

type Harvester

type Harvester interface {
	// Pids return the IDs of all the processes that are currently running
	Pids() ([]int32, error)
	// Do performs the actual harvesting operation, returning a process sample containing all the metrics data
	// for the last elapsedSeconds
	Do(pid int32, elapsedSeconds float64) (*types.ProcessSample, error)
}

Harvester manages sampling for individual processes. It is used by the Process Sampler to get information about the existing processes.

type Process

type Process interface {
	Username() (string, error)
	Name() (string, error)
	Cmdline() (string, error)
	ProcessId() int32
	Parent() (Process, error)
	NumThreads() (int32, error)
	Status() ([]string, error)
	MemoryInfo() (*process.MemoryInfoStat, error)
	CPUPercent() (float64, error)
	Times() (*cpu.TimesStat, error)
}

Process it's an interface to abstract gopsutil process so we can mock it and test not coupling to infra

type ProcessWrapper

type ProcessWrapper struct {
	*process.Process
}

ProcessWrapper is necessary to implement the interface as gopsutil process is not exporting Pid()

func (*ProcessWrapper) Parent

func (p *ProcessWrapper) Parent() (Process, error)

Parent return the process' parent

func (*ProcessWrapper) ProcessId

func (p *ProcessWrapper) ProcessId() int32

ProcessId returns the Pid of the process

type Snapshot

type Snapshot interface {
	// Pid returns the Process ID
	Pid() int32
	// Ppid returns the Parent Process ID
	Ppid() int32
	// Status returns the state of the process: R (running or runnable), D (uninterruptible sleep), S (interruptible
	// sleep), Z (defunct/zombie) or T (stopped)
	Status() string
	// Command returns the process Command name
	Command() string
	// CmdLine returns the process invoking command line, with or without arguments
	CmdLine(withArgs bool) (string, error)
	// Username returns the name of the process owner user
	Username() (string, error)
	// CPUTimes returns the CPU consumption percentages for the process
	CPUTimes() (CPUInfo, error)
	// IOCounters returns the I/O statistics for the process
	IOCounters() (*process.IOCountersStat, error)
	// NumThreads returns the number of threads that are being used by the process
	NumThreads() int32
	// NumFDs returns the number of File Descriptors that are open by the process
	NumFDs() (int32, error)
	// VmRSS returns the Resident Set Size (memory in RAM) of the process
	VmRSS() int64
	// VmSize returns the total memory of the process (RSS + virtual memory)
	VmSize() int64
}

Snapshot represents the status of a process at a given time. Instances of Snapshot must not be reused for different samples

Jump to

Keyboard shortcuts

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