Documentation ¶
Overview ¶
Package monitor provides the tools to monitor a set of system properties, for example, services
Index ¶
- Constants
- func CheckOnce(c interface{ ... }, opts Opts) bool
- func NewClient(socket string) interface{ ... }
- type Checkable
- type CheckableProcess
- type ChecksDatabase
- type ChecksDatabaseEntry
- type ChecksManager
- type Client
- func (c *Client) Monitor(id string) error
- func (c *Client) MonitorAll() (errors []error)
- func (c *Client) Restart(id string) error
- func (c *Client) RestartAll() (errors []error)
- func (c *Client) Start(id string) error
- func (c *Client) StartAll() (errors []error)
- func (c *Client) StatusText(args ...string) string
- func (c *Client) Stop(id string) error
- func (c *Client) StopAll() (errors []error)
- func (c *Client) SummaryText(args ...string) string
- func (c *Client) Unmonitor(id string) error
- func (c *Client) UnmonitorAll() (errors []error)
- type Command
- type Config
- type Logger
- type Monitor
- func (m *Monitor) AddCheck(c interface{ ... }) error
- func (m *Monitor) FindCheck(id string) interface{ ... }
- func (m *Monitor) HTTPServerSupported() bool
- func (m *Monitor) LastCheck() time.Time
- func (m *Monitor) LoopForever(finish chan bool)
- func (m *Monitor) Monitor(id string) error
- func (m *Monitor) MonitorAll() (errors []error)
- func (m *Monitor) Perform()
- func (m *Monitor) Reload() error
- func (m *Monitor) Restart(id string) error
- func (m *Monitor) RestartAll() []error
- func (m *Monitor) RuntimeDebugStats() string
- func (m *Monitor) Start(id string) error
- func (m *Monitor) StartAll() []error
- func (m *Monitor) StartServer() error
- func (m *Monitor) StatusText(args ...string) string
- func (m *Monitor) Stop(id string) error
- func (m *Monitor) StopAll() []error
- func (m *Monitor) SummaryText(args ...string) string
- func (m *Monitor) Terminate() (err error)
- func (m *Monitor) Unmonitor(id string) error
- func (m *Monitor) UnmonitorAll() (errors []error)
- func (m *Monitor) UpdateDatabase() error
- func (m *Monitor) Uptime() time.Duration
- type Opts
- type ProcessCheck
- func (c ProcessCheck) GetID() string
- func (c ProcessCheck) GetTimeout() time.Duration
- func (c ProcessCheck) GetUniqueID() string
- func (c *ProcessCheck) Initialize(opts Opts)
- func (c ProcessCheck) IsMonitored() bool
- func (c *ProcessCheck) IsNotRunning() bool
- func (c *ProcessCheck) IsRunning() bool
- func (c *ProcessCheck) Parse(data string)
- func (c *ProcessCheck) Perform()
- func (c *ProcessCheck) Pid() int
- func (c *ProcessCheck) Restart() (err error)
- func (c ProcessCheck) SetMonitored(monitored bool)
- func (c *ProcessCheck) Start() error
- func (c *ProcessCheck) Status() (str string)
- func (c *ProcessCheck) Stop() error
- func (c *ProcessCheck) String() string
- func (c *ProcessCheck) SummaryText() string
- func (c *ProcessCheck) Uptime() time.Duration
Constants ¶
const CheckMaxStartTries = 5
CheckMaxStartTries defines a global default value for how many failed start attempts are made before automatically unmonitoring a check
Variables ¶
This section is empty.
Functions ¶
func CheckOnce ¶
CheckOnce calls the provided check Perform operation once, ignoring the call if a previous call is still in process
func NewClient ¶
func NewClient(socket string) interface { ChecksManager }
NewClient returns a new monitor Client instance using the provided socket to connect to a previously running daemon
Types ¶
type Checkable ¶
type Checkable interface { GetID() string GetUniqueID() string GetTimeout() time.Duration Perform() SetMonitored(bool) IsMonitored() bool Parse(data string) String() string Initialize(Opts) SummaryText() string }
Checkable defines the interface the every Check must provide
type CheckableProcess ¶
type CheckableProcess interface { Checkable Start() error Stop() error Restart() error Status() string IsRunning() bool IsNotRunning() bool Uptime() time.Duration Pid() int }
CheckableProcess defines the interface the every process Check (type service) must provide
type ChecksDatabase ¶
ChecksDatabase defines a storage for saving process check information
func NewDatabase ¶
func NewDatabase(file string) (*ChecksDatabase, error)
NewDatabase returns a new database storage for checks information
func (*ChecksDatabase) AddEntry ¶
func (cd *ChecksDatabase) AddEntry(id string) *ChecksDatabaseEntry
AddEntry adds a check entry to the database
func (*ChecksDatabase) GetEntry ¶
func (cd *ChecksDatabase) GetEntry(id string) *ChecksDatabaseEntry
GetEntry returns an entry from the database
type ChecksDatabaseEntry ¶
type ChecksDatabaseEntry struct { ID string Monitored bool DataCollectedAt time.Time Uptime time.Duration // contains filtered or unexported fields }
ChecksDatabaseEntry defines a check entry in the monitor database
type ChecksManager ¶
type ChecksManager interface { // Uptime() time.Duration // UpdateDatabase() error // Reload() error Monitor(id string) error Unmonitor(id string) error Start(id string) error Stop(id string) error Restart(id string) error MonitorAll() []error UnmonitorAll() []error StartAll() []error StopAll() []error RestartAll() []error SummaryText(args ...string) string StatusText(args ...string) string }
ChecksManager defines the interface provided by objects being able to manipulate checks
type Client ¶
Client allows connection to an existing monitor via a UNIX socket and use it through the same API as when directly using the monitor The main difference is that service management call don't block
func (*Client) Monitor ¶
Monitor looks for the Check with the provide id and set its monitored status to true
func (*Client) MonitorAll ¶
MonitorAll set all checks monitored status to true
func (*Client) RestartAll ¶
RestartAll allows restarting all process checks
func (*Client) StatusText ¶
StatusText returns a string containing a long description of all checks and Monitor attributes
func (*Client) SummaryText ¶
SummaryText returns a string containing a short status summary for every check registered
func (*Client) Unmonitor ¶
Unmonitor looks for the Check with the provide id and set its monitored status to false
func (*Client) UnmonitorAll ¶
UnmonitorAll set all checks monitored status to false
type Command ¶
type Command struct { // Cmd contains the actual commad to call Cmd string // Timeout defines the time to wait for the command to trigger // a state change in the check (for example, running to stopped after calling stop) Timeout time.Duration // contains filtered or unexported fields }
Command defines a check command to execute
type Config ¶
type Config struct { ControlFile string Verbose bool ShouldDaemonize bool CheckInterval time.Duration PidFile string SocketFile string StateFile string LogFile string }
Config reprosents the basic configuration settings supported by the monitor
type Logger ¶
type Logger interface { Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Printf(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) Panicf(format string, args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Print(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) MDebugf(format string, args ...interface{}) }
Logger defines the required interface to support to be able to log messages
type Monitor ¶
type Monitor struct { // Pid is the Pid of the running monitor process Pid int // PidFile contains the path in which the Monitor PID is stored PidFile string // LogFile constains the path to the Monitor log file LogFile string // StartTime is the moment in which the monitor was started StartTime time.Time // ControlFile points to the configuration file used to load the checks to perform ControlFile string // CheckInterval configures the interval between checks CheckInterval time.Duration // SocketFile contains the path to he listening Unix domain socket when the HTTP server is enabled SocketFile string // contains filtered or unexported fields }
Monitor represents an instance of the monitor application
func (*Monitor) AddCheck ¶
AddCheck registers a new Check in the Monitor. It will return an error if an existing check is already registered with the same id
func (*Monitor) HTTPServerSupported ¶
HTTPServerSupported return wether the HTTP interface can be enabled or not
func (*Monitor) LoopForever ¶
LoopForever allows performing all registerd checks in a loop
func (*Monitor) Monitor ¶
Monitor looks for the Check with the provide id and set its monitored status to true
func (*Monitor) MonitorAll ¶
MonitorAll set all checks monitored status to true
func (*Monitor) Perform ¶
func (m *Monitor) Perform()
Perform calls the Perform method for all managed checks currently monitored
func (*Monitor) Reload ¶
Reload makes the running app re-parse the configuration file, updating the set of monitored checks
func (*Monitor) RestartAll ¶
RestartAll allows restarting all process checks
func (*Monitor) RuntimeDebugStats ¶
RuntimeDebugStats returns a summary text with currently running Go Routines and memory consume
func (*Monitor) StartServer ¶
StartServer starts the HTTP intterface
func (*Monitor) StatusText ¶
StatusText returns a string containing a long description of all checks and Monitor attributes
func (*Monitor) SummaryText ¶
SummaryText returns a string containing a short status summary for every check registered
func (*Monitor) Terminate ¶
Terminate allows cleaning quitting a monitor (ie. stopping the HTTP server)
func (*Monitor) Unmonitor ¶
Unmonitor looks for the Check with the provide id and set its monitored status to false
func (*Monitor) UnmonitorAll ¶
UnmonitorAll set all checks monitored status to false
func (*Monitor) UpdateDatabase ¶
UpdateDatabase updates the file database with the in-memory state
type Opts ¶
type Opts struct { // Logger allows customizing the logger to used Logger Logger }
Opts defines a set of common configuration options for many of the package functions
type ProcessCheck ¶
type ProcessCheck struct { Group string PidFile string StartProgram *Command StopProgram *Command // contains filtered or unexported fields }
ProcessCheck defines a service type check
func (ProcessCheck) GetTimeout ¶
GetTimeout returns the check Timeout
func (ProcessCheck) GetUniqueID ¶
func (c ProcessCheck) GetUniqueID() string
GetUniqueID returns a globally unique ide for the check. Two instances of the same check with the same ID will have different UniqueId
func (*ProcessCheck) Initialize ¶
func (c *ProcessCheck) Initialize(opts Opts)
Initialize fills up any unconfigured process attributes, for example, the logger
func (ProcessCheck) IsMonitored ¶
func (c ProcessCheck) IsMonitored() bool
func (*ProcessCheck) IsNotRunning ¶
func (c *ProcessCheck) IsNotRunning() bool
IsNotRunning returns true if the process is not running
func (*ProcessCheck) IsRunning ¶
func (c *ProcessCheck) IsRunning() bool
IsRunning returns true if the process is running
func (*ProcessCheck) Parse ¶
func (c *ProcessCheck) Parse(data string)
Parse reads a string containing a monit-like process configuration text and loads the specified settings
func (*ProcessCheck) Perform ¶
func (c *ProcessCheck) Perform()
Perform makes the process check execute its default task. In case of process type checks, calling its start command and waiting for the status to change to "running"
func (*ProcessCheck) Pid ¶
func (c *ProcessCheck) Pid() int
Pid returns the pid of the process by reading its pid file. It will return -1 in case of no pid file found or it is malformed
func (*ProcessCheck) Restart ¶
func (c *ProcessCheck) Restart() (err error)
Restart restarts tge service by calling its stop and restart commands and waiting for the checck to be in running status
func (ProcessCheck) SetMonitored ¶
func (c ProcessCheck) SetMonitored(monitored bool)
func (*ProcessCheck) Start ¶
func (c *ProcessCheck) Start() error
Start starts the process by calling its start command and waiting for the checck to be in running status
func (*ProcessCheck) Status ¶
func (c *ProcessCheck) Status() (str string)
Status returns a string specifying the process status ("running" or "stopped")
func (*ProcessCheck) Stop ¶
func (c *ProcessCheck) Stop() error
Stop stops the process by calling its stop command and waiting for the checck to be in stopped status
func (*ProcessCheck) String ¶
func (c *ProcessCheck) String() string
String returns a string representation for the process check
func (*ProcessCheck) SummaryText ¶
func (c *ProcessCheck) SummaryText() string
SummaryText returns a string the a short summary of the check status: Process id monitored
func (*ProcessCheck) Uptime ¶
func (c *ProcessCheck) Uptime() time.Duration
Uptime returns for how long the process have been running