rename monitor -> mon
This commit is contained in:
48
monitor.go
48
monitor.go
@@ -162,50 +162,50 @@ func (mon *AbstractMonitor) tick(iface MonitorInterface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyseData decides if the monitor is statistically up or down and creates / resolves an incident
|
// AnalyseData decides if the monitor is statistically up or down and creates / resolves an incident
|
||||||
func (monitor *AbstractMonitor) AnalyseData() {
|
func (mon *AbstractMonitor) AnalyseData() {
|
||||||
// look at the past few incidents
|
// look at the past few incidents
|
||||||
numDown := 0
|
numDown := 0
|
||||||
for _, wasUp := range monitor.history {
|
for _, wasUp := range mon.history {
|
||||||
if wasUp == false {
|
if wasUp == false {
|
||||||
numDown++
|
numDown++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t := (float32(numDown) / float32(len(monitor.history))) * 100
|
t := (float32(numDown) / float32(len(mon.history))) * 100
|
||||||
if monitor.ThresholdCount {
|
if mon.ThresholdCount {
|
||||||
logrus.Printf("%s %d/%d down at %v", monitor.Name, numDown, int(monitor.Threshold), time.Now().Format(DefaultTimeFormat))
|
logrus.Printf("%s %d/%d down at %v", mon.Name, numDown, int(mon.Threshold), time.Now().Format(mon.config.DateFormat))
|
||||||
} else {
|
} else {
|
||||||
logrus.Printf("%s %.2f%%/%.2f%% down at %v", monitor.Name, t, monitor.Threshold, time.Now().Format(DefaultTimeFormat))
|
logrus.Printf("%s %.2f%%/%.2f%% down at %v", mon.Name, t, mon.Threshold, time.Now().Format(mon.config.DateFormat))
|
||||||
}
|
}
|
||||||
|
|
||||||
histSize := HistorySize
|
histSize := HistorySize
|
||||||
if monitor.ThresholdCount {
|
if mon.ThresholdCount {
|
||||||
histSize = int(monitor.Threshold)
|
histSize = int(mon.Threshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(monitor.history) != histSize {
|
if len(mon.history) != histSize {
|
||||||
// not saturated
|
// not saturated
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
triggered := (monitor.ThresholdCount && numDown == int(monitor.Threshold)) || (!monitor.ThresholdCount && t > monitor.Threshold)
|
triggered := (mon.ThresholdCount && numDown == int(mon.Threshold)) || (!mon.ThresholdCount && t > mon.Threshold)
|
||||||
|
|
||||||
if triggered && monitor.incident == nil {
|
if triggered && mon.incident == nil {
|
||||||
// create incident
|
// create incident
|
||||||
subject, message := monitor.Template.Investigating.Exec(getTemplateData(monitor))
|
subject, message := mon.Template.Investigating.Exec(getTemplateData(mon))
|
||||||
monitor.incident = &Incident{
|
mon.incident = &Incident{
|
||||||
Name: subject,
|
Name: subject,
|
||||||
ComponentID: monitor.ComponentID,
|
ComponentID: mon.ComponentID,
|
||||||
Message: message,
|
Message: message,
|
||||||
Notify: true,
|
Notify: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// is down, create an incident
|
// is down, create an incident
|
||||||
logrus.Warnf("%v: creating incident. Monitor is down: %v", monitor.Name, monitor.lastFailReason)
|
logrus.Warnf("%v: creating incident. Monitor is down: %v", mon.Name, mon.lastFailReason)
|
||||||
// set investigating status
|
// set investigating status
|
||||||
monitor.incident.SetInvestigating()
|
mon.incident.SetInvestigating()
|
||||||
// create/update incident
|
// create/update incident
|
||||||
if err := monitor.incident.Send(monitor.config); err != nil {
|
if err := mon.incident.Send(mon.config); err != nil {
|
||||||
logrus.Printf("Error sending incident: %v\n", err)
|
logrus.Printf("Error sending incident: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,20 +213,20 @@ func (monitor *AbstractMonitor) AnalyseData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// still triggered or no incident
|
// still triggered or no incident
|
||||||
if triggered || monitor.incident == nil {
|
if triggered || mon.incident == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Warnf("Resolving incident")
|
logrus.Warnf("Resolving incident")
|
||||||
|
|
||||||
// was down, created an incident, its now ok, make it resolved.
|
// was down, created an incident, its now ok, make it resolved.
|
||||||
logrus.Printf("%v resolved downtime incident", monitor.Name)
|
logrus.Printf("%v resolved downtime incident", mon.Name)
|
||||||
|
|
||||||
// resolve incident
|
// resolve incident
|
||||||
monitor.incident.Message = "\n**Resolved** - " + time.Now().Format(DefaultTimeFormat) + "\n\n - - - \n\n" + monitor.incident.Message
|
mon.incident.Message = "\n**Resolved** - " + time.Now().Format(mon.config.DateFormat) + "\n\n - - - \n\n" + mon.incident.Message
|
||||||
monitor.incident.SetFixed()
|
mon.incident.SetFixed()
|
||||||
monitor.incident.Send(monitor.config)
|
mon.incident.Send(mon.config)
|
||||||
|
|
||||||
monitor.lastFailReason = ""
|
mon.lastFailReason = ""
|
||||||
monitor.incident = nil
|
mon.incident = nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user