diff --git a/lib/couchdb-client.go b/lib/couchdb-client.go index c3ee9fc2..794a623d 100644 --- a/lib/couchdb-client.go +++ b/lib/couchdb-client.go @@ -32,6 +32,39 @@ type MembershipResponse struct { ClusterNodes []string `json:"cluster_nodes"` } +func (c *CouchdbClient) getHealthByNodeName(urisByNodeName map[string]string) (map[string]HealthResponse, error) { + healthByNodeName := make(map[string]HealthResponse) + for name, uri := range urisByNodeName { + var health HealthResponse + + // Instead of http://localhost:15984/_node/couchdb@172.16.238.13/_up + // we have to request http://localhost:15984/_up, + // but how do we find the correct base uris, say: ip and port, for each node? + data, err := c.Request("GET", fmt.Sprintf("%s/_up", uri), nil) + if err != nil { + err = fmt.Errorf("error reading couchdb health: %v", err) + //if !strings.Contains(err.Error(), "\"error\":\"nodedown\"") { + // return nil, err + //} + klog.Error(fmt.Errorf("continuing despite error: %v", err)) + continue + } + + err = json.Unmarshal(data, &health) + if err != nil { + return nil, fmt.Errorf("error unmarshalling health: %v", err) + } + + healthByNodeName[name] = health + } + + if len(urisByNodeName) == 0 { + return nil, fmt.Errorf("all nodes down") + } + + return healthByNodeName, nil +} + func (c *CouchdbClient) getNodeInfo(uri string) (NodeInfo, error) { data, err := c.Request("GET", fmt.Sprintf("%s/", uri), nil) if err != nil { @@ -179,6 +212,10 @@ func (c *CouchdbClient) getStats(config CollectorConfig) (Stats, error) { if err != nil { return Stats{}, err } + //nodeHealth, err := c.getHealthByNodeName(urisByNode) + //if err != nil { + // return Stats{}, err + //} nodeStats, err := c.getStatsByNodeName(urisByNode) if err != nil { return Stats{}, err @@ -211,6 +248,7 @@ func (c *CouchdbClient) getStats(config CollectorConfig) (Stats, error) { } return Stats{ + //HealthByNodeName: nodeHealth, StatsByNodeName: nodeStats, DatabasesTotal: len(databasesList), DatabaseStatsByDbName: databaseStats, diff --git a/lib/couchdb-stats.go b/lib/couchdb-stats.go index 27726f10..f44aa037 100644 --- a/lib/couchdb-stats.go +++ b/lib/couchdb-stats.go @@ -126,6 +126,12 @@ type CouchReplicator struct { Connection map[string]Counter `json:"connection"` } +type HealthResponse struct { + Status string `json:"status"` + // see https://github.com/apache/couchdb/pull/1658 + //Seeds map[string]SeedStat `json:"seeds"` +} + type StatsResponse struct { Couchdb CouchdbStats `json:"couchdb"` Up float64 `json:"-"` @@ -229,6 +235,7 @@ type SystemResponse struct { } type Stats struct { + //HealthByNodeName map[string]HealthResponse StatsByNodeName map[string]StatsResponse DatabasesTotal int DatabaseStatsByDbName DatabaseStatsByDbName