process

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the prox configuration directory

func FormatBytes

func FormatBytes(bytes uint64) string

FormatBytes formats bytes into human-readable string

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration into human-readable string

func GetSystemCPU

func GetSystemCPU() (float64, error)

GetSystemCPU returns overall system CPU usage

func LoadState

func LoadState(m *Manager, storage *storage.Storage) error

LoadState loads manager state (convenience wrapper)

func SaveState

func SaveState(m *Manager, storage *storage.Storage) error

SaveState saves manager state (convenience wrapper)

Types

type Manager

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

Manager manages all processes in the prox system. It handles process lifecycle, monitoring, and coordination.

func NewManager

func NewManager() *Manager

NewManager creates a new process manager

func (*Manager) Delete

func (m *Manager) Delete(nameOrID string) error

Delete removes a process (stops it first if running)

func (*Manager) Get

func (m *Manager) Get(nameOrID string) *Process

Get returns a process by name or ID. Returns nil if no process is found with the given identifier.

func (*Manager) List

func (m *Manager) List() []*Process

List returns all managed processes sorted alphabetically by name. The returned slice is a copy and can be safely modified by the caller.

func (*Manager) LoadState

func (m *Manager) LoadState(storage *storage.Storage) error

LoadState loads the manager state from disk

func (*Manager) Restart

func (m *Manager) Restart(nameOrID string) error

Restart restarts a process

func (*Manager) RestoreRunningProcesses

func (m *Manager) RestoreRunningProcesses() error

RestoreRunningProcesses attempts to restore monitoring for running processes

func (*Manager) SaveState

func (m *Manager) SaveState(storage *storage.Storage) error

SaveState saves the current manager state to disk

func (*Manager) SetStorage

func (m *Manager) SetStorage(storage Storage)

SetStorage sets the storage backend for the manager

func (*Manager) Start

func (m *Manager) Start(config ProcessConfig) (*Process, error)

Start starts a new process with the given configuration. It validates the config, spawns the process, and begins monitoring. Returns the process instance and any error that occurred.

func (*Manager) Stop

func (m *Manager) Stop(nameOrID string) error

Stop stops a process by name or ID. It performs a graceful shutdown with SIGTERM, then SIGKILL if needed. Returns an error if the process is not found or cannot be stopped.

func (*Manager) StopAll

func (m *Manager) StopAll() error

StopAll stops all running processes

type ManagerState

type ManagerState struct {
	Processes []ProcessState `json:"processes"`
}

ManagerState represents the persistent state of the manager

type MetricsCollector

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

MetricsCollector collects metrics for all managed processes

func NewMetricsCollector

func NewMetricsCollector(manager *Manager) *MetricsCollector

NewMetricsCollector creates a new metrics collector

func (*MetricsCollector) CollectAllMetrics

func (mc *MetricsCollector) CollectAllMetrics() map[string]*ProcessMetrics

CollectAllMetrics collects metrics for all managed processes

func (*MetricsCollector) CollectMetrics

func (mc *MetricsCollector) CollectMetrics(proc *Process) (*ProcessMetrics, error)

CollectMetrics collects metrics for a specific process

type Process

type Process struct {
	ID            string        `json:"id"`
	Name          string        `json:"name"`
	Script        string        `json:"script"`
	Interpreter   string        `json:"interpreter"` // e.g., "node", "python", "go", ""
	Args          []string      `json:"args"`
	Cwd           string        `json:"cwd"`
	Env           []string      `json:"env"`
	PID           int           `json:"pid"`
	Status        ProcessStatus `json:"status"`
	Restarts      int           `json:"restarts"`
	StartedAt     time.Time     `json:"started_at"`
	StoppedAt     *time.Time    `json:"stopped_at,omitempty"`
	RestartPolicy RestartPolicy `json:"restart_policy"`
	DependsOn     []string      `json:"depends_on,omitempty"`
	// contains filtered or unexported fields
}

Process represents a managed process with its configuration and runtime state.

func (*Process) Uptime

func (p *Process) Uptime() time.Duration

Uptime returns how long the process has been running

type ProcessConfig

type ProcessConfig struct {
	Name        string            `json:"name"`
	Script      string            `json:"script"`
	Interpreter string            `json:"interpreter,omitempty"`
	Args        []string          `json:"args,omitempty"`
	Cwd         string            `json:"cwd,omitempty"`
	Env         map[string]string `json:"env,omitempty"`
	Restart     RestartPolicy     `json:"restart,omitempty"`
	DependsOn   []string          `json:"depends_on,omitempty"`
}

ProcessConfig is the configuration for starting a process. It defines how a process should be executed and managed.

type ProcessMetrics

type ProcessMetrics struct {
	PID           int
	CPU           float64
	Memory        uint64 // bytes
	MemoryPercent float64
	Uptime        time.Duration
	NetSent       uint64 // system-wide bytes sent (network accounting per-process is complex)
	NetRecv       uint64 // system-wide bytes received (network accounting per-process is complex)
}

ProcessMetrics holds real-time metrics for a process. Note: NetSent and NetRecv represent system-wide network metrics, not per-process metrics (which are difficult to obtain accurately).

type ProcessState

type ProcessState struct {
	ID          string        `json:"id"`
	Name        string        `json:"name"`
	Script      string        `json:"script"`
	Interpreter string        `json:"interpreter"`
	Args        []string      `json:"args"`
	Cwd         string        `json:"cwd"`
	Env         []string      `json:"env"`
	PID         int           `json:"pid"`
	Status      ProcessStatus `json:"status"`
	Restarts    int           `json:"restarts"`
	StartedAt   time.Time     `json:"started_at"`
	StoppedAt   *time.Time    `json:"stopped_at,omitempty"`
}

ProcessState represents the persistent state of a process

type ProcessStatus

type ProcessStatus string

ProcessStatus represents the current state of a process

const (
	StatusOnline     ProcessStatus = "online"
	StatusStopped    ProcessStatus = "stopped"
	StatusErrored    ProcessStatus = "errored"
	StatusRestarting ProcessStatus = "restarting"
	StatusStopping   ProcessStatus = "stopping"
)

type RestartPolicy

type RestartPolicy string

RestartPolicy defines how a process should be restarted

const (
	RestartAlways    RestartPolicy = "always"
	RestartOnFailure RestartPolicy = "on-failure"
	RestartNever     RestartPolicy = "never"
)

type Storage

type Storage interface {
	GetLogFile(name, stream string) string
	LogsDir() string
}

Storage interface for log paths

Jump to

Keyboard shortcuts

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