Skip to content

Commit

Permalink
Add new metric for "changes_pending" from /_active_tasks
Browse files Browse the repository at this point in the history
Relates to #110
  • Loading branch information
gesellix committed Feb 6, 2022
1 parent 6fb6c15 commit 7ad2416
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 deletions.
6 changes: 3 additions & 3 deletions couchdb-exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ func performCouchdbStatsTest(t *testing.T, couchdbVersion string, expectedMetric
}

func TestCouchdbStatsV1(t *testing.T) {
performCouchdbStatsTest(t, "v1", 58, 4711, 12396, 11)
performCouchdbStatsTest(t, "v1", 59, 4711, 12396, 11)
}

func TestCouchdbStatsV2(t *testing.T) {
performCouchdbStatsTest(t, "v2", 306, 4712, 58570, 17)
performCouchdbStatsTest(t, "v2", 307, 4712, 58570, 17)
}

func TestCouchdbStatsV2Prerelease(t *testing.T) {
performCouchdbStatsTest(t, "v2-pre", 294, 4712, 58570, 17)
performCouchdbStatsTest(t, "v2-pre", 295, 4712, 58570, 17)
}

func TestCouchdbStatsV1Integration(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions lib/collector-v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func (e *Exporter) collectV1(stats Stats, exposedHttpStatusCodes []string, colle
strconv.FormatBool(task.Continuous),
task.Source,
task.Target).Set(task.UpdatedOn)
e.activeTasksReplicationChangesPending.WithLabelValues(
task.Node,
task.DocId,
strconv.FormatBool(task.Continuous),
task.Source,
task.Target).Set(float64(task.ChangesPending))
}

if _, ok := activeTasksByNode[task.Node]; !ok {
Expand Down
6 changes: 6 additions & 0 deletions lib/collector-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ func (e *Exporter) collectV2(stats Stats, exposedHttpStatusCodes []string, colle
strconv.FormatBool(task.Continuous),
task.Source,
task.Target).Set(task.UpdatedOn)
e.activeTasksReplicationChangesPending.WithLabelValues(
task.Node,
task.DocId,
strconv.FormatBool(task.Continuous),
task.Source,
task.Target).Set(float64(task.ChangesPending))
}

if _, ok := activeTasksByNode[task.Node]; !ok {
Expand Down
3 changes: 3 additions & 0 deletions lib/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
e.activeTasksIndexer.Describe(ch)
e.activeTasksReplication.Describe(ch)
e.activeTasksReplicationLastUpdate.Describe(ch)
e.activeTasksReplicationChangesPending.Describe(ch)

e.couchLog.Describe(ch)

Expand Down Expand Up @@ -226,6 +227,7 @@ func (e *Exporter) resetAllMetrics() {
e.activeTasksIndexer,
e.activeTasksReplication,
e.activeTasksReplicationLastUpdate,
e.activeTasksReplicationChangesPending,

e.couchLog,

Expand Down Expand Up @@ -361,6 +363,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) error {
e.activeTasksIndexer.Collect(ch)
e.activeTasksReplication.Collect(ch)
e.activeTasksReplicationLastUpdate.Collect(ch)
e.activeTasksReplicationChangesPending.Collect(ch)

e.couchLog.Collect(ch)

Expand Down
15 changes: 8 additions & 7 deletions lib/couchdb-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,14 @@ type DatabaseStats struct {
type DatabaseStatsByDbName map[string]DatabaseStats

type ActiveTask struct {
Type string `json:"type"`
Node string `json:"node,omitempty"`
Continuous bool `json:"continuous,omitempty"`
UpdatedOn float64 `json:"updated_on,omitempty"`
Source string `json:"source,omitempty"`
Target string `json:"target,omitempty"`
DocId string `json:"doc_id,omitempty"`
Type string `json:"type"`
Node string `json:"node,omitempty"`
ChangesPending int `json:"changes_pending,omitempty"`
Continuous bool `json:"continuous,omitempty"`
UpdatedOn float64 `json:"updated_on,omitempty"`
Source string `json:"source,omitempty"`
Target string `json:"target,omitempty"`
DocId string `json:"doc_id,omitempty"`
}

type ActiveTasksResponse []ActiveTask
Expand Down
32 changes: 21 additions & 11 deletions lib/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ type Exporter struct {
compactRunning *prometheus.GaugeVec
diskSizeOverhead *prometheus.GaugeVec

activeTasks *prometheus.GaugeVec
activeTasksDatabaseCompaction *prometheus.GaugeVec
activeTasksViewCompaction *prometheus.GaugeVec
activeTasksIndexer *prometheus.GaugeVec
activeTasksReplication *prometheus.GaugeVec
activeTasksReplicationLastUpdate *prometheus.GaugeVec
activeTasks *prometheus.GaugeVec
activeTasksDatabaseCompaction *prometheus.GaugeVec
activeTasksViewCompaction *prometheus.GaugeVec
activeTasksIndexer *prometheus.GaugeVec
activeTasksReplication *prometheus.GaugeVec
activeTasksReplicationLastUpdate *prometheus.GaugeVec
activeTasksReplicationChangesPending *prometheus.GaugeVec

couchLog *prometheus.GaugeVec

Expand Down Expand Up @@ -333,31 +334,31 @@ func NewExporter(uri string, basicAuth BasicAuth, collectorConfig CollectorConfi
Namespace: namespace,
Subsystem: "server",
Name: "active_tasks_database_compaction",
Help: "active tasks",
Help: "active tasks database compaction",
},
[]string{"node_name"}),
activeTasksViewCompaction: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "server",
Name: "active_tasks_view_compaction",
Help: "active tasks",
Help: "active tasks view compaction",
},
[]string{"node_name"}),
activeTasksIndexer: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "server",
Name: "active_tasks_indexer",
Help: "active tasks",
Help: "active tasks indexer",
},
[]string{"node_name"}),
activeTasksReplication: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "server",
Name: "active_tasks_replication",
Help: "active tasks",
Help: "active tasks replication",
},
[]string{"node_name"}),

Expand All @@ -366,7 +367,16 @@ func NewExporter(uri string, basicAuth BasicAuth, collectorConfig CollectorConfi
Namespace: namespace,
Subsystem: "server",
Name: "active_tasks_replication_updated_on",
Help: "active tasks",
Help: "active tasks replication updated on",
},
[]string{"node_name", "doc_id", "continuous", "source", "target"}),

activeTasksReplicationChangesPending: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "server",
Name: "active_tasks_replication_changes_pending",
Help: "active tasks replication changes pending ",
},
[]string{"node_name", "doc_id", "continuous", "source", "target"}),

Expand Down

0 comments on commit 7ad2416

Please sign in to comment.