stats

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRemoteStatsCollectorFromSFTP

func NewRemoteStatsCollectorFromSFTP(sftpClient *sftp.Client, sampleDelta time.Duration) *remoteStatsCollector

NewRemoteStatsCollectorFromSFTP creates a new instance of remoteStatsCollector from an existing SFTP client

func NewRemoteStatsCollectorFromSSH

func NewRemoteStatsCollectorFromSSH(sshClient *ssh.Client, sampleDelta time.Duration) (*remoteStatsCollector, error)

NewRemoteStatsCollectorFromSSH creates a new instance of remoteStatsCollector from an SSH connection

func NewRemoteStatsCollectorFromSSHConfig

func NewRemoteStatsCollectorFromSSHConfig(serverAddress string, config *ssh.ClientConfig, sampleDelta time.Duration) (*remoteStatsCollector, error)

NewRemoteStatsCollectorFromSSHConfig creates a new instance of remoteStatsCollector from SSH configuration

func PrintSystemStats

func PrintSystemStats(stats *SystemStats)

func SystemStatsToJSON

func SystemStatsToJSON(stats *SystemStats) map[string]any

Types

type CPUStat

type CPUStat struct {
	Core     string // e.g., "cpu0", "cpu1"
	UsagePct float64
}

type RemoteStatsMonitor

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

RemoteStatsMonitor monitors remote system stats at regular intervals

func NewRemoteStatsMonitorFromSFTP

func NewRemoteStatsMonitorFromSFTP(sftpClient *sftp.Client, interval time.Duration, sampleDelta time.Duration, logger *log.Logger) *RemoteStatsMonitor

NewRemoteStatsMonitorFromSFTP creates a new monitor from an existing SFTP client

func NewRemoteStatsMonitorFromSSH

func NewRemoteStatsMonitorFromSSH(sshClient *ssh.Client, interval time.Duration, sampleDelta time.Duration, logger *log.Logger) (*RemoteStatsMonitor, error)

NewRemoteStatsMonitorFromSSH creates a new monitor from an existing SSH client

func NewRemoteStatsMonitorFromSSHConfig

func NewRemoteStatsMonitorFromSSHConfig(serverAddress string, config *ssh.ClientConfig, interval time.Duration, sampleDelta time.Duration, logger *log.Logger) (*RemoteStatsMonitor, error)

NewRemoteStatsMonitorFromSSHConfig creates a new monitor from SSH configuration

func (*RemoteStatsMonitor) Close

func (m *RemoteStatsMonitor) Close() error

Close closes the underlying collector and stops monitoring

func (*RemoteStatsMonitor) GetCurrentStats

func (m *RemoteStatsMonitor) GetCurrentStats() (*SystemStats, error)

GetCurrentStats gets the current system stats without logging

func (*RemoteStatsMonitor) GetInterval

func (m *RemoteStatsMonitor) GetInterval() time.Duration

GetInterval returns the current monitoring interval

func (*RemoteStatsMonitor) GetSampleDelta

func (m *RemoteStatsMonitor) GetSampleDelta() time.Duration

GetSampleDelta returns the current CPU sampling interval

func (*RemoteStatsMonitor) IsRunning

func (m *RemoteStatsMonitor) IsRunning() bool

IsRunning returns whether the monitor is currently running

func (*RemoteStatsMonitor) SetInterval

func (m *RemoteStatsMonitor) SetInterval(interval time.Duration)

SetInterval updates the monitoring interval (only effective after restart)

func (*RemoteStatsMonitor) SetLogFile

func (m *RemoteStatsMonitor) SetLogFile(filename string) error

SetLogFile sets the logger to write to the specified file

func (*RemoteStatsMonitor) SetLogLineFunc

func (m *RemoteStatsMonitor) SetLogLineFunc(logLineFunc func(*SystemStats) ([]byte, error))

SetLogLine sets a custom log line formatting function

func (*RemoteStatsMonitor) SetSampleDelta

func (m *RemoteStatsMonitor) SetSampleDelta(sampleDelta time.Duration)

SetSampleDelta updates the CPU sampling interval (only effective after restart)

func (*RemoteStatsMonitor) StartAsync

func (m *RemoteStatsMonitor) StartAsync() error

StartAsync starts monitoring asynchronously (non-blocking call)

func (*RemoteStatsMonitor) StartSync

func (m *RemoteStatsMonitor) StartSync() error

StartSync starts monitoring synchronously (blocking call)

func (*RemoteStatsMonitor) Stop

func (m *RemoteStatsMonitor) Stop()

Stop stops the monitoring by cancelling the internal context

type SystemStats

type SystemStats struct {
	TotalMemoryMB      float64
	UsedMemoryMB       float64
	UsedMemoryPercent  float64
	TotalCPUPercentage float64   // "cpu" aggregate line
	CPUStats           []CPUStat // only "cpu0", "cpu1", ...
}

Jump to

Keyboard shortcuts

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