这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions cmd/bosun/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"bosun.org/_third_party/github.com/MiniProfiler/go/miniprofiler"
"bosun.org/_third_party/github.com/influxdb/influxdb/client"
"bosun.org/cmd/bosun/conf/parse"
"bosun.org/cmd/bosun/expr"
eparse "bosun.org/cmd/bosun/expr/parse"
Expand Down Expand Up @@ -61,7 +62,7 @@ type Conf struct {
GraphiteHost string // Graphite query host: foo.bar.baz
GraphiteHeaders []string // extra http headers when querying graphite.
LogstashElasticHosts expr.LogstashElasticHosts // CSV Elastic Hosts (All part of the same cluster) that stores logstash documents, i.e http://ny-elastic01:9200
InfluxHost string
InfluxConfig client.Config

tree *parse.Tree
node parse.Node
Expand Down Expand Up @@ -412,7 +413,31 @@ func (c *Conf) loadGlobal(p *parse.PairNode) {
case "logstashElasticHosts":
c.LogstashElasticHosts = strings.Split(v, ",")
case "influxHost":
c.InfluxHost = v
c.InfluxConfig.URL.Host = v
c.InfluxConfig.UserAgent = "bosun"
// Default scheme to non-TLS
c.InfluxConfig.URL.Scheme = "http"
case "influxUsername":
c.InfluxConfig.Username = v
case "influxPassword":
c.InfluxConfig.Password = v
case "influxTLS":
b, err := strconv.ParseBool(v)
if err != nil {
c.error(err)
}
if b {
c.InfluxConfig.URL.Scheme = "https"
} else {
c.InfluxConfig.URL.Scheme = "http"
}
case "influxTimeout":
od, err := opentsdb.ParseDuration(v)
if err != nil {
c.error(err)
}
d := time.Duration(od)
c.InfluxConfig.Timeout = d
case "httpListen":
c.HTTPListen = v
case "hostname":
Expand Down Expand Up @@ -1281,7 +1306,7 @@ func (c *Conf) Funcs() map[string]eparse.Func {
if len(c.LogstashElasticHosts) != 0 {
merge(expr.LogstashElastic)
}
if c.InfluxHost != "" {
if c.InfluxConfig.URL.Host != "" {
merge(expr.Influx)
}
return funcs
Expand Down
7 changes: 4 additions & 3 deletions cmd/bosun/expr/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"bosun.org/_third_party/github.com/MiniProfiler/go/miniprofiler"
"bosun.org/_third_party/github.com/influxdb/influxdb/client"
"bosun.org/_third_party/github.com/olivere/elastic"
"bosun.org/cmd/bosun/cache"
"bosun.org/cmd/bosun/expr/parse"
Expand Down Expand Up @@ -41,7 +42,7 @@ type State struct {
logstashHosts LogstashElasticHosts

// InfluxDB
InfluxHost string
InfluxConfig client.Config

History AlertStatusProvider
}
Expand Down Expand Up @@ -76,7 +77,7 @@ func New(expr string, funcs ...map[string]parse.Func) (*Expr, error) {

// Execute applies a parse expression to the specified OpenTSDB context, and
// returns one result per group. T may be nil to ignore timings.
func (e *Expr) Execute(c opentsdb.Context, g graphite.Context, l LogstashElasticHosts, influxHost string, cache *cache.Cache, T miniprofiler.Timer, now time.Time, autods int, unjoinedOk bool, search *search.Search, squelched func(tags opentsdb.TagSet) bool, history AlertStatusProvider) (r *Results, queries []opentsdb.Request, err error) {
func (e *Expr) Execute(c opentsdb.Context, g graphite.Context, l LogstashElasticHosts, influxConfig client.Config, cache *cache.Cache, T miniprofiler.Timer, now time.Time, autods int, unjoinedOk bool, search *search.Search, squelched func(tags opentsdb.TagSet) bool, history AlertStatusProvider) (r *Results, queries []opentsdb.Request, err error) {
if squelched == nil {
squelched = func(tags opentsdb.TagSet) bool {
return false
Expand All @@ -88,7 +89,7 @@ func (e *Expr) Execute(c opentsdb.Context, g graphite.Context, l LogstashElastic
tsdbContext: c,
graphiteContext: g,
logstashHosts: l,
InfluxHost: influxHost,
InfluxConfig: influxConfig,
now: now,
autods: autods,
unjoinedOk: unjoinedOk,
Expand Down
5 changes: 3 additions & 2 deletions cmd/bosun/expr/expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

"bosun.org/_third_party/github.com/influxdb/influxdb/client"
"bosun.org/opentsdb"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ func TestExprSimple(t *testing.T) {
t.Error(err)
break
}
r, _, err := e.Execute(nil, nil, nil, "", nil, nil, time.Now(), 0, false, nil, nil, nil)
r, _, err := e.Execute(nil, nil, nil, client.Config{}, nil, nil, time.Now(), 0, false, nil, nil, nil)
if err != nil {
t.Error(err)
break
Expand Down Expand Up @@ -204,7 +205,7 @@ func TestQueryExpr(t *testing.T) {
if err != nil {
t.Fatal(err)
}
results, _, err := e.Execute(opentsdb.Host(u.Host), nil, nil, "", nil, nil, queryTime, 0, false, nil, nil, nil)
results, _, err := e.Execute(opentsdb.Host(u.Host), nil, nil, client.Config{}, nil, nil, queryTime, 0, false, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 1 addition & 9 deletions cmd/bosun/expr/influx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package expr
import (
"encoding/json"
"fmt"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -159,14 +158,7 @@ func timeInfluxRequest(e *State, T miniprofiler.Timer, db, query, startDuration,
if err != nil {
return nil, err
}
conf := client.Config{
URL: url.URL{
Scheme: "http",
Host: e.InfluxHost,
},
Timeout: time.Minute,
}
conn, err := client.NewClient(conf)
conn, err := client.NewClient(e.InfluxConfig)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/bosun/expr/influx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"bosun.org/_third_party/github.com/MiniProfiler/go/miniprofiler"
"bosun.org/_third_party/github.com/influxdb/influxdb/client"
"bosun.org/opentsdb"
)

Expand Down Expand Up @@ -46,8 +47,8 @@ func TestInfluxQueryDuration(t *testing.T) {

func TestInfluxQuery(t *testing.T) {
e := State{
now: time.Date(2015, time.February, 25, 0, 0, 0, 0, time.UTC),
InfluxHost: "nonexistant:8086",
now: time.Date(2015, time.February, 25, 0, 0, 0, 0, time.UTC),
InfluxConfig: client.Config{},
squelched: func(tags opentsdb.TagSet) bool {
return false
},
Expand Down
7 changes: 4 additions & 3 deletions cmd/bosun/sched/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"bosun.org/_third_party/github.com/MiniProfiler/go/miniprofiler"
"bosun.org/_third_party/github.com/influxdb/influxdb/client"
"bosun.org/cmd/bosun/cache"
"bosun.org/cmd/bosun/conf"
"bosun.org/cmd/bosun/expr"
Expand Down Expand Up @@ -74,7 +75,7 @@ type RunHistory struct {
Start time.Time
Context opentsdb.Context
GraphiteContext graphite.Context
InfluxHost string
InfluxConfig client.Config
Logstash expr.LogstashElasticHosts
Events map[expr.AlertKey]*Event
schedule *Schedule
Expand All @@ -95,7 +96,7 @@ func (s *Schedule) NewRunHistory(start time.Time, cache *cache.Cache) *RunHistor
Events: make(map[expr.AlertKey]*Event),
Context: s.Conf.TSDBContext(),
GraphiteContext: s.Conf.GraphiteContext(),
InfluxHost: s.Conf.InfluxHost,
InfluxConfig: s.Conf.InfluxConfig,
Logstash: s.Conf.LogstashElasticHosts,
schedule: s,
}
Expand Down Expand Up @@ -502,7 +503,7 @@ func (s *Schedule) executeExpr(T miniprofiler.Timer, rh *RunHistory, a *conf.Ale
if e == nil {
return nil, nil
}
results, _, err := e.Execute(rh.Context, rh.GraphiteContext, rh.Logstash, rh.InfluxHost, rh.Cache, T, rh.Start, 0, a.UnjoinedOK, s.Search, s.Conf.AlertSquelched(a), rh)
results, _, err := e.Execute(rh.Context, rh.GraphiteContext, rh.Logstash, rh.InfluxConfig, rh.Cache, T, rh.Start, 0, a.UnjoinedOK, s.Search, s.Conf.AlertSquelched(a), rh)
return results, err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/bosun/sched/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (c *Context) evalExpr(e *expr.Expr, filter bool, series bool, autods int) (
if series && e.Root.Return() != parse.TypeSeriesSet {
return nil, "", fmt.Errorf("need a series, got %T (%v)", e, e)
}
res, _, err := e.Execute(c.runHistory.Context, c.runHistory.GraphiteContext, c.runHistory.Logstash, c.runHistory.InfluxHost, c.runHistory.Cache, nil, c.runHistory.Start, autods, c.Alert.UnjoinedOK, c.schedule.Search, c.schedule.Conf.AlertSquelched(c.Alert), c.runHistory)
res, _, err := e.Execute(c.runHistory.Context, c.runHistory.GraphiteContext, c.runHistory.Logstash, c.runHistory.InfluxConfig, c.runHistory.Cache, nil, c.runHistory.Start, autods, c.Alert.UnjoinedOK, c.schedule.Search, c.schedule.Conf.AlertSquelched(c.Alert), c.runHistory)
if err != nil {
return nil, "", fmt.Errorf("%s: %v", e, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bosun/web/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func ExprGraph(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (in
tsdbContext := schedule.Conf.TSDBContext()
graphiteContext := schedule.Conf.GraphiteContext()
ls := schedule.Conf.LogstashElasticHosts
influx := schedule.Conf.InfluxHost
influx := schedule.Conf.InfluxConfig
res, _, err := e.Execute(tsdbContext, graphiteContext, ls, influx, cacheObj, t, now, autods, false, schedule.Search, nil, nil)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/bosun/web/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func Expr(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (v inter
tsdbContext := schedule.Conf.TSDBContext()
graphiteContext := schedule.Conf.GraphiteContext()
ls := schedule.Conf.LogstashElasticHosts
influx := schedule.Conf.InfluxHost
influx := schedule.Conf.InfluxConfig
res, queries, err := e.Execute(tsdbContext, graphiteContext, ls, influx, cacheObj, t, now, 0, false, schedule.Search, nil, nil)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Every variable is optional, though you should enable at least 1 backend.
* graphiteHeader: a http header to be sent to graphite on each request in 'key:value' format. optional. can be specified multiple times.
* logstashElasticHosts: Elasticsearch host populated by logstash. Must be a URL.
* influxHost: InfluxDB host address ip:port pair.
* influxUsername: InfluxDB username. If empty will attempt to connect without authentication.
* influxPassword: InfluxDB password. If empty will attempt to connect without authentication.
* influxTLS: Whether to use TLS when connecting to InfluxDB. Default is false.
* influxTimeout: Timeout duration for connections to InfluxDB.

#### settings

Expand Down