Skip to content

Commit

Permalink
https://github.com/lelvisl/couchbase_exporter/issues/9
Browse files Browse the repository at this point in the history
  • Loading branch information
lelvisl committed Mar 10, 2018
1 parent c3180b9 commit 19ba547
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
32 changes: 32 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"io/ioutil"

yaml "gopkg.in/yaml.v2"
)

type config struct {
node struct {
auth string
urls []string
name string
}
web struct {
listenAddress string `yaml:listen-address`
metricURI string `yaml:telemetry-path`
}
}

func configure(filePath string) (config, error) {
var c config
file, err := ioutil.ReadFile(filePath)
if err != nil {
return c, err
}
err = yaml.Unmarshal(file, &c)
if err != nil {
return c, err
}
return c, nil
}
9 changes: 9 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node:
auth: user:password
urls:
- http://localhost:8091
- http://localhost:8092
name: some_name
web:
listen-address: :9131
telemetry-path: /metrics
26 changes: 14 additions & 12 deletions couchbase_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ import (
)

var (
listenAddress = flag.String("web.listen-address", ":9131", "Address to listen on for web interface and telemetry.")
metricUri = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
nodeName = flag.String("node.name", "", "Hostname to filter node metrics.")
nodeURL = flag.String("node.url", "http://localhost:8091", "DB Url")
nodeAuth = flag.String("node.auth", "", "Couchbase auth - login:password")
Version = flag.Bool("version", false, "show version")
configPath = flag.String("config", "./config.yml", "Config")
Version = flag.Bool("version", false, "show version")
)

func main() {
var login, password string
flag.Parse()

prometheus.Register(ReplicaNumber)
prometheus.Register(Stats)
prometheus.Register(Quota)
Expand All @@ -40,16 +37,21 @@ func main() {
fmt.Println(version.Show())
os.Exit(0)
}
c, err := configure(*configPath)
if err != nil {
log.Println("Configure err: %s", err.Error())
os.Exit(2)
}

if len(*nodeAuth) > 0 {
login = strings.Split(*nodeAuth, ":")[0]
password = strings.Split(*nodeAuth, ":")[1]
if len(c.node.auth) > 0 {
login = strings.Split(c.node.auth, ":")[0]
password = strings.Split(c.node.auth, ":")[1]
} else {
flag.PrintDefaults()
os.Exit(254)
}
couchCluster := cbmgr.New(login, password)
couchCluster.SetEndpoints([]string{*nodeURL})
couchCluster.SetEndpoints(c.node.urls)
go func() {
for {
getBucketStats(couchCluster)
Expand All @@ -59,9 +61,9 @@ func main() {
}
}()

http.Handle("/metrics", promhttp.Handler())
http.Handle(c.web.metricURI, promhttp.Handler())
server := &http.Server{
Addr: *listenAddress,
Addr: c.web.listenAddress,
}

signals := make(chan os.Signal, 1)
Expand Down

0 comments on commit 19ba547

Please sign in to comment.