Documentation ¶
Index ¶
- Variables
- func ExtractContainerRateMetric(containers []*containers.Container) map[string]ContainerRateMetrics
- func GetContainers() ([]*containers.Container, error)
- func GetCurrentIno() (uint32, error)
- func GetDockerSocketPath() (string, error)
- func GetEnv(key string, dfault string, combineWith ...string) string
- func GetInoForNs(ns netns.NsHandle) (uint32, error)
- func GetNetNamespaceFromPid(procRoot string, pid int) (netns.NsHandle, error)
- func GetNetNamespaces(procRoot string) ([]netns.NsHandle, error)
- func GetNetNsInoFromPid(procRoot string, pid int) (uint32, error)
- func GetProcRoot() string
- func GetRootNSPID() (int, error)
- func GetRootNetNamespace(procRoot string) (netns.NsHandle, error)
- func GetSysRoot() string
- func HandleSignals(exit chan struct{})
- func HostProc(combineWith ...string) string
- func HostSys(combineWith ...string) string
- func NetIPFromAddress(addr Address, buf []byte) net.IP
- func PathExists(filename string) bool
- func ReadLines(filename string) ([]string, error)
- func SetContainerSources(names []string)
- func StringInSlice(slice []string, searchString string) bool
- func ToLowHigh(addr Address) (l, h uint64)
- func WithAllProcs(procRoot string, fn func(int) error) error
- func WithNS(procRoot string, ns netns.NsHandle, fn func() error) error
- func WithRootNS(procRoot string, fn func() error) error
- type Address
- type ContainerRateMetrics
- type LogLimit
- type SSBytes
Constants ¶
This section is empty.
Variables ¶
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.
var IPBufferPool = sync.Pool{ New: func() interface{} { return make([]byte, net.IPv6len) }, }
IPBufferPool is meant to be used in conjunction with `NetIPFromAddress`
var NullContainerRates = ContainerRateMetrics{ CPU: &metrics.ContainerCPUStats{ User: -1, System: -1, Shares: -1, }, IO: &metrics.ContainerIOStats{}, NetworkSum: &metrics.InterfaceNetStats{}, Network: metrics.ContainerNetStats{}, }
NullContainerRates can be safely used for containers that have no previous 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 GetCurrentIno ¶
GetCurrentIno returns the ino number for the current network namespace
func GetDockerSocketPath ¶
GetDockerSocketPath is only for exposing the sockpath out of the module
func GetEnv ¶
GetEnv retrieves the environment variable key. If it does not exist it returns the default.
func GetInoForNs ¶
GetInoForNs gets the inode number for the given network namespace
func GetNetNamespaceFromPid ¶
GetNetNamespaceFromPid gets the network namespace for a given `pid`
func GetNetNamespaces ¶
GetNetNamespaces returns a list of network namespaces on the machine. The caller is responsible for calling Close() on each of the returned NsHandle's.
func GetNetNsInoFromPid ¶
GetNetNsInoFromPid gets the network namespace inode number for the given `pid`
func GetProcRoot ¶
func GetProcRoot() string
GetProcRoot retrieves the current procfs dir we should use
func GetRootNSPID ¶
GetRootNSPID returns the current PID from the root namespace
func GetRootNetNamespace ¶
GetRootNetNamespace gets the root network namespace
func HandleSignals ¶
func HandleSignals(exit chan struct{})
HandleSignals tells us whether we should exit.
func HostProc ¶
HostProc returns the location of a host's procfs. This can and will be overridden when running inside a container.
func HostSys ¶
HostSys returns the location of a host's /sys. This can and will be overridden when running inside a container.
func NetIPFromAddress ¶
NetIPFromAddress returns a net.IP from an Address
func PathExists ¶
PathExists returns a boolean indicating if the given path exists on the file system.
func SetContainerSources ¶
func SetContainerSources(names []string)
SetContainerSources allows config to force one or multiple container sources
func StringInSlice ¶
StringInSlice returns true if the given searchString is in the given slice, false otherwise.
func WithAllProcs ¶
WithAllProcs will execute `fn` for every pid under procRoot. `fn` is passed the `pid`. If `fn` returns an error the iteration aborts, returning the last error returned from `fn`.
func WithNS ¶
WithNS executes the given function in the given network namespace, and then switches back to the previous namespace.
func WithRootNS ¶
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 ¶
Address is an IP abstraction that is family (v4/v6) agnostic
func AddressFromNetIP ¶
AddressFromNetIP returns an Address from a provided net.IP
func AddressFromString ¶
AddressFromString creates an Address using the string representation of an v4 IP
func V4AddressFromBytes ¶
V4AddressFromBytes creates an Address using the byte representation of an v4 IP
func V6AddressFromBytes ¶
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 ¶
NewLogLimit creates a LogLimit where shouldLog will return true the first N times it is called, and will return true once every interval thereafter.