util

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: Apache-2.0 Imports: 24 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("not implemented yet")

ErrNotImplemented is the "not implemented" error given by `gopsutil` when an OS doesn't support and API. Unfortunately it's in an internal package so we can't import it so we'll copy it here.

View Source
var NullContainerRates = ContainerRateMetrics{
	CPU:        &metrics.ContainerCPUStats{},
	IO:         &metrics.ContainerIOStats{},
	NetworkSum: &metrics.InterfaceNetStats{},
	Network:    metrics.ContainerNetStats{},
}

NullContainerRates can be safely used for containers that have no previours rate values stored (new containers)

Functions

func ExtractContainerRateMetric

func ExtractContainerRateMetric(containers []*containers.Container) map[string]ContainerRateMetrics

ExtractContainerRateMetric extracts relevant rate values from a container list for later reuse, while reducing memory usage to only the needed fields

func GetContainers

func GetContainers() ([]*containers.Container, error)

GetContainers returns containers found on the machine GetContainers autodetects the best backend from available sources if the users don't specify the preferred container sources

func GetDockerSocketPath

func GetDockerSocketPath() (string, error)

GetDockerSocketPath is only for exposing the sockpath out of the module

func GetEnv

func GetEnv(key string, dfault string, combineWith ...string) string

GetEnv retrieves the environment variable key. If it does not exist it returns the default.

func GetPlatform

func GetPlatform() (string, error)

GetPlatform returns the current platform we are running on by calling 1. python -m platform 2. "uname -a" 3. "lsb_release -a" 4. reading redhat-release

func GetProcRoot

func GetProcRoot() string

GetProcRoot retrieves the current procfs dir we should use

func HandleSignals

func HandleSignals(exit chan struct{})

HandleSignals tells us whether we should exit.

func HostProc

func HostProc(combineWith ...string) string

HostProc returns the location of a host's procfs. This can and will be overridden when running inside a container.

func HostSys

func HostSys(combineWith ...string) string

HostSys returns the location of a host's /sys. This can and will be overridden when running inside a container.

func IsDebugfsMounted

func IsDebugfsMounted() (bool, string)

IsDebugfsMounted would test the existence of file /sys/kernel/debug/tracing/kprobe_events to determine if debugfs is mounted or not returns a boolean and a possible error message

func NetIPFromAddress

func NetIPFromAddress(addr Address) net.IP

NetIPFromAddress returns a net.IP from an Address

func PathExists

func PathExists(filename string) bool

PathExists returns a boolean indicating if the given path exists on the file system.

func ReadLines

func ReadLines(filename string) ([]string, error)

ReadLines reads contents from a file and splits them by new lines.

func SetContainerSources

func SetContainerSources(names []string)

SetContainerSources allows config to force one or multiple container sources

func StringInSlice

func StringInSlice(slice []string, searchString string) bool

StringInSlice returns true if the given searchString is in the given slice, false otherwise.

func WithRootNS

func WithRootNS(procRoot string, fn func()) error

WithRootNS executes a function within root network namespace and then switch back to the previous namespace. If the thread is already in the root network namespace, the function is executed without calling SYS_SETNS.

Types

type Address

type Address interface {
	Bytes() []byte
	String() string
	IsLoopback() bool
}

Address is an IP abstraction that is family (v4/v6) agnostic

func AddressFromNetIP

func AddressFromNetIP(ip net.IP) Address

AddressFromNetIP returns an Address from a provided net.IP

func AddressFromString

func AddressFromString(ip string) Address

AddressFromString creates an Address using the string representation of an v4 IP

func V4Address

func V4Address(ip uint32) Address

V4Address creates an Address using the uint32 representation of an v4 IP

func V4AddressFromBytes

func V4AddressFromBytes(buf []byte) Address

V4AddressFromBytes creates an Address using the byte representation of an v4 IP

func V6Address

func V6Address(low, high uint64) Address

V6Address creates an Address using the uint128 representation of an v6 IP

func V6AddressFromBytes

func V6AddressFromBytes(buf []byte) Address

V6AddressFromBytes creates an Address using the byte representation of an v6 IP

type ContainerRateMetrics

type ContainerRateMetrics struct {
	CPU        *metrics.ContainerCPUStats
	IO         *metrics.ContainerIOStats
	NetworkSum *metrics.InterfaceNetStats
	Network    metrics.ContainerNetStats
}

ContainerRateMetrics holds previous values for a container, in order to compute rates

type LogLimit

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

LogLimit is a utility that can be used to avoid logging noisily

func NewLogLimit

func NewLogLimit(n int, interval time.Duration) *LogLimit

NewLogLimit creates a LogLimit where shouldLog will return true the first N times it is called, and will return true once every interval thereafter.

func (*LogLimit) Close

func (l *LogLimit) Close()

Close will stop the underlying ticker

func (*LogLimit) ShouldLog

func (l *LogLimit) ShouldLog() bool

ShouldLog returns true if the caller should log

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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