Skip to content

Commit

Permalink
fix: nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Oct 22, 2018
1 parent 87470b7 commit ae5a815
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 61 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $ couchbase-exporter --couchbase.username adm --couchbase.password secret
- [x] export bucket metrics
- [ ] export node metrics
- [x] export cluster metrics
- [ ] provide alerting rules examples
- [ ] provide grafana dashboards (maybe use jsonnet (https://github.com/grafana/grafonnet-lib)?)
- [ ] check other TODOs
- [ ] improve metric names (add `_bytes`, `_seconds`, `_total`, etc)
Expand Down
4 changes: 2 additions & 2 deletions client/couchbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func New(url, user, password string) (Client, error) {
if err != nil {
return client, errors.Wrap(err, "failed to get node details")
}
if !strings.HasPrefix(nodes.Version, "5.") {
log.Warnf("couchbase %s is not fully supported", nodes.Version)
if !strings.HasPrefix(nodes.Nodes[0].Version, "5.") {
log.Warnf("couchbase %s is not fully supported", nodes.Nodes[0].Version)
}
return client, nil
}
Expand Down
107 changes: 52 additions & 55 deletions client/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,71 @@ package client

import "github.com/pkg/errors"

// Nodes returns the results of /nodes/self
func (c Client) Nodes() (Node, error) {
var nodes Node
err := c.get("/nodes/self", &nodes)
// Nodes returns the results of /pools/nodes
func (c Client) Nodes() (Nodes, error) {
var nodes Nodes
err := c.get("/pools/nodes", &nodes)
return nodes, errors.Wrap(err, "failed to get nodes")
}

// Node (/nodes/self)
type Node struct {
// Nodes (/pools/nodes)
type Nodes struct {
StorageTotals struct {
RAM struct {
Total int64 `json:"total"`
QuotaTotal int64 `json:"quotaTotal"`
QuotaUsed int64 `json:"quotaUsed"`
QuotaTotal int `json:"quotaTotal"`
QuotaUsed int `json:"quotaUsed"`
Used int64 `json:"used"`
UsedByData int64 `json:"usedByData"`
QuotaUsedPerNode int64 `json:"quotaUsedPerNode"`
QuotaTotalPerNode int64 `json:"quotaTotalPerNode"`
UsedByData int `json:"usedByData"`
QuotaUsedPerNode int `json:"quotaUsedPerNode"`
QuotaTotalPerNode int `json:"quotaTotalPerNode"`
} `json:"ram"`
Hdd struct {
Total int64 `json:"total"`
QuotaTotal int64 `json:"quotaTotal"`
Used int64 `json:"used"`
UsedByData int64 `json:"usedByData"`
UsedByData int `json:"usedByData"`
Free int64 `json:"free"`
} `json:"hdd"`
} `json:"storageTotals"`
SystemStats struct {
CPUUtilizationRate float64 `json:"cpu_utilization_rate"`
SwapTotal int64 `json:"swap_total"`
SwapUsed int64 `json:"swap_used"`
MemTotal int64 `json:"mem_total"`
MemFree int64 `json:"mem_free"`
} `json:"systemStats"`
InterestingStats struct {
CmdGet float64 `json:"cmd_get"`
CouchDocsActualDiskSize float64 `json:"couch_docs_actual_disk_size"`
CouchDocsDataSize float64 `json:"couch_docs_data_size"`
CouchSpatialDataSize float64 `json:"couch_spatial_data_size"`
CouchSpatialDiskSize float64 `json:"couch_spatial_disk_size"`
CouchViewsActualDiskSize float64 `json:"couch_views_actual_disk_size"`
CouchViewsDataSize float64 `json:"couch_views_data_size"`
CurrItems float64 `json:"curr_items"`
CurrItemsTot float64 `json:"curr_items_tot"`
EpBgFetched float64 `json:"ep_bg_fetched"`
GetHits float64 `json:"get_hits"`
MemUsed float64 `json:"mem_used"`
Ops float64 `json:"ops"`
VbActiveNumNonResident float64 `json:"vb_active_num_non_resident"`
VbReplicaCurrItems float64 `json:"vb_replica_curr_items"`
} `json:"interestingStats"`
MemoryTotal int64 `json:"memoryTotal"`
MemoryFree int64 `json:"memoryFree"`
McdMemoryReserved int64 `json:"mcdMemoryReserved"`
McdMemoryAllocated int64 `json:"mcdMemoryAllocated"`
CouchAPIBase string `json:"couchApiBase"`
OtpCookie string `json:"otpCookie"`
ClusterMembership string `json:"clusterMembership"`
RecoveryType string `json:"recoveryType"`
Status string `json:"status"`
OtpNode string `json:"otpNode"`
ThisNode bool `json:"thisNode"`
Hostname string `json:"hostname"`
ClusterCompatibility int `json:"clusterCompatibility"`
Version string `json:"version"`
Os string `json:"os"`
Services []string `json:"services"`
FtsMemoryQuota int `json:"ftsMemoryQuota"`
IndexMemoryQuota int `json:"indexMemoryQuota"`
MemoryQuota int `json:"memoryQuota"`
FtsMemoryQuota int `json:"ftsMemoryQuota"`
IndexMemoryQuota int `json:"indexMemoryQuota"`
MemoryQuota int `json:"memoryQuota"`
Name string `json:"name"`
Alerts []interface{} `json:"alerts"`
Nodes []struct {
SystemStats struct {
CPUUtilizationRate float64 `json:"cpu_utilization_rate"`
SwapTotal int `json:"swap_total"`
SwapUsed int `json:"swap_used"`
MemTotal int64 `json:"mem_total"`
MemFree int64 `json:"mem_free"`
} `json:"systemStats"`
InterestingStats struct {
} `json:"interestingStats"`
Uptime string `json:"uptime"`
MemoryTotal int64 `json:"memoryTotal"`
MemoryFree int64 `json:"memoryFree"`
McdMemoryReserved int `json:"mcdMemoryReserved"`
McdMemoryAllocated int `json:"mcdMemoryAllocated"`
CouchAPIBase string `json:"couchApiBase"`
OtpCookie string `json:"otpCookie"`
ClusterMembership string `json:"clusterMembership"`
RecoveryType string `json:"recoveryType"`
Status string `json:"status"`
OtpNode string `json:"otpNode"`
ThisNode bool `json:"thisNode,omitempty"`
Hostname string `json:"hostname"`
ClusterCompatibility int `json:"clusterCompatibility"`
Version string `json:"version"`
Os string `json:"os"`
} `json:"nodes"`
RebalanceStatus string `json:"rebalanceStatus"`
MaxBucketCount int `json:"maxBucketCount"`
Counters struct {
RebalanceSuccess int `json:"rebalance_success"`
RebalanceStart int `json:"rebalance_start"`
} `json:"counters"`
ClusterName string `json:"clusterName"`
Balanced bool `json:"balanced"`
}
6 changes: 3 additions & 3 deletions collector/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func (c *nodesCollector) Collect(ch chan<- prometheus.Metric) {
}
ch <- prometheus.MustNewConstMetric(c.up, prometheus.GaugeValue, 1)

// for _, node := range nodes {
log.Info(nodes.Hostname)
// }
for _, node := range nodes.Nodes {
log.Info(node.Hostname)
}

ch <- prometheus.MustNewConstMetric(c.scrapeDuration, prometheus.GaugeValue, time.Since(start).Seconds())
}
4 changes: 3 additions & 1 deletion test/rebalance
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ while true; do

sleep 60

docker exec test_cb1_1 couchbase-cli rebalance \
docker exec test_cb1_1 couchbase-cli server-add \
-c localhost -u adm -p secret \
--server-add=172.21.0.12 \
--server-add-username=adm \
--server-add-password=secret \
--services=data,index,query,fts
docker exec test_cb1_1 couchbase-cli rebalance \
-c localhost -u adm -p secret

sleep 60
done

0 comments on commit ae5a815

Please sign in to comment.