Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a flag to ignore replications updated_on #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 14 additions & 9 deletions couchdb-exporter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"fmt"
goflag "flag"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/gesellix/couchdb-prometheus-exporter/glogadapt"
"github.com/gesellix/couchdb-prometheus-exporter/lib"
"github.com/golang/glog"
Expand All @@ -15,13 +16,14 @@ import (
)

type exporterConfigType struct {
listenAddress string
metricsEndpoint string
couchdbURI string
couchdbUsername string
couchdbPassword string
couchdbInsecure bool
databases string
listenAddress string
metricsEndpoint string
couchdbURI string
couchdbUsername string
couchdbPassword string
couchdbInsecure bool
couchdbReplsUpdate bool
databases string
}

var exporterConfig exporterConfigType
Expand All @@ -34,6 +36,7 @@ func init() {
flag.StringVar(&exporterConfig.couchdbUsername, "couchdb.username", "", "Basic auth username for the CouchDB instance")
flag.StringVar(&exporterConfig.couchdbPassword, "couchdb.password", "", "Basic auth password for the CouchDB instance")
flag.BoolVar(&exporterConfig.couchdbInsecure, "couchdb.insecure", true, "Ignore server certificate if using https")
flag.BoolVar(&exporterConfig.couchdbReplsUpdate, "couchdb.replsupdate", true, "Report on each replication task's updated_on.")
flag.StringVar(&exporterConfig.databases, "databases", "", "Comma separated list of database names")

flag.BoolVar(&glogadapt.Logging.ToStderr, "logtostderr", false, "log to standard error instead of files")
Expand Down Expand Up @@ -63,7 +66,9 @@ func main() {
Username: *&exporterConfig.couchdbUsername,
Password: *&exporterConfig.couchdbPassword},
databases,
*&exporterConfig.couchdbInsecure)
*&exporterConfig.couchdbInsecure,
*&exporterConfig.couchdbReplsUpdate,
)
prometheus.MustRegister(exporter)

http.Handle(*&exporterConfig.metricsEndpoint, promhttp.Handler())
Expand Down
2 changes: 1 addition & 1 deletion lib/collector-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (e *Exporter) collectV2(stats Stats, exposedHttpStatusCodes []string, datab

activeTasksByNode := make(map[string]ActiveTaskTypes)
for _, task := range stats.ActiveTasksResponse {
if task.Type == "replication" {
if e.replsUpdate && task.Type == "replication" {
e.activeTasksReplicationLastUpdate.WithLabelValues(
task.Node,
task.DocId,
Expand Down
14 changes: 8 additions & 6 deletions lib/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const (
)

type Exporter struct {
client *CouchdbClient
databases []string
mutex sync.RWMutex
client *CouchdbClient
databases []string
replsUpdate bool
mutex sync.RWMutex

up prometheus.Gauge
nodeUp *prometheus.GaugeVec
Expand Down Expand Up @@ -47,11 +48,12 @@ type Exporter struct {
activeTasksReplicationLastUpdate *prometheus.GaugeVec
}

func NewExporter(uri string, basicAuth BasicAuth, databases []string, insecure bool) *Exporter {
func NewExporter(uri string, basicAuth BasicAuth, databases []string, insecure, replsUpdate bool) *Exporter {

return &Exporter{
client: NewCouchdbClient(uri, basicAuth, insecure),
databases: databases,
client: NewCouchdbClient(uri, basicAuth, insecure),
databases: databases,
replsUpdate: replsUpdate,

up: prometheus.NewGauge(
prometheus.GaugeOpts{
Expand Down