Merge pull request #354 from prometheus/feature/send-prom-metadata

Transfer alerting rule and Prometheus URL to alertmanager.
This commit is contained in:
juliusv 2013-08-12 03:10:17 -07:00
commit 483f2be3b3
3 changed files with 25 additions and 6 deletions

View File

@ -202,8 +202,8 @@ func main() {
}
go ruleManager.Run()
// Queue depth will need to be exposed
notificationHandler := notification.NewNotificationHandler(*alertmanagerUrl, notifications)
prometheusUrl := web.MustBuildServerUrl()
notificationHandler := notification.NewNotificationHandler(*alertmanagerUrl, prometheusUrl, notifications)
go notificationHandler.Run()
flags := map[string]string{}

View File

@ -42,6 +42,8 @@ var (
type NotificationHandler struct {
// The URL of the alert manager to send notifications to.
alertmanagerUrl string
// The URL of this Prometheus instance to include in notifications.
prometheusUrl string
// Buffer of notifications that have not yet been sent.
pendingNotifications <-chan rules.NotificationReqs
// HTTP client with custom timeout settings.
@ -49,11 +51,12 @@ type NotificationHandler struct {
}
// Construct a new NotificationHandler.
func NewNotificationHandler(alertmanagerUrl string, notificationReqs <-chan rules.NotificationReqs) *NotificationHandler {
func NewNotificationHandler(alertmanagerUrl string, prometheusUrl string, notificationReqs <-chan rules.NotificationReqs) *NotificationHandler {
return &NotificationHandler{
alertmanagerUrl: alertmanagerUrl,
pendingNotifications: notificationReqs,
httpClient: utility.NewDeadlineClient(*deadline),
prometheusUrl: prometheusUrl,
}
}
@ -70,6 +73,8 @@ func (n *NotificationHandler) sendNotifications(reqs rules.NotificationReqs) err
"Payload": map[string]interface{}{
"Value": req.ActiveAlert.Value,
"ActiveSince": req.ActiveAlert.ActiveSince,
"GeneratorUrl": n.prometheusUrl,
"AlertingRule": req.Rule.String(),
},
})
}

View File

@ -18,8 +18,10 @@ import (
"fmt"
"html/template"
"log"
"net"
"net/http"
"net/http/pprof"
"os"
"code.google.com/p/gorest"
@ -64,7 +66,7 @@ func (w WebService) ServeForever() error {
exp.HandleFunc("/graph", graphHandler)
exp.Handle("/api/", compressionHandler{handler: gorest.Handle()})
exp.Handle("/metrics.json", prometheus.DefaultHandler)
exp.Handle("/metrics", prometheus.DefaultHandler)
if *useLocalAssets {
exp.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
} else {
@ -137,3 +139,15 @@ func executeTemplate(w http.ResponseWriter, name string, data interface{}) {
log.Printf("Error executing template: %s", err)
}
}
func MustBuildServerUrl() string {
_, port, err := net.SplitHostPort(*listenAddress)
if err != nil {
panic(err)
}
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
return fmt.Sprintf("http://%s:%s", hostname, port)
}