Documentation ¶
Index ¶
- Constants
- Variables
- func LookupGroupId(group string) (int, error)
- func ReadPidFile(path string) (int, error)
- func RpcArgs(method string, name string, isGroup bool) (string, string)
- func WritePidFile(pid int, path string) error
- type API
- func (a *API) About(unused interface{}, about *About) error
- func (a *API) MonitorAll(unused interface{}, r *ActionResult) error
- func (a *API) MonitorGroup(name string, r *ActionResult) error
- func (a *API) MonitorProcess(name string, r *ActionResult) error
- func (a *API) Quit(unused interface{}, r *ActionResult) error
- func (a *API) Reload(unused interface{}, r *ActionResult) error
- func (a *API) RestartAll(unused interface{}, r *ActionResult) error
- func (a *API) RestartGroup(name string, r *ActionResult) error
- func (a *API) RestartProcess(name string, r *ActionResult) error
- func (a *API) StartAll(unused interface{}, r *ActionResult) error
- func (a *API) StartGroup(name string, r *ActionResult) error
- func (a *API) StartProcess(name string, r *ActionResult) error
- func (a *API) StatusAll(name string, r *ProcessGroupStatus) error
- func (a *API) StatusGroup(name string, r *ProcessGroupStatus) error
- func (a *API) StatusProcess(name string, r *ProcessStatus) error
- func (a *API) StopAll(unused interface{}, r *ActionResult) error
- func (a *API) StopGroup(name string, r *ActionResult) error
- func (a *API) StopProcess(name string, r *ActionResult) error
- func (a *API) Summary(unused interface{}, s *Summary) error
- func (a *API) UnmonitorAll(unused interface{}, r *ActionResult) error
- func (a *API) UnmonitorGroup(name string, r *ActionResult) error
- func (a *API) UnmonitorProcess(name string, r *ActionResult) error
- type About
- type Action
- type ActionError
- type ActionResult
- type AlertMessage
- type CliClient
- type CliFormatter
- type ConfigManager
- func (c *ConfigManager) AddProcess(groupName string, process *Process) error
- func (c *ConfigManager) ApplyDefaultSettings()
- func (c *ConfigManager) FindGroup(name string) (*ProcessGroup, error)
- func (c *ConfigManager) FindProcess(name string) (*Process, error)
- func (c *ConfigManager) LoadConfig(path string) error
- func (c *ConfigManager) VisitProcesses(visit func(p *Process) bool)
- type Control
- func (c *Control) Config() *ConfigManager
- func (c *Control) DoAction(name string, action *ControlAction) error
- func (c *Control) IsMonitoring(process *Process) bool
- func (c *Control) LoadPersistState() error
- func (c *Control) PersistStates(states map[string]*ProcessState) error
- func (c *Control) RegisterEventMonitor(eventMonitor *EventMonitor)
- func (c *Control) State(process *Process) *ProcessState
- type ControlAction
- type ControlInterface
- type DataTimestamp
- type Event
- type EventMonitor
- func (e *EventMonitor) CleanDataForProcess(p *Process)
- func (e *EventMonitor) IsMonitoring(p *Process) bool
- func (e *EventMonitor) Start(configManager *ConfigManager, control *Control) error
- func (e *EventMonitor) StartMonitoringProcess(p *Process)
- func (e *EventMonitor) Stop()
- func (e *EventMonitor) TriggerAlerts(p *Process) bool
- func (e *EventMonitor) TriggerProcessActions(p *Process) bool
- type EventMonitorInterface
- type LoggerConfig
- type ParsedEvent
- type Process
- func (p *Process) Command(program string) (*exec.Cmd, error)
- func (p *Process) IsMonitoringModeActive() bool
- func (p *Process) IsMonitoringModeManual() bool
- func (p *Process) IsMonitoringModePassive() bool
- func (p *Process) IsRunning() bool
- func (p *Process) Pid() (int, error)
- func (p *Process) Redirect(fd *io.Writer, where string) error
- func (p *Process) RestartProcess() error
- func (p *Process) SavePid(pid int) error
- func (p *Process) Spawn(program string) (*exec.Cmd, error)
- func (p *Process) StartProcess() (int, error)
- func (p *Process) StopProcess() error
- type ProcessGroup
- type ProcessGroupStatus
- type ProcessState
- type ProcessStatus
- type ProcessSummary
- type ResourceHolder
- type ResourceManager
- func (r *ResourceManager) CleanData()
- func (r *ResourceManager) CleanDataForProcess(p *Process)
- func (r *ResourceManager) ClearCachedResources()
- func (r *ResourceManager) GetResource(parsedEvent *ParsedEvent, pid int) (uint64, error)
- func (r *ResourceManager) IsValidResourceName(resourceName string) bool
- func (r *ResourceManager) ParseAmount(resourceName string, amount string) (uint64, error)
- func (r *ResourceManager) SetSigarInterface(sigar SigarInterface)
- type RpcServer
- type Settings
- type SigarGetter
- type SigarInterface
- type Summary
- type SystemStatus
- type Watcher
- Bugs
Constants ¶
const ( CONFIG_FILE_POSTFIX = "-gonit.yml" SETTINGS_FILENAME = "gonit.yml" UNIX_SOCKET_TRANSPORT = "unix_socket" MONITOR_MODE_ACTIVE = "active" MONITOR_MODE_PASSIVE = "passive" MONITOR_MODE_MANUAL = "manual" )
const ( MONITOR_NOT = 0x0 MONITOR_YES = 0x1 MONITOR_INIT = 0x2 MONITOR_WAITING = 0x4 )
const ( ACTION_START = iota ACTION_STOP ACTION_RESTART ACTION_MONITOR ACTION_UNMONITOR )
const ( DEFAULT_DURATION = "2s" DEFAULT_INTERVAL = "2s" )
const ( EQ_OPERATOR = 0x1 NEQ_OPERATOR = 0x2 GT_OPERATOR = 0x3 LT_OPERATOR = 0x4 )
const ( INTERVAL_MARGIN_ERR = 0.05 NANO_TO_MILLI = float64(time.Millisecond) )
const ( CPU_PERCENT_NAME = "cpu_percent" MEMORY_USED_NAME = "memory_used" )
const (
DEFAULT_ALERT_TRANSPORT = "none"
)
const DEFAULT_ENV_PATH = "PATH=/bin:/usr/bin:/sbin:/usr/sbin"
const (
ERROR_IN_PROGRESS_FMT = "Process %q action already in progress"
)
const (
VERSION = "0.0.1"
)
Variables ¶
var Log steno.Logger
Functions ¶
func LookupGroupId ¶
until we have user.LookupGroupId: http://codereview.appspot.com/4589049
Types ¶
type API ¶
type API struct {
Control *Control
}
func NewAPI ¶
func NewAPI(config *ConfigManager) *API
func (*API) MonitorAll ¶
func (a *API) MonitorAll(unused interface{}, r *ActionResult) error
func (*API) MonitorGroup ¶
func (a *API) MonitorGroup(name string, r *ActionResult) error
func (*API) MonitorProcess ¶
func (a *API) MonitorProcess(name string, r *ActionResult) error
func (*API) Reload ¶
func (a *API) Reload(unused interface{}, r *ActionResult) error
reload server configuration
func (*API) RestartAll ¶
func (a *API) RestartAll(unused interface{}, r *ActionResult) error
func (*API) RestartGroup ¶
func (a *API) RestartGroup(name string, r *ActionResult) error
func (*API) RestartProcess ¶
func (a *API) RestartProcess(name string, r *ActionResult) error
func (*API) StartAll ¶
func (a *API) StartAll(unused interface{}, r *ActionResult) error
func (*API) StartGroup ¶
func (a *API) StartGroup(name string, r *ActionResult) error
func (*API) StartProcess ¶
func (a *API) StartProcess(name string, r *ActionResult) error
func (*API) StatusGroup ¶
func (a *API) StatusGroup(name string, r *ProcessGroupStatus) error
func (*API) StatusProcess ¶
func (a *API) StatusProcess(name string, r *ProcessStatus) error
func (*API) StopAll ¶
func (a *API) StopAll(unused interface{}, r *ActionResult) error
func (*API) StopProcess ¶
func (a *API) StopProcess(name string, r *ActionResult) error
func (*API) UnmonitorAll ¶
func (a *API) UnmonitorAll(unused interface{}, r *ActionResult) error
func (*API) UnmonitorGroup ¶
func (a *API) UnmonitorGroup(name string, r *ActionResult) error
func (*API) UnmonitorProcess ¶
func (a *API) UnmonitorProcess(name string, r *ActionResult) error
type ActionError ¶
type ActionError struct {
Err error
}
wrap errors returned by API methods so client can disambiguate between API errors and rpc errors
func (*ActionError) Error ¶
func (e *ActionError) Error() string
type ActionResult ¶
type AlertMessage ¶
type AlertMessage struct { Action string `json:"action"` Rule string `json:"rule"` Date time.Time `json:"date"` Service string `json:"service"` Description string `json:"description"` Value float64 `json:"value"` Message_id uint64 `json:"message_id"` }
The JSON message that is sent in alerts.
type CliClient ¶
API interface for cli commands. When gonit is running as a daemon, will be RPCs; Otherwise, invoke the API in-process via reflection.
func NewLocalClient ¶
func NewLocalClient(rcvr interface{}) CliClient
func NewRemoteClient ¶
type CliFormatter ¶
format data returned from the API
type ConfigManager ¶
type ConfigManager struct { ProcessGroups map[string]*ProcessGroup Settings *Settings // contains filtered or unexported fields }
func (*ConfigManager) AddProcess ¶
func (c *ConfigManager) AddProcess(groupName string, process *Process) error
XXX TODO needed for tests, a form of this should probably be in ConfigManager
func (*ConfigManager) ApplyDefaultSettings ¶
func (c *ConfigManager) ApplyDefaultSettings()
Applies default global settings if some options haven't been specified.
func (*ConfigManager) FindGroup ¶
func (c *ConfigManager) FindGroup(name string) (*ProcessGroup, error)
TODO should probably be in configmanager.go Helper method to find a ProcessGroup by name
func (*ConfigManager) FindProcess ¶
func (c *ConfigManager) FindProcess(name string) (*Process, error)
BUG(lisbakke): If there are two processes named the same thing in different process groups, this could return the wrong process. ConfigManager should enforce unique group/process names. XXX TODO should probably be in configmanager.go Helper methods to find a Process by name
func (*ConfigManager) LoadConfig ¶
func (c *ConfigManager) LoadConfig(path string) error
Main function to call, parses a path for gonit config file(s).
func (*ConfigManager) VisitProcesses ¶
func (c *ConfigManager) VisitProcesses(visit func(p *Process) bool)
XXX TODO should probably be in configmanager.go Visit each Process in the ConfigManager. Stop visiting if visit func returns false
type Control ¶
type Control struct { ConfigManager *ConfigManager EventMonitor EventMonitorInterface States map[string]*ProcessState // contains filtered or unexported fields }
func (*Control) Config ¶
func (c *Control) Config() *ConfigManager
ConfigManager accessor (exported for tests)
func (*Control) DoAction ¶
func (c *Control) DoAction(name string, action *ControlAction) error
Invoke given action for the given process and its dependents and/or dependencies
func (*Control) IsMonitoring ¶
func (*Control) LoadPersistState ¶
func (*Control) PersistStates ¶
func (c *Control) PersistStates(states map[string]*ProcessState) error
func (*Control) RegisterEventMonitor ¶
func (c *Control) RegisterEventMonitor(eventMonitor *EventMonitor)
Registers the event monitor with Control so that it can turn event monitoring on/off when processes are started/stopped.
func (*Control) State ¶
func (c *Control) State(process *Process) *ProcessState
type ControlAction ¶
type ControlAction struct {
// contains filtered or unexported fields
}
func NewControlAction ¶
func NewControlAction(method int) *ControlAction
func NewGroupControlAction ¶
func NewGroupControlAction(method int) *ControlAction
type ControlInterface ¶
type ControlInterface interface { DoAction(name string, action *ControlAction) error IsMonitoring(process *Process) bool }
type DataTimestamp ¶
type DataTimestamp struct {
// contains filtered or unexported fields
}
type EventMonitor ¶
type EventMonitor struct {
// contains filtered or unexported fields
}
Managers the monitoring of event rules. It gets the rules from the configmanager, parses them, sets up a timer, then begins monitoring their resource values from resourcemanager. If any events trigger, it will take appropriate action.
func (*EventMonitor) CleanDataForProcess ¶
func (e *EventMonitor) CleanDataForProcess(p *Process)
func (*EventMonitor) IsMonitoring ¶
func (e *EventMonitor) IsMonitoring(p *Process) bool
func (*EventMonitor) Start ¶
func (e *EventMonitor) Start(configManager *ConfigManager, control *Control) error
Given a configmanager config, this function starts the eventmonitor on monitoring events and dispatching them.
func (*EventMonitor) StartMonitoringProcess ¶
func (e *EventMonitor) StartMonitoringProcess(p *Process)
func (*EventMonitor) Stop ¶
func (e *EventMonitor) Stop()
func (*EventMonitor) TriggerAlerts ¶
func (e *EventMonitor) TriggerAlerts(p *Process) bool
func (*EventMonitor) TriggerProcessActions ¶
func (e *EventMonitor) TriggerProcessActions(p *Process) bool
type EventMonitorInterface ¶
type EventMonitorInterface interface { StartMonitoringProcess(process *Process) Start(configManager *ConfigManager, control *Control) error Stop() }
So we can mock it in tests.
type LoggerConfig ¶
type LoggerConfig struct { Level string FileName string Codec string // contains filtered or unexported fields }
func (*LoggerConfig) Close ¶
func (lc *LoggerConfig) Close() error
func (*LoggerConfig) Init ¶
func (lc *LoggerConfig) Init() error
type ParsedEvent ¶
type ParsedEvent struct {
// contains filtered or unexported fields
}
After configmanager gets the rules to be monitored, eventmonitor parses the rules and stores their data as ParsedEvent.
type Process ¶
type Process struct { Name string Pidfile string Start string Stop string Restart string Gid string Uid string Stdout string Stderr string Env []string Dir string Description string DependsOn []string Actions map[string][]string MonitorMode string }
func (*Process) IsMonitoringModeActive ¶
func (*Process) IsMonitoringModeManual ¶
func (*Process) IsMonitoringModePassive ¶
func (*Process) RestartProcess ¶
Restart a process: Spawn Restart program if configured, otherwise call StopProcess() + StartProcess()
func (*Process) Spawn ¶
Fork+Exec program with std{out,err} redirected and new session so program becomes the session and process group leader.
func (*Process) StartProcess ¶
Start a process. Process must manage its own Pidfile.
func (*Process) StopProcess ¶
Stop a process: Spawn Stop program if configured, otherwise send SIGTERM.
type ProcessGroup ¶
func (*ProcessGroup) EventByName ¶
func (pg *ProcessGroup) EventByName(eventName string) *Event
Given an action string name, returns the events associated with it.
type ProcessGroupStatus ¶
type ProcessGroupStatus struct { Name string Group []ProcessStatus }
func (*ProcessGroupStatus) Len ¶
func (pgs *ProcessGroupStatus) Len() int
func (*ProcessGroupStatus) Less ¶
func (pgs *ProcessGroupStatus) Less(i, j int) bool
func (*ProcessGroupStatus) Print ¶
func (g *ProcessGroupStatus) Print(w io.Writer)
func (*ProcessGroupStatus) Swap ¶
func (pgs *ProcessGroupStatus) Swap(i, j int)
type ProcessState ¶
type ProcessState struct { Monitor int MonitorLock sync.Mutex Starts int // contains filtered or unexported fields }
XXX TODO should state be attached to Process type?
type ProcessStatus ¶
type ProcessStatus struct { Summary ProcessSummary Pid int State sigar.ProcState Time sigar.ProcTime Mem sigar.ProcMem }
func (*ProcessStatus) Print ¶
func (p *ProcessStatus) Print(w io.Writer)
type ProcessSummary ¶
type ProcessSummary struct { Name string Running bool ControlState ProcessState }
type ResourceHolder ¶
type ResourceHolder struct {
// contains filtered or unexported fields
}
type ResourceManager ¶
type ResourceManager struct {
// contains filtered or unexported fields
}
Don't create more.
func (*ResourceManager) CleanData ¶
func (r *ResourceManager) CleanData()
Cleans data from ResourceManager.
func (*ResourceManager) CleanDataForProcess ¶
func (r *ResourceManager) CleanDataForProcess(p *Process)
Cleans up the resource data used for a process's event monitors.
func (*ResourceManager) ClearCachedResources ¶
func (r *ResourceManager) ClearCachedResources()
Clears the resources cache.
func (*ResourceManager) GetResource ¶
func (r *ResourceManager) GetResource(parsedEvent *ParsedEvent, pid int) (uint64, error)
Takes a ParsedEvent and pid and returns the value for the resource used in the rule.
func (*ResourceManager) IsValidResourceName ¶
func (r *ResourceManager) IsValidResourceName(resourceName string) bool
Checks to see if a resource is a valid resource.
func (*ResourceManager) ParseAmount ¶
func (r *ResourceManager) ParseAmount(resourceName string, amount string) (uint64, error)
A utility function that parses a rule's amount string and returns the value as the correct type. For instance, in a rule such as 'memory_used > 14mb' the amount is '14mb' which this function would turn into a uint64 of 14*1024*1024.
func (*ResourceManager) SetSigarInterface ¶
func (r *ResourceManager) SetSigarInterface(sigar SigarInterface)
Allows the sigar interface to be set so that tests can set it.
type RpcServer ¶
type RpcServer struct {
// contains filtered or unexported fields
}
func NewRpcServer ¶
Construct a new RpcServer via string URL Currently supporting json RPC over unix or tcp socket
type Settings ¶
type Settings struct { AlertTransport string SocketFile string RpcServerUrl string ProcessPollInterval int Daemon *Process PersistFile string Logging *LoggerConfig }
func (*Settings) ApplyDefaults ¶
func (settings *Settings) ApplyDefaults()
type SigarGetter ¶
type SigarGetter struct{}
type SigarInterface ¶
type SigarInterface interface {
// contains filtered or unexported methods
}
This interface allows us to mock sigar in unit tests.
type Summary ¶
type Summary struct {
Processes []ProcessSummary
}
type SystemStatus ¶
type SystemStatus struct { }
Notes ¶
Bugs ¶
If there are two processes named the same thing in different process groups, this could return the wrong process. ConfigManager should enforce unique group/process names. XXX TODO should probably be in configmanager.go Helper methods to find a Process by name