Documentation ¶
Index ¶
- Variables
- func CheckContainers(cnt []AlertdContainer, cli *client.Client, a *Alert)
- func ContainerInspect(a *AlertdContainer, c *client.Client) (*types.ContainerJSON, error)
- func ErrContainsErr(e, b error) bool
- func Execute()
- func GetStats(a *AlertdContainer, c *client.Client) (*types.Stats, error)
- func Monitor(c *Conf, a *Alert)
- func Start(c *Conf)
- type Alert
- func (a *Alert) Add(e1, e2 error, s, subAddendum string)
- func (a *Alert) Clear()
- func (a *Alert) Concat(b ...*Alert)
- func (a *Alert) Dump() string
- func (a *Alert) DumpEmail() (s string)
- func (a *Alert) Evaluate()
- func (a *Alert) Len() int
- func (a *Alert) Log()
- func (a *Alert) Send(b []Alerter)
- func (a *Alert) ShouldSend() bool
- type AlertdContainer
- func (c *AlertdContainer) CheckCPUUsage(s *types.Stats)
- func (c *AlertdContainer) CheckExists(e error)
- func (c *AlertdContainer) CheckMemory(s *types.Stats)
- func (c *AlertdContainer) CheckMetrics(s *types.Stats, e error)
- func (c *AlertdContainer) CheckMinPids(s *types.Stats)
- func (c *AlertdContainer) CheckRunning(j *types.ContainerJSON)
- func (c *AlertdContainer) CheckStatics(j *types.ContainerJSON, e error)
- func (c *AlertdContainer) ChecksShouldStop() bool
- func (c *AlertdContainer) HasBecomeKnown(e error) bool
- func (c *AlertdContainer) HasErrored(e error) bool
- func (c *AlertdContainer) IsUnknown(err error) bool
- func (c *AlertdContainer) MemUsageMB(s *types.Stats) uint64
- func (c *AlertdContainer) RealCPUUsage(s *types.Stats) uint64
- func (c *AlertdContainer) ShouldAlertCPU(u uint64) bool
- func (c *AlertdContainer) ShouldAlertMemory(s *types.Stats) bool
- func (c *AlertdContainer) ShouldAlertMinPIDS(s *types.Stats) bool
- func (c *AlertdContainer) ShouldAlertRunning(j *types.ContainerJSON) bool
- type Alerter
- type AlerterStub
- type Checker
- type Conf
- type Container
- type Email
- type Evaluator
- type MetricCheck
- type Pushover
- type Slack
- type StaticCheck
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyConfig = errors.New("the configuration is completely empty (check config file)") ErrEmailNoSMTP = errors.New("no email SMTP server") ErrEmailNoTo = errors.New("no email to addresses") ErrEmailNoFrom = errors.New("no email from addresses") ErrEmailNoPass = errors.New("no email password") ErrEmailNoPort = errors.New("no email port") ErrEmailNoSubject = errors.New("no email subject") ErrSlackNoWebHookURL = errors.New("no slack webhook url") ErrNoContainers = errors.New("there were no containers found in the configuration file") ErrExistCheckFail = errors.New("Existence check failure") ErrExistCheckRecovered = errors.New("Existence check recovered") ErrRunningCheckFail = errors.New("Running check failure") ErrRunningCheckRecovered = errors.New("Running check recovered") ErrCPUCheckFail = errors.New("CPU check failure") ErrCPUCheckRecovered = errors.New("CPU check recovered") ErrMemCheckFail = errors.New("Memory check failure") ErrMemCheckRecovered = errors.New("Memory check recovered") ErrMinPIDCheckFail = errors.New("Min PID check Failure") ErrMinPIDCheckRecovered = errors.New("Min PID check recovered") ErrMaxPIDCheckFail = errors.New("Max PID check Failure") ErrMaxPIDCheckRecovered = errors.New("Max PID check recovered") ErrUnknown = errors.New("Received an unknown error") ErrPushoverAPIToken = errors.New("no pushover api token") ErrPushoverUserKey = errors.New("no pushover user key") ErrPushoverAPIURL = errors.New("no pushover api url") )
these errors are for the purpose of being able to compare them later
var RootCmd = &cobra.Command{ Use: "docker-alertd", Short: "docker-alertd: alert daemon for docker engine", Long: `docker-alerts parses a configuration file and then monitors containers through the docker api.`, Run: func(cmd *cobra.Command, args []string) { err := Config.Validate() if err != nil { log.Println(err) os.Exit(1) } Start(&Config) }, }
RootCmd represents the base command when called without any subcommands
Functions ¶
func CheckContainers ¶
func CheckContainers(cnt []AlertdContainer, cli *client.Client, a *Alert)
CheckContainers goes through and checks all the containers in a loop
func ContainerInspect ¶
func ContainerInspect(a *AlertdContainer, c *client.Client) (*types.ContainerJSON, error)
ContainerInspect returns the information which can decide if the container is current;y running or not.
func ErrContainsErr ¶
ErrContainsErr returns true if the error string contains the message
func Execute ¶
func Execute()
Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.
func GetStats ¶
GetStats just uses the docker API and an already tested Unmarshal function, no testing needed.
Types ¶
type Alert ¶
Alert is the struct that stores information about alerts and its methods satisfy the Alerter interface
func (*Alert) DumpEmail ¶ added in v0.4.4
DumpEmail behaves like dump, but formats them for email by splitting on ":" and adding \n\t (newline and tab) for the first two segments and joining the last segment. This should result in an email that is formatted as follows... [containerName]:
[alertName]: Error: [errString]
func (*Alert) Evaluate ¶
func (a *Alert) Evaluate()
Evaluate will check if error should be sent and then trigger it if necessary
func (*Alert) ShouldSend ¶
ShouldSend returns true if there is an alert message to be sent
type AlertdContainer ¶
type AlertdContainer struct { Name string `json:"name"` Alert *Alert CPUCheck *MetricCheck MemCheck *MetricCheck PIDCheck *MetricCheck // static checks only below... ExistenceCheck *StaticCheck RunningCheck *StaticCheck }
AlertdContainer has the name of the container and the StaticChecks, and MetricChecks which are to be run on the container.
func InitCheckers ¶
func InitCheckers(c *Conf) []AlertdContainer
InitCheckers returns a slice of containers with all the info needed to run a check on the container. Active is for whether or not the alert is active, not the check
func (*AlertdContainer) CheckCPUUsage ¶
func (c *AlertdContainer) CheckCPUUsage(s *types.Stats)
CheckCPUUsage takes care of sending the alerts if they are needed
func (*AlertdContainer) CheckExists ¶
func (c *AlertdContainer) CheckExists(e error)
CheckExists checks that the container exists, running or not
func (*AlertdContainer) CheckMemory ¶
func (c *AlertdContainer) CheckMemory(s *types.Stats)
CheckMemory checks the memory used by the container in MB, returns true if an error should be sent as well as the actual memory usage
func (*AlertdContainer) CheckMetrics ¶
func (c *AlertdContainer) CheckMetrics(s *types.Stats, e error)
CheckMetrics checks everything where the Limit is not 0, there is no return because the checks modify the error in AlertdContainer
func (*AlertdContainer) CheckMinPids ¶
func (c *AlertdContainer) CheckMinPids(s *types.Stats)
CheckMinPids uses the min pids setting and check the number of PIDS in the container returns true if alerts should be sent, and also returns the amount of running pids.
func (*AlertdContainer) CheckRunning ¶
func (c *AlertdContainer) CheckRunning(j *types.ContainerJSON)
CheckRunning will check to see if the container is currently running or not
func (*AlertdContainer) CheckStatics ¶
func (c *AlertdContainer) CheckStatics(j *types.ContainerJSON, e error)
CheckStatics will run all of the static checks that are listed for a container.
func (*AlertdContainer) ChecksShouldStop ¶
func (c *AlertdContainer) ChecksShouldStop() bool
ChecksShouldStop returns whether the checks should stop after the static checks or continue onto the metric checks.
func (*AlertdContainer) HasBecomeKnown ¶
func (c *AlertdContainer) HasBecomeKnown(e error) bool
HasBecomeKnown returns true if there is an active alert and error is nil, which means that the container check was successful and the 0 index check (existence check) cannot be active
func (*AlertdContainer) HasErrored ¶
func (c *AlertdContainer) HasErrored(e error) bool
HasErrored returns true when the error is something other than `isUnknownContainer` which means that docker-alertd probably crashed.
func (*AlertdContainer) IsUnknown ¶
func (c *AlertdContainer) IsUnknown(err error) bool
IsUnknown is a check that takes the error when the docker API is polled, it mathes part of the error string that is returned.
func (*AlertdContainer) MemUsageMB ¶
func (c *AlertdContainer) MemUsageMB(s *types.Stats) uint64
MemUsageMB returns the memory usage in MB
func (*AlertdContainer) RealCPUUsage ¶
func (c *AlertdContainer) RealCPUUsage(s *types.Stats) uint64
RealCPUUsage calculates the CPU usage based on the ContainerJSON info
func (*AlertdContainer) ShouldAlertCPU ¶
func (c *AlertdContainer) ShouldAlertCPU(u uint64) bool
ShouldAlertCPU returns true if the limit is breached
func (*AlertdContainer) ShouldAlertMemory ¶
func (c *AlertdContainer) ShouldAlertMemory(s *types.Stats) bool
ShouldAlertMemory returns whether the memory limit has been exceeded
func (*AlertdContainer) ShouldAlertMinPIDS ¶
func (c *AlertdContainer) ShouldAlertMinPIDS(s *types.Stats) bool
ShouldAlertMinPIDS returns true if the minPID check fails
func (*AlertdContainer) ShouldAlertRunning ¶
func (c *AlertdContainer) ShouldAlertRunning(j *types.ContainerJSON) bool
ShouldAlertRunning returns whether the running state is as expected
type Alerter ¶
Alerter is the interface which will handle alerting via different methods such as email and twitter/slack
type AlerterStub ¶ added in v0.3.2
AlerterStub stores the bytes needed for the alerter stub in the config file as well as a boolean value which is evaluated only if the user has supplied specific alerter stubs to include
type Checker ¶
type Checker interface { CPUCheck(s *types.Stats) MemCheck(s *types.Stats) PIDCheck(s *types.Stats) ExistenceCheck(a *types.ContainerJSON, e error) RunningCheck(a *types.ContainerJSON, e error) }
Checker interface has all of the methods necessary to check a container
type Conf ¶
type Conf struct { Containers []Container Email Email Slack Slack Pushover Pushover Iterations uint64 Duration uint64 Alerters []Alerter }
Conf struct that combines containers and email settings structs
var ( // Config is the configuration object defined in conf-types file Config Conf )
func (*Conf) ValidateEmailSettings ¶
ValidateEmailSettings calls valid on the Email settings and adds them to the alerters if everything is ok
func (*Conf) ValidatePushoverSettings ¶ added in v0.3.2
ValidatePushoverSettings validates pushover settings and adds it to the alerters
func (*Conf) ValidateSlackSettings ¶
ValidateSlackSettings validates slack settings and adds it to the alerters
type Container ¶
type Container struct { Name string MaxCPU *uint64 MaxMem *uint64 MinProcs *uint64 ExpectedRunning *bool }
Container gets data from the Unmarshaling of the configuration file JSON and stores the data throughout the course of the monitor.
type Email ¶
type Email struct { SMTP string Password string Port string From string To []string Subject string }
Email implements the Alerter interface and sends emails
type Evaluator ¶
type Evaluator interface { Send(a []Alerter) Evaluate() }
Evaluator evaluates a set of alerts and decides if they need to be sent
type MetricCheck ¶
MetricCheck stores the name of the alert, a function, and a active boolean
func (*MetricCheck) ToggleAlertActive ¶
func (c *MetricCheck) ToggleAlertActive()
ToggleAlertActive changes the state of the alert
type Pushover ¶ added in v0.3.2
Pushover contains all info needed to push a notification to Pushover api
type Slack ¶
type Slack struct {
WebhookURL string
}
Slack contains all the info needed to connect to a slack channel
type StaticCheck ¶
StaticCheck checks the container for some static thing that is not based on usage statistics, like its existence, whether it is running or not, etc.
func (*StaticCheck) ToggleAlertActive ¶
func (c *StaticCheck) ToggleAlertActive()
ToggleAlertActive changes the state of the alert