procspy

package
v7.0.6+incompatible Latest Latest
Warning

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

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

Documentation

Overview

Package procspy lists TCP connections, and optionally tries to find the owning processes. Works on Linux (via /proc) and Darwin (via `lsof -i` and `netstat`). You'll need root to use Processes().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadDirNames

func ReadDirNames(path string) ([]string, error)

func ReadNetnsFromPID

func ReadNetnsFromPID(procRoot string, pid int) (uint64, error)

ReadNetnsFromPID gets the netns inode of the specified pid

func ReadTCPFiles

func ReadTCPFiles(procRoot string, pid int, buf *bytes.Buffer) (int64, error)

ReadTCPFiles reads the proc files tcp and tcp6 for a pid

Types

type CachingWalker

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

CachingWalker is a walker than caches a copy of the output from another Walker, and then allows other concurrent readers to Walk that copy.

func NewCachingWalker

func NewCachingWalker(source Walker) *CachingWalker

NewCachingWalker returns a new CachingWalker

func (*CachingWalker) Name

func (*CachingWalker) Name() string

Name of this ticker, for metrics gathering

func (*CachingWalker) Tick

func (c *CachingWalker) Tick() error

Tick updates cached copy of process list

func (*CachingWalker) Walk

func (c *CachingWalker) Walk(f func(Process, Process)) error

Walk walks a cached copy of process list

type ConnIter

type ConnIter interface {
	Next() *Connection
}

ConnIter is returned by Connections().

type Connection

type Connection struct {
	LocalAddress  net.IP
	LocalPort     uint16
	RemoteAddress net.IP
	RemotePort    uint16
	Inode         uint64
	Proc          Proc
	Listening     bool
}

Connection is a (TCP) connection. The Proc struct might not be filled in.

type ConnectionScanner

type ConnectionScanner interface {
	// Connections returns all established (TCP) connections.
	Connections() (ConnIter, error)
	// Stops the scanning
	Stop()
}

ConnectionScanner scans the system for established (TCP) connections

func NewConnectionScanner

func NewConnectionScanner(walker Walker, procRoot string, processes bool) ConnectionScanner

NewConnectionScanner creates a new Linux ConnectionScanner

func NewSyncConnectionScanner

func NewSyncConnectionScanner(walker Walker, procRoot string, processes bool) ConnectionScanner

NewSyncConnectionScanner creates a new synchronous Linux ConnectionScanner

type Proc

type Proc struct {
	PID            uint
	NetNamespaceID uint64
}

Proc is a single process with PID and process name.

type ProcNet

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

ProcNet is an iterator to parse /proc/net/tcp{,6} files.

func NewProcNet

func NewProcNet(b []byte) *ProcNet

NewProcNet gives a new ProcNet parser.

func (*ProcNet) Next

func (p *ProcNet) Next() *Connection

Next returns the next connection. All buffers are re-used, so if you want to keep the IPs you have to copy them.

type Process

type Process struct {
	PID int
}

Process represents a single process.

type Walker

type Walker interface {
	Walk(func(Process, Process)) error
}

Walker is something that walks the /proc directory

func NewWalker

func NewWalker(procRoot string) Walker

NewWalker creates a new process Walker.

Jump to

Keyboard shortcuts

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