Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adel Abdelhak committed Dec 9, 2018
2 parents 989c988 + b506f86 commit 8aed202
Show file tree
Hide file tree
Showing 21 changed files with 2,691 additions and 1,617 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ LABEL maintainer="Adel Abdelhak"

ENV CB_EXPORTER_LISTEN_ADDR=9191 \
CB_EXPORTER_TELEMETRY_PATH=/metrics \
CB_EXPORTER_SERVER_TIMEOUT=10 \
CB_EXPORTER_DB_URI=http://127.0.0.1:8091 \
CB_EXPORTER_DB_TIMEOUT=10 \
CB_EXPORTER_DB_USER=admin \
CB_EXPORTER_DB_PASSWORD=password \
CB_EXPORTER_LOG_LEVEL=info \
Expand Down
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
[![Coverage Status](https://coveralls.io/repos/github/blakelead/couchbase_exporter/badge.svg?branch=master)](https://coveralls.io/github/blakelead/couchbase_exporter?branch=master)
[![Software License](https://img.shields.io/badge/license-MIT-green.svg)](/LICENSE.txt)

Expose metrics from *Couchbase Community 4.5.1 and 5.1.1* cluster for consumption by Prometheus.

## Disclaimer

Couchbase exporter is in its early stage. I'll add new features constantly at the cost of breaking things often. Your are welcome to contribute by creating issues or making pull requests.
Expose metrics from Couchbase cluster for consumption by Prometheus.

## Getting Started

Expand All @@ -20,24 +16,26 @@ Run from command line:

The exporter supports various configuration ways: command line arguments takes precedence over environment variables that take precedence over configuration file.

Configuration file can be written in json or yaml, must be named `config.json` or `config.yml`, and must be placed in the same directory that the exporter binary. You can find complete examples of configuation files in the sources.

As for available flags and equivalent environment, here is a list:

| environment variable | argument | description | default |
| -------------------------- | ------------------- | ---------------------------------------- | --------------------- |
| CB_EXPORTER_LISTEN_ADDR | -web.listen-address | Address to listen on for HTTP requests | :9191 |
| CB_EXPORTER_TELEMETRY_PATH | -web.telemetry-path | Path under which to expose metrics | /metrics |
| CB_EXPORTER_DB_URI | -db.uri | Address of Couchbase cluster | http://127.0.0.1:8091 |
| CB_EXPORTER_DB_USER | | Administrator username | |
| CB_EXPORTER_DB_PASSWORD | | Administrator password | |
| CB_EXPORTER_LOG_LEVEL | -log.level | Log level: info,debug,warn,error,fatal | info |
| CB_EXPORTER_LOG_FORMAT | -log.format | Log format: text, json | text |
| CB_EXPORTER_SCRAPE_CLUSTER | -scrape.cluster | If false, wont scrape cluster metrics | true |
| CB_EXPORTER_SCRAPE_NODE | -scrape.node | If false, wont scrape node metrics | true |
| CB_EXPORTER_SCRAPE_BUCKET | -scrape.bucket | If false, wont scrape bucket metrics | true |
| CB_EXPORTER_SCRAPE_XDCR | -scrape.xdcr | If false, wont scrape xdcr metrics | true |
| | -help | Command line help | |
Configuration file can be written in json or yaml, must be named `config.json` or `config.yml`, and must be placed in the same directory that the exporter binary. You can find complete examples of configuation files in the sources (directory `examples`).

As for available flags and equivalent environment variables, here is a list:

| environment variable | argument | description | default |
| -------------------------- | ------------------- | -------------------------------------- | --------------------- |
| CB_EXPORTER_LISTEN_ADDR | -web.listen-address | Address to listen on for HTTP requests | :9191 |
| CB_EXPORTER_TELEMETRY_PATH | -web.telemetry-path | Path under which to expose metrics | /metrics |
| CB_EXPORTER_SERVER_TIMEOUT | -web.timeout | Server read timeout in seconds | 10s |
| CB_EXPORTER_DB_URI | -db.uri | Address of Couchbase cluster | http://127.0.0.1:8091 |
| CB_EXPORTER_DB_TIMEOUT | -db.timeout | Couchbase client timeout in seconds | 10s |
| CB_EXPORTER_DB_USER | *not allowed* | Administrator username | |
| CB_EXPORTER_DB_PASSWORD | *not allowed* | Administrator password | |
| CB_EXPORTER_LOG_LEVEL | -log.level | Log level: info,debug,warn,error,fatal | info |
| CB_EXPORTER_LOG_FORMAT | -log.format | Log format: text, json | text |
| CB_EXPORTER_SCRAPE_CLUSTER | -scrape.cluster | If false, wont scrape cluster metrics | true |
| CB_EXPORTER_SCRAPE_NODE | -scrape.node | If false, wont scrape node metrics | true |
| CB_EXPORTER_SCRAPE_BUCKET | -scrape.bucket | If false, wont scrape bucket metrics | true |
| CB_EXPORTER_SCRAPE_XDCR | -scrape.xdcr | If false, wont scrape xdcr metrics | false |
| | -help | Command line help | |

> Important: for security reasons credentials cannot be set with command line arguments.
Expand Down Expand Up @@ -342,8 +340,8 @@ As for available flags and equivalent environment, here is a list:

### XDCR metrics

| name | description |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| name | description |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- |
| cb_xdcr_bandwidth_usage | Bandwidth used during replication, measured in bytes per second |
| cb_xdcr_changes_left | Number of updates still pending replication |
| cb_xdcr_data_replicated | Size of data replicated in bytes |
Expand All @@ -363,6 +361,7 @@ As for available flags and equivalent environment, here is a list:
| cb_xdcr_time_committing | Seconds elapsed during replication |
| cb_xdcr_wtavg_docs_latency | Weighted average latency for sending replicated changes to destination cluster |
| cb_xdcr_wtavg_meta_latency | Weighted average time for requesting document metadata |
| cb_xdcr_percent_completeness | Percentage of checked items out of all checked and to-be-replicated items |

## Docker

Expand Down
2 changes: 1 addition & 1 deletion collector/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type BucketExporter struct {

// NewBucketExporter instantiates the Exporter with the URI and metrics.
func NewBucketExporter(context Context) (*BucketExporter, error) {
bucketMetrics, err := GetMetricsFromFile("bucket", context.CouchbaseVersion)
bucketMetrics, err := GetMetricsFromFile("bucket")
if err != nil {
return &BucketExporter{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion collector/bucketstatsdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ type BucketStatsExporter struct {

// NewBucketStatsExporter instantiates the Exporter with the URI and metrics.
func NewBucketStatsExporter(context Context) (*BucketStatsExporter, error) {
bucketStatsMetrics, err := GetMetricsFromFile("bucketstats", context.CouchbaseVersion)
bucketStatsMetrics, err := GetMetricsFromFile("bucketstats")
if err != nil {
return &BucketStatsExporter{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion collector/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type ClusterExporter struct {

// NewClusterExporter instantiates the Exporter with the URI and metrics.
func NewClusterExporter(context Context) (*ClusterExporter, error) {
clusterMetrics, err := GetMetricsFromFile("cluster", context.CouchbaseVersion)
clusterMetrics, err := GetMetricsFromFile("cluster")
if err != nil {
return &ClusterExporter{}, err
}
Expand Down
33 changes: 16 additions & 17 deletions collector/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type Metrics struct {

// Context is a custom url wrapper with credentials
type Context struct {
URI string
Username string
Password string
CouchbaseVersion string
URI string
Username string
Password string
Timeout time.Duration
}

// Exporters regroups all exporters structs
Expand Down Expand Up @@ -104,7 +104,7 @@ func Fetch(context Context, route string) ([]byte, error) {
return []byte{}, err
}
req.SetBasicAuth(context.Username, context.Password)
client := http.Client{Timeout: 10 * time.Second}
client := http.Client{Timeout: context.Timeout}
res, err := client.Do(req)
if err != nil {
log.Error(err.Error())
Expand Down Expand Up @@ -159,30 +159,29 @@ func MultiFetch(context Context, routes []string) map[string][]byte {
}

// GetMetricsFromFile checks if metric file exist and convert it to Metrics structure
func GetMetricsFromFile(metricType string, cbVersion string) (Metrics, error) {
ex, err := os.Executable()
func GetMetricsFromFile(metricType string) (Metrics, error) {
absPath, err := os.Executable()
if err != nil {
log.Fatal(err.Error())
log.Error("An unknown error occurred: ", err)
return Metrics{}, err
}
exPath := filepath.Dir(ex)
filename := exPath + "/metrics/" + metricType + "-"
if _, err := os.Stat(filename + cbVersion + ".json"); err == nil {
filename = filename + cbVersion + ".json"
} else {
filename = filename + "default.json"
filename := filepath.Dir(absPath) + string(os.PathSeparator) + "metrics" + string(os.PathSeparator) + metricType + ".json"
if _, err := os.Stat(filename); err != nil {
log.Error("Could not find metrics file ", filename)
return Metrics{}, err
}
rawMetrics, err := ioutil.ReadFile(filename)
if err != nil {
log.Error("Could not read file " + filename)
log.Error("Could not read file ", filename)
return Metrics{}, err
}
var metrics Metrics
err = json.Unmarshal(rawMetrics, &metrics)
if err != nil {
log.Error("Could not unmarshal file " + filename)
log.Error("Could not unmarshal file ", filename)
return Metrics{}, err
}
log.Debug(filename + " loaded")
log.Debug(filename, " loaded")
return metrics, nil
}

Expand Down
2 changes: 1 addition & 1 deletion collector/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type NodeExporter struct {

// NewNodeExporter instantiates the Exporter with the URI and metrics.
func NewNodeExporter(context Context) (*NodeExporter, error) {
nodeMetrics, err := GetMetricsFromFile("node", context.CouchbaseVersion)
nodeMetrics, err := GetMetricsFromFile("node")
if err != nil {
return &NodeExporter{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion collector/xdcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type XDCRExporter struct {

// NewXDCRExporter instantiates the Exporter with the URI and metrics.
func NewXDCRExporter(context Context) (*XDCRExporter, error) {
xdcrMetrics, err := GetMetricsFromFile("xdcr", context.CouchbaseVersion)
xdcrMetrics, err := GetMetricsFromFile("xdcr")
if err != nil {
return &XDCRExporter{}, err
}
Expand Down
Loading

0 comments on commit 8aed202

Please sign in to comment.