Documentation
¶
Index ¶
- func ConfigDir() (string, error)
- func FormatBytes(bytes uint64) string
- func FormatDuration(d time.Duration) string
- func GetSystemCPU() (float64, error)
- func LoadState(m *Manager, storage *storage.Storage) error
- func SaveState(m *Manager, storage *storage.Storage) error
- type Manager
- func (m *Manager) Delete(nameOrID string) error
- func (m *Manager) Get(nameOrID string) *Process
- func (m *Manager) List() []*Process
- func (m *Manager) LoadState(storage *storage.Storage) error
- func (m *Manager) Restart(nameOrID string) error
- func (m *Manager) RestoreRunningProcesses() error
- func (m *Manager) SaveState(storage *storage.Storage) error
- func (m *Manager) SetStorage(storage Storage)
- func (m *Manager) Start(config ProcessConfig) (*Process, error)
- func (m *Manager) Stop(nameOrID string) error
- func (m *Manager) StopAll() error
- type ManagerState
- type MetricsCollector
- type Process
- type ProcessConfig
- type ProcessMetrics
- type ProcessState
- type ProcessStatus
- type RestartPolicy
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes formats bytes into human-readable string
func FormatDuration ¶
FormatDuration formats a duration into human-readable string
func GetSystemCPU ¶
GetSystemCPU returns overall system CPU usage
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 (*Manager) Get ¶
Get returns a process by name or ID. Returns nil if no process is found with the given identifier.
func (*Manager) List ¶
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) RestoreRunningProcesses ¶
RestoreRunningProcesses attempts to restore monitoring for running processes
func (*Manager) SetStorage ¶
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.
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.
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" )