store

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoCompress = uint32(1 << iota)
	ZstdCompress
	ZstdCompressWithDict
)
View Source
const (
	CompressModeShift = 0
	CompressModeLen   = 8
	DictOffsetShift   = 8
	DictOffsetLen     = 24
	MaxDictOffset     = 1<<DictOffsetLen - 1
)

Variables

View Source
var (
	CgroupV2MountPoint  = "/sys/fs/cgroup"
	ErrInvalidFormat    = errors.New("cgroups: parsing file with invalid format failed")
	ErrInvalidGroupPath = errors.New("cgroups: invalid group path")
)
View Source
var (
	ErrOutOfRange                   = errors.New("data is out of range")
	ErrIndexCorrupt                 = errors.New("corrupt index")
	ErrDataCorrupt                  = errors.New("corrupt data")
	MinimumFreeSpaceForStore uint64 = 500 * (1 << 20) // 500MB
	ShardTime                       = int64(24 * 60 * 60)
)

Functions

func CollectSampleFromSys

func CollectSampleFromSys(s *Sample, exit *ExitProcess, log *slog.Logger) error

Types

type CPUStat added in v0.1.5

type CPUStat struct {
	UsageUsec     uint64
	UserUsec      uint64
	SystemUsec    uint64
	NrPeriods     uint64
	NrThrottled   uint64
	ThrottledUsec uint64
	NrBursts      uint64
	BurstUsec     uint64
}

type CgoupStat added in v0.1.5

type CgoupStat struct {
	NrDescendants      uint64
	NrDyingDescendants uint64
}

type CgroupFile added in v0.1.5

type CgroupFile int
const (
	CpuStatFile CgroupFile = iota
	MemoryStatFile
	CpuSetCpusFile
	CpuSetCpusEffectiveFile
	CpuSetMemsFileFile
	CpuSetMemsEffectiveFile
	CpuWeightFile
	CpuMaxFile
	MemoryCurrentFile
	MemoryLowFile
	MemoryHighFile
	MemoryMinFile
	MemoryMaxFile
	MemoryPeakFile
	MemorySwapCurrentFile
	MemorySwapMaxFile
	MemoryZswapCurrentFile
	MemoryZswapMaxFile
	MemoryEventsFile
	IoStatFile
	CpuPressureFile
	MemoryPressureFile
	IoPressureFile
)

type CgroupSample added in v0.1.5

type CgroupSample struct {
	Path        string
	Name        string
	Level       int
	Inode       uint64
	Child       map[string]*CgroupSample
	IsNotExist  map[CgroupFile]struct{}
	Controllers string
	CgoupStat
	CPUStat
	MemoryStat
	CpuSetCpus          string
	CpuSetCpusEffective string
	CpuSetMems          string
	CpuSetMemsEffective string
	CpuWeight           uint64
	CpuMax              string
	MemoryCurrent       uint64
	MemoryLow           uint64
	MemoryHigh          uint64
	MemoryMin           uint64
	MemoryMax           uint64
	MemoryPeak          uint64
	SwapCurrent         uint64
	SwapMax             uint64
	ZswapCurrent        uint64
	ZswapMax            uint64
	MemoryEvents
	IOStats        []IOStat
	CpuPressure    PSIStats
	MemoryPressure PSIStats
	IOPressure     PSIStats
}

type ExitProcess added in v0.0.3

type ExitProcess struct {
	sync.Mutex
	Samples map[int]ProcSample
	// contains filtered or unexported fields
}

func NewExitProcess added in v0.0.3

func NewExitProcess(log *slog.Logger) *ExitProcess

func (*ExitProcess) Collect added in v0.0.3

func (e *ExitProcess) Collect()

type IOStat added in v0.1.5

type IOStat struct {
	Major  uint64
	Minor  uint64
	Rbytes uint64
	Wbytes uint64
	Rios   uint64
	Wios   uint64
	Dbytes uint64
	Dios   uint64
}

type Index

type Index struct {
	TimeStamp int64  // unix time when sample was generated
	Offset    int64  // offset of file where sample is exist
	Len       int64  // length of one sample
	Flag      uint32 // compress mode and dict offset
	CRC       uint32 // crc for whole index, except CRC self
}

Index represent short info for one sample, so that speed up to find specifed sample.

func (*Index) CompressMode added in v0.0.9

func (idx *Index) CompressMode() (uint32, uint32)

func (*Index) Marshal

func (idx *Index) Marshal() []byte

func (*Index) SetCompressMode added in v0.0.9

func (idx *Index) SetCompressMode(m uint32, offset uint32)

func (*Index) Unmarshal

func (idx *Index) Unmarshal(b []byte)

type LocalStore

type LocalStore struct {
	Path       string   // path which index and data file is stored
	Index      *os.File // current active index file
	Data       *os.File // current active data file
	Log        *slog.Logger
	DataOffset int64 // file offset which next sample was written to

	sync.Mutex
	// contains filtered or unexported fields
}

LocalStore represent local store, which consist of index and data files. All files was stored into Path (default: /var/log/etop). file format: index_{shard}, data_{shard} shard is unix time of 00:00 utc every day It should work either readonly mode or writeonly mode.

func NewLocalStore

func NewLocalStore(opts ...Option) (*LocalStore, error)

func (*LocalStore) CleanOldFiles added in v0.0.5

func (local *LocalStore) CleanOldFiles(opt WriteOption)

func (*LocalStore) Close

func (local *LocalStore) Close() error

func (*LocalStore) CollectSample added in v0.0.2

func (local *LocalStore) CollectSample(s *Sample) error

func (*LocalStore) DeleteSingleFile added in v0.0.7

