Skip to content

Commit

Permalink
notifier: use dynamic service discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
fabxc committed Nov 23, 2016
1 parent 183c574 commit f210d96
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 90 deletions.
4 changes: 2 additions & 2 deletions cmd/prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var cfg = struct {
storage local.MemorySeriesStorageOptions
localStorageEngine string
notifier notifier.Options
notifierTimeout time.Duration
queryEngine promql.EngineOptions
web web.Options
remote remote.Options
Expand Down Expand Up @@ -228,7 +229,7 @@ func init() {
"The capacity of the queue for pending alert manager notifications.",
)
cfg.fs.DurationVar(
&cfg.notifier.Timeout, "alertmanager.timeout", 10*time.Second,
&cfg.notifierTimeout, "alertmanager.timeout", 10*time.Second,
"Alert manager HTTP API timeout.",
)

Expand Down Expand Up @@ -283,7 +284,6 @@ func parse(args []string) error {
if err := validateAlertmanagerURL(u); err != nil {
return err
}
cfg.notifier.AlertmanagerURLs = cfg.alertmanagerURLs.slice()
}

cfg.remote.InfluxdbPassword = os.Getenv("INFLUXDB_PW")
Expand Down
27 changes: 27 additions & 0 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import (
"flag"
"fmt"
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
"net/url"
"os"
"os/signal"
"syscall"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
"github.com/prometheus/common/version"
"golang.org/x/net/context"

Expand Down Expand Up @@ -259,6 +261,31 @@ func reloadConfig(filename string, rls ...Reloadable) (err error) {
return fmt.Errorf("couldn't load configuration (-config.file=%s): %v", filename, err)
}

// Add AlertmanagerConfigs for legacy Alertmanager URL flags.
for us := range cfg.alertmanagerURLs {
u, err := url.Parse(us)
if err != nil {
return err
}
acfg := &config.AlertmanagersConfig{
Scheme: u.Scheme,
PathPrefix: u.Path,
Timeout: cfg.notifierTimeout,
ServiceDiscoveryConfig: config.ServiceDiscoveryConfig{
StaticConfigs: []*config.TargetGroup{
{
Targets: []model.LabelSet{
{
model.AddressLabel: model.LabelValue(u.Host),
},
},
},
},
},
}
conf.AlertingConfig.AlertmanagersConfigs = append(conf.AlertingConfig.AlertmanagersConfigs, acfg)
}

failed := false
for _, rl := range rls {
if err := rl.ApplyConfig(conf); err != nil {
Expand Down
Loading

0 comments on commit f210d96

Please sign in to comment.