mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-19 12:40:49 +00:00
Merge pull request #68 from prometheus/migrate-logging
Migrate logging to use `prometheus/log`.
This commit is contained in:
commit
ba4e53343c
@ -32,7 +32,7 @@ configuration updates.
|
||||
## Building and running
|
||||
|
||||
make
|
||||
./alertmanager -logtostderr -config.file=/path/to/alertmanager.conf
|
||||
./alertmanager -config.file=/path/to/alertmanager.conf
|
||||
|
||||
## Configuring Prometheus to send alerts
|
||||
|
||||
|
@ -16,8 +16,8 @@ package config
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/prometheus/log"
|
||||
|
||||
pb "github.com/prometheus/alertmanager/config/generated"
|
||||
)
|
||||
@ -46,7 +46,7 @@ func LoadFromFile(fileName string) (Config, error) {
|
||||
func MustLoadFromFile(fileName string) Config {
|
||||
conf, err := LoadFromFile(fileName)
|
||||
if err != nil {
|
||||
glog.Fatalf("Error loading configuration from %s: %s", fileName, err)
|
||||
log.Fatalf("Error loading configuration from %s: %s", fileName, err)
|
||||
}
|
||||
return conf
|
||||
}
|
||||
|
@ -14,8 +14,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"github.com/howeyc/fsnotify"
|
||||
"github.com/prometheus/log"
|
||||
)
|
||||
|
||||
type ReloadCallback func(*Config)
|
||||
@ -37,25 +37,25 @@ func NewFileWatcher(fileName string) *fileWatcher {
|
||||
func (w *fileWatcher) Watch(cb ReloadCallback) {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
glog.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = watcher.WatchFlags(w.fileName, fsnotify.FSN_MODIFY)
|
||||
if err != nil {
|
||||
glog.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case ev := <-watcher.Event:
|
||||
glog.Infof("Config file changed (%s), attempting reload", ev)
|
||||
log.Infof("Config file changed (%s), attempting reload", ev)
|
||||
conf, err := LoadFromFile(w.fileName)
|
||||
if err != nil {
|
||||
glog.Error("Error loading new config: ", err)
|
||||
log.Error("Error loading new config: ", err)
|
||||
failedConfigReloads.Inc()
|
||||
} else {
|
||||
cb(&conf)
|
||||
glog.Info("Config reloaded successfully")
|
||||
log.Info("Config reloaded successfully")
|
||||
configReloads.Inc()
|
||||
}
|
||||
// Re-add the file watcher since it can get lost on some changes. E.g.
|
||||
@ -63,7 +63,7 @@ func (w *fileWatcher) Watch(cb ReloadCallback) {
|
||||
// sequence, after which the newly written file is no longer watched.
|
||||
err = watcher.WatchFlags(w.fileName, fsnotify.FSN_MODIFY)
|
||||
case err := <-watcher.Error:
|
||||
glog.Error("Error watching config: ", err)
|
||||
log.Error("Error watching config: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
main.go
8
main.go
@ -19,7 +19,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/log"
|
||||
|
||||
"github.com/prometheus/alertmanager/config"
|
||||
"github.com/prometheus/alertmanager/manager"
|
||||
@ -53,13 +53,13 @@ func main() {
|
||||
|
||||
err := silencer.LoadFromFile(*silencesFile)
|
||||
if err != nil {
|
||||
glog.Warning("Couldn't load silences, starting up with empty silence list: ", err)
|
||||
log.Warn("Couldn't load silences, starting up with empty silence list: ", err)
|
||||
}
|
||||
saveSilencesTicker := time.NewTicker(10 * time.Second)
|
||||
go func() {
|
||||
for _ = range saveSilencesTicker.C {
|
||||
if err := silencer.SaveToFile(*silencesFile); err != nil {
|
||||
glog.Error("Error saving silences to file: ", err)
|
||||
log.Error("Error saving silences to file: ", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -124,6 +124,6 @@ func main() {
|
||||
statusHandler.UpdateConfig(conf.String())
|
||||
})
|
||||
|
||||
glog.Info("Running notification dispatcher...")
|
||||
log.Info("Running notification dispatcher...")
|
||||
notifier.Dispatch()
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/log"
|
||||
)
|
||||
|
||||
// AlertManager stores Alerts and removes them upon expiry.
|
||||
@ -243,7 +243,7 @@ func (s *memoryAlertManager) SetAggregationRules(rules AggregationRules) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
glog.Infof("Replacing aggregator rules (old: %d, new: %d)...", len(s.rules), len(rules))
|
||||
log.Infof("Replacing aggregator rules (old: %d, new: %d)...", len(s.rules), len(rules))
|
||||
s.rules = rules
|
||||
|
||||
// Reassign AlertAggregates to the first new matching rule, set the rule to
|
||||
@ -350,7 +350,7 @@ func (s *memoryAlertManager) refreshNotifications() {
|
||||
}
|
||||
}
|
||||
if numSent > 0 {
|
||||
glog.Infof("Sent %d notifications", numSent)
|
||||
log.Infof("Sent %d notifications", numSent)
|
||||
heap.Init(&s.aggregatesByNextNotification)
|
||||
}
|
||||
}
|
||||
@ -395,7 +395,7 @@ func (s *memoryAlertManager) runIteration() {
|
||||
s.removeExpiredAggregates()
|
||||
s.checkNotificationRepeats()
|
||||
if refresh, reasons := s.refreshNeeded(); refresh {
|
||||
glog.Infof("Recomputing notification outputs (%s)", strings.Join(reasons, ", "))
|
||||
log.Infof("Recomputing notification outputs (%s)", strings.Join(reasons, ", "))
|
||||
s.refreshNotifications()
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/log"
|
||||
"github.com/thorduri/pushover"
|
||||
|
||||
pb "github.com/prometheus/alertmanager/config/generated"
|
||||
@ -180,7 +180,7 @@ func (n *notifier) sendPagerDutyNotification(serviceKey string, op notificationO
|
||||
return err
|
||||
}
|
||||
|
||||
glog.Infof("Sent PagerDuty notification: %v: HTTP %d: %s", incidentKey, resp.StatusCode, respBuf)
|
||||
log.Infof("Sent PagerDuty notification: %v: HTTP %d: %s", incidentKey, resp.StatusCode, respBuf)
|
||||
// BUG: Check response for result of operation.
|
||||
return nil
|
||||
}
|
||||
@ -227,7 +227,7 @@ func (n *notifier) sendHipChatNotification(op notificationOp, config *pb.HipChat
|
||||
return err
|
||||
}
|
||||
|
||||
glog.Infof("Sent HipChat notification: %v: HTTP %d: %s", incidentKey, resp.StatusCode, respBuf)
|
||||
log.Infof("Sent HipChat notification: %v: HTTP %d: %s", incidentKey, resp.StatusCode, respBuf)
|
||||
// BUG: Check response for result of operation.
|
||||
return nil
|
||||
}
|
||||
@ -321,7 +321,7 @@ func (n *notifier) sendSlackNotification(op notificationOp, config *pb.SlackConf
|
||||
return err
|
||||
}
|
||||
|
||||
glog.Infof("Sent Slack notification: %v: HTTP %d: %s", incidentKey, resp.StatusCode, respBuf)
|
||||
log.Infof("Sent Slack notification: %v: HTTP %d: %s", incidentKey, resp.StatusCode, respBuf)
|
||||
// BUG: Check response for result of operation.
|
||||
return nil
|
||||
}
|
||||
@ -528,14 +528,14 @@ func processResponse(r *http.Response, targetName string, a *Alert) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
glog.Infof("Sent %s. Response: HTTP %d: %s", spec, r.StatusCode, respBuf)
|
||||
log.Infof("Sent %s. Response: HTTP %d: %s", spec, r.StatusCode, respBuf)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *notifier) handleNotification(a *Alert, op notificationOp, config *pb.NotificationConfig) {
|
||||
for _, pdConfig := range config.PagerdutyConfig {
|
||||
if err := n.sendPagerDutyNotification(pdConfig.GetServiceKey(), op, a); err != nil {
|
||||
glog.Errorln("Error sending PagerDuty notification:", err)
|
||||
log.Errorln("Error sending PagerDuty notification:", err)
|
||||
}
|
||||
}
|
||||
for _, emailConfig := range config.EmailConfig {
|
||||
@ -543,11 +543,11 @@ func (n *notifier) handleNotification(a *Alert, op notificationOp, config *pb.No
|
||||
continue
|
||||
}
|
||||
if *smtpSmartHost == "" {
|
||||
glog.Warning("No SMTP smarthost configured, not sending email notification.")
|
||||
log.Warn("No SMTP smarthost configured, not sending email notification.")
|
||||
continue
|
||||
}
|
||||
if err := n.sendEmailNotification(emailConfig.GetEmail(), op, a); err != nil {
|
||||
glog.Errorln("Error sending email notification:", err)
|
||||
log.Errorln("Error sending email notification:", err)
|
||||
}
|
||||
}
|
||||
for _, poConfig := range config.PushoverConfig {
|
||||
@ -555,7 +555,7 @@ func (n *notifier) handleNotification(a *Alert, op notificationOp, config *pb.No
|
||||
continue
|
||||
}
|
||||
if err := n.sendPushoverNotification(poConfig.GetToken(), op, poConfig.GetUserKey(), a); err != nil {
|
||||
glog.Errorln("Error sending Pushover notification:", err)
|
||||
log.Errorln("Error sending Pushover notification:", err)
|
||||
}
|
||||
}
|
||||
for _, hcConfig := range config.HipchatConfig {
|
||||
@ -563,7 +563,7 @@ func (n *notifier) handleNotification(a *Alert, op notificationOp, config *pb.No
|
||||
continue
|
||||
}
|
||||
if err := n.sendHipChatNotification(op, hcConfig, a); err != nil {
|
||||
glog.Errorln("Error sending HipChat notification:", err)
|
||||
log.Errorln("Error sending HipChat notification:", err)
|
||||
}
|
||||
}
|
||||
for _, scConfig := range config.SlackConfig {
|
||||
@ -571,7 +571,7 @@ func (n *notifier) handleNotification(a *Alert, op notificationOp, config *pb.No
|
||||
continue
|
||||
}
|
||||
if err := n.sendSlackNotification(op, scConfig, a); err != nil {
|
||||
glog.Errorln("Error sending Slack notification:", err)
|
||||
log.Errorln("Error sending Slack notification:", err)
|
||||
}
|
||||
}
|
||||
for _, fdConfig := range config.FlowdockConfig {
|
||||
@ -579,7 +579,7 @@ func (n *notifier) handleNotification(a *Alert, op notificationOp, config *pb.No
|
||||
continue
|
||||
}
|
||||
if err := n.sendFlowdockNotification(op, fdConfig, a); err != nil {
|
||||
glog.Errorln("Error sending Flowdock notification:", err)
|
||||
log.Errorln("Error sending Flowdock notification:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/log"
|
||||
)
|
||||
|
||||
type SilenceID uint
|
||||
@ -136,7 +136,7 @@ func (s *Silencer) setupExpiryTimer(sc *Silence) {
|
||||
expDuration := sc.EndsAt.Sub(time.Now())
|
||||
sc.expiryTimer = time.AfterFunc(expDuration, func() {
|
||||
if err := s.DelSilence(sc.ID); err != nil {
|
||||
glog.Errorf("Failed to delete silence %d: %s", sc.ID, err)
|
||||
log.Errorf("Failed to delete silence %d: %s", sc.ID, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
//"github.com/golang/glog"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
"github.com/prometheus/alertmanager/manager"
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -51,7 +51,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
file, err := GetFile(StaticFiles, name)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
glog.Error("Could not get file: ", err)
|
||||
log.Error("Could not get file: ", err)
|
||||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
|
12
web/web.go
12
web/web.go
@ -21,8 +21,8 @@ import (
|
||||
_ "net/http/pprof"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/log"
|
||||
|
||||
"github.com/prometheus/alertmanager/web/api"
|
||||
"github.com/prometheus/alertmanager/web/blob"
|
||||
@ -75,7 +75,7 @@ func (w WebService) ServeForever(pathPrefix string) error {
|
||||
}
|
||||
http.Handle(pathPrefix+"api/", w.AlertManagerService.Handler())
|
||||
|
||||
glog.Info("listening on ", *listenAddress)
|
||||
log.Info("listening on ", *listenAddress)
|
||||
|
||||
return http.ListenAndServe(*listenAddress, nil)
|
||||
}
|
||||
@ -98,14 +98,14 @@ func getEmbeddedTemplate(name string, pathPrefix string) (*template.Template, er
|
||||
|
||||
file, err := blob.GetFile(blob.TemplateFiles, "_base.html")
|
||||
if err != nil {
|
||||
glog.Error("Could not read base template: ", err)
|
||||
log.Error("Could not read base template: ", err)
|
||||
return nil, err
|
||||
}
|
||||
t.Parse(string(file))
|
||||
|
||||
file, err = blob.GetFile(blob.TemplateFiles, name+".html")
|
||||
if err != nil {
|
||||
glog.Errorf("Could not read %s template: %s", name, err)
|
||||
log.Errorf("Could not read %s template: %s", name, err)
|
||||
return nil, err
|
||||
}
|
||||
t.Parse(string(file))
|
||||
@ -130,11 +130,11 @@ func getTemplate(name string, pathPrefix string) (t *template.Template, err erro
|
||||
func executeTemplate(w http.ResponseWriter, name string, data interface{}, pathPrefix string) {
|
||||
tpl, err := getTemplate(name, pathPrefix)
|
||||
if err != nil {
|
||||
glog.Error("Error preparing layout template: ", err)
|
||||
log.Error("Error preparing layout template: ", err)
|
||||
return
|
||||
}
|
||||
err = tpl.Execute(w, data)
|
||||
if err != nil {
|
||||
glog.Error("Error executing template: ", err)
|
||||
log.Error("Error executing template: ", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user