func (local *LocalStore) DeleteSingleFile(shard int64)

func (*LocalStore) FileStatInfo added in v0.0.2

func (local *LocalStore) FileStatInfo() (result string, err error)

func (*LocalStore) JumpSampleByTimeStamp added in v0.0.2

func (local *LocalStore) JumpSampleByTimeStamp(timestamp int64, sample *Sample) error

JumpSampleByTimeStamp get sample by specific timestamp (unix time) if no, search the nearest one. ignore 1st sample for better handle corner case.

func (*LocalStore) NextSample added in v0.0.2

func (local *LocalStore) NextSample(step int, sample *Sample) error

func (*LocalStore) Snapshot added in v0.0.2

func (local *LocalStore) Snapshot(begin int64, end int64) (string, error)

func (*LocalStore) WriteLoop

func (local *LocalStore) WriteLoop(opt WriteOption) error

func (*LocalStore) WriteSample

func (local *LocalStore) WriteSample(s *Sample) (bool, error)

type MemoryEvents added in v0.1.5

type MemoryEvents struct {
	Low     uint64
	High    uint64
	Max     uint64
	Oom     uint64
	OomKill uint64
}

type MemoryStat added in v0.1.5

type MemoryStat struct {
	Anon                  uint64
	File                  uint64
	KernelStack           uint64
	Slab                  uint64
	Sock                  uint64
	Shmem                 uint64
	Zswap                 uint64
	Zswapped              uint64
	FileMapped            uint64
	FileDirty             uint64
	FileWriteback         uint64
	AnonThp               uint64
	InactiveAnon          uint64
	ActiveAnon            uint64
	InactiveFile          uint64
	ActiveFile            uint64
	Unevictable           uint64
	SlabReclaimable       uint64
	SlabUnreclaimable     uint64
	Pgfault               uint64
	Pgmajfault            uint64
	WorkingsetRefault     uint64
	WorkingsetActivate    uint64
	WorkingsetNodereclaim uint64
	Pgrefill              uint64
	Pgscan                uint64
	Pgsteal               uint64
	Pgactivate            uint64
	Pgdeactivate          uint64
	Pglazyfree            uint64
	Pglazyfreed           uint64
	ZswpIn                uint64
	ZswpOut               uint64
	ThpFaultAlloc         uint64
	ThpCollapseAlloc      uint64
}

type NetStat added in v0.0.2

type NetStat struct {
	Ip       procfs.Ip
	Icmp     procfs.Icmp
	IcmpMsg  procfs.IcmpMsg
	Tcp      procfs.Tcp
	Udp      procfs.Udp
	UdpLite  procfs.UdpLite
	Ip6      procfs.Ip6
	Icmp6    procfs.Icmp6
	Udp6     procfs.Udp6
	UdpLite6 procfs.UdpLite6
	TcpExt   procfs.TcpExt
	IpExt    procfs.IpExt
}

type Option added in v0.0.2

type Option func(*LocalStore) error

func WithExitProcess added in v0.0.9

func WithExitProcess(log *slog.Logger) Option

func WithPathAndLogger added in v0.0.9

func WithPathAndLogger(path string, log *slog.Logger) Option

func WithWriteOnly added in v0.0.2

func WithWriteOnly(mode, chunk uint32) Option

type PSIData added in v0.1.5

type PSIData struct {
	Avg10  float64
	Avg60  float64
	Avg300 float64
	Total  uint64
}

type PSIStats added in v0.1.5

type PSIStats struct {
	Some PSIData
	Full PSIData
}

type PidMap added in v0.0.3

type PidMap map[int]ProcSample

type ProcSample

type ProcSample struct {
	procfs.ProcStat
	procfs.ProcIO
	CmdLine  string
	Cgroup   string
	EndTime  uint64
	ExitCode uint32
}

type Sample

type Sample struct {
	TimeStamp    int64  // unix time when sample was generated
	SystemSample        // system information
	ProcSamples  PidMap // process information
	CgroupSample *CgroupSample
}

Sample represent all system info and process info.

func NewSample added in v0.0.2

func NewSample() Sample

func (*Sample) Marshal added in v0.0.2

func (s *Sample) Marshal() ([]byte, error)

func (*Sample) Reset added in v0.0.9

func (s *Sample) Reset()

func (*Sample) Unmarshal added in v0.0.2

func (s *Sample) Unmarshal(b []byte) error

type Store

type Store interface {
	// if step is positive , advance the corresponding number of steps
	// otherwise back, then get sample
	NextSample(step int, sample *Sample) error
	// Get sample which collect at timestamp
	JumpSampleByTimeStamp(timestamp int64, sample *Sample) error
}

Store is interface which operate file/network which include sample data.

type SystemSample

type SystemSample struct {
	HostName      string
	KernelVersion string
	PageSize      int
	BootTimeTick  uint64
	procfs.LoadAvg
	procfs.Stat
	procfs.Meminfo
	VmStat
	NetDevStats map[string]procfs.NetDevLine
	DiskStats   map[string]blockdevice.Diskstats
	NetStat
	procfs.NetProtocolStats
	SoftNetStats []procfs.SoftnetStat
}

type VmStat added in v0.0.2

type VmStat struct {
	PageIn          uint64
	PageOut         uint64
	SwapIn          uint64
	SwapOut         uint64
	PageScanKswapd  uint64
	PageScanDirect  uint64
	PageStealKswapd uint64
	PageStealDirect uint64
	OOMKill         uint64
}

type WriteOption added in v0.0.2

type WriteOption struct {
	Interval   time.Duration
	RetainDay  int
	RetainSize int64
}

Jump to

Keyboard shortcuts

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