From 2f83643bef70aab66bb8fe62dd8206e040f6c473 Mon Sep 17 00:00:00 2001 From: Dmitry Medvedev Date: Mon, 27 Jul 2015 19:14:39 +0300 Subject: [PATCH] cmd/scollector: riak allow custom URL --- cmd/scollector/collectors/riak.go | 26 +++++++++++++++++++++++--- cmd/scollector/conf/conf.go | 5 +++++ cmd/scollector/doc.go | 6 ++++++ cmd/scollector/main.go | 3 +++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/cmd/scollector/collectors/riak.go b/cmd/scollector/collectors/riak.go index 2702c34c16..b99aec5a91 100644 --- a/cmd/scollector/collectors/riak.go +++ b/cmd/scollector/collectors/riak.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/url" "strings" "bosun.org/metadata" @@ -460,16 +461,35 @@ func init() { } const ( - riakURL string = "http://localhost:8098/stats" + localRiakURL string = "http://localhost:8098/stats" ) +func Riak(s string) error { + u, err := url.Parse(s) + if err != nil { + return err + } + collectors = append(collectors, + &IntervalCollector{ + F: func() (opentsdb.MultiDataPoint, error) { + return riak(s) + }, + name: fmt.Sprintf("riak-%s", u.Host), + }) + return nil +} + func enableRiak() bool { - return enableURL(riakURL)() + return enableURL(localRiakURL)() } func c_riak() (opentsdb.MultiDataPoint, error) { + return riak(localRiakURL) +} + +func riak(s string) (opentsdb.MultiDataPoint, error) { var md opentsdb.MultiDataPoint - res, err := http.Get(riakURL) + res, err := http.Get(s) if err != nil { return nil, err } diff --git a/cmd/scollector/conf/conf.go b/cmd/scollector/conf/conf.go index 76b01febd3..f7cf08e1cc 100644 --- a/cmd/scollector/conf/conf.go +++ b/cmd/scollector/conf/conf.go @@ -42,6 +42,7 @@ type Conf struct { Process []ProcessParams ProcessDotNet []ProcessDotNet HTTPUnit []HTTPUnit + Riak []Riak } type HAProxy struct { @@ -112,3 +113,7 @@ type HTTPUnit struct { TOML string Hiera string } + +type Riak struct { + URL string +} diff --git a/cmd/scollector/doc.go b/cmd/scollector/doc.go index 328c9dd3df..ed77e754f8 100644 --- a/cmd/scollector/doc.go +++ b/cmd/scollector/doc.go @@ -202,6 +202,7 @@ AWS (array of table, keys are AccessKey, SecretKey, Region): AWS hosts to poll. SecretKey = "snch0d" Region = "somewhere" + Process (array of table, keys are Command, Name, Args for Linux, and Name for Windows): processes to monitor. Name is optional, and defaults to Command. @@ -238,6 +239,11 @@ or just one. [[HTTPUnit]] TOML = "/some/other.toml" +Riak (array of table, keys are URL): Riak hosts to poll. + + [[Riak]] + URL = "http://localhost:8098/stats" + Windows scollector has full Windows support. It can be run standalone, or installed as a diff --git a/cmd/scollector/main.go b/cmd/scollector/main.go index 7200937098..c57d4bc3cf 100644 --- a/cmd/scollector/main.go +++ b/cmd/scollector/main.go @@ -128,6 +128,9 @@ func main() { check(collectors.HTTPUnitHiera(h.Hiera)) } } + for _, r := range conf.Riak { + check(collectors.Riak(r.URL)) + } if err != nil { slog.Fatal(err) }