Skip to content

Commit

Permalink
Merge pull request #108 from kermat/mdk/add-drbd-quorum-bool
Browse files Browse the repository at this point in the history
Add quorum status to DRBD metrics
  • Loading branch information
MalloZup authored Dec 10, 2019
2 parents 1da69e1 + 4edbf7d commit 1262e07
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
27 changes: 20 additions & 7 deletions doc/metric_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ The DRBD subsystems collect devices stats by parsing its configuration the JSON
5. [`ha_cluster_drbd_bm_writes`](#ha_cluster_bm_writes)
6. [`ha_cluster_drbd_upper_pending`](#ha_cluster_drbd_upper_pending)
7. [`ha_cluster_drbd_lower_pending`](#ha_cluster_drbd_lower_pending)
8. [`ha_cluster_drbd_connections`](#ha_cluster_drbd_connections)
9. [`ha_cluster_drbd_connections_sync`](#ha_cluster_drbd_connections_sync)
10. [`ha_cluster_drbd_connections_received`](#ha_cluster_drbd_connections_received)
11. [`ha_cluster_drbd_connections_sent`](#ha_cluster_drbd_connections_sent)
12. [`ha_cluster_drbd_connections_pending`](#ha_cluster_drbd_connections_pending)
13. [`ha_cluster_drbd_connections_unacked`](#ha_cluster_drbd_connections_unacked)
14. [`ha_cluster_drbd_split_brain`](#ha_cluster_drbd_split_brain)
8. [`ha_cluster_drbd_quorum`](#ha_cluster_drbd_quorum)
9. [`ha_cluster_drbd_connections`](#ha_cluster_drbd_connections)
10. [`ha_cluster_drbd_connections_sync`](#ha_cluster_drbd_connections_sync)
11. [`ha_cluster_drbd_connections_received`](#ha_cluster_drbd_connections_received)
12. [`ha_cluster_drbd_connections_sent`](#ha_cluster_drbd_connections_sent)
13. [`ha_cluster_drbd_connections_pending`](#ha_cluster_drbd_connections_pending)
14. [`ha_cluster_drbd_connections_unacked`](#ha_cluster_drbd_connections_unacked)
15. [`ha_cluster_drbd_split_brain`](#ha_cluster_drbd_split_brain)

### `ha_cluster_drbd_connections`

Expand Down Expand Up @@ -388,6 +389,18 @@ Value is an integer greater than or equal to `0`.
- `resource`: the name of the resource.
- `volume`: the volume number

### `ha_cluster_drbd_quorum`

#### Description

Quorum status of the DRBD resource according to it's configured quorum policies; 1 line per `resource`, per `volume`
Value is `1` when quorate, or `0` when inquorate.

#### Labels

- `resource`: the name of the resource.
- `volume`: the volume number

### `ha_cluster_drbd_split_brain`

#### Description
Expand Down
8 changes: 8 additions & 0 deletions drbd_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type drbdStatus struct {
BmWrites int `json:"bm-writes"`
UpPending int `json:"upper-pending"`
LoPending int `json:"lower-pending"`
Quorum bool `json:"quorum"`
DiskState string `json:"disk-state"`
} `json:"devices"`
Connections []struct {
Expand Down Expand Up @@ -53,6 +54,7 @@ var (
"bm_writes": NewMetricDesc("drbd", "bm_writes", "Writes to bitmap; 1 line per res, per volume", []string{"resource", "volume"}),
"upper_pending": NewMetricDesc("drbd", "upper_pending", "Upper pending; 1 line per res, per volume", []string{"resource", "volume"}),
"lower_pending": NewMetricDesc("drbd", "lower_pending", "Lower pending; 1 line per res, per volume", []string{"resource", "volume"}),
"quorum": NewMetricDesc("drbd", "quorum", "Quorum status per resource and per volume", []string{"resource", "volume"}),
"connections": NewMetricDesc("drbd", "connections", "The DRBD resource connections; 1 line per per resource, per peer_node_id", []string{"resource", "peer_node_id", "peer_role", "volume", "peer_disk_state"}),
"connections_sync": NewMetricDesc("drbd", "connections_sync", "The in sync percentage value for DRBD resource connections", []string{"resource", "peer_node_id", "volume"}),
"connections_received": NewMetricDesc("drbd", "connections_received", "KiB received per connection", []string{"resource", "peer_node_id", "volume"}),
Expand Down Expand Up @@ -121,6 +123,12 @@ func (c *drbdCollector) Collect(ch chan<- prometheus.Metric) {
ch <- c.makeGaugeMetric("upper_pending", float64(device.UpPending), resource.Name, strconv.Itoa(device.Volume))

ch <- c.makeGaugeMetric("lower_pending", float64(device.LoPending), resource.Name, strconv.Itoa(device.Volume))

if bool(device.Quorum) == true {
ch <- c.makeGaugeMetric("quorum", float64(1), resource.Name, strconv.Itoa(device.Volume))
} else {
ch <- c.makeGaugeMetric("quorum", float64(0), resource.Name, strconv.Itoa(device.Volume))
}
}
if len(resource.Connections) == 0 {
log.Warnf("Could not retrieve connection info for resource '%s'\n", resource.Name)
Expand Down
10 changes: 9 additions & 1 deletion drbd_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestDrbdParsing(t *testing.T) {
"minor": 3,
"disk-state": "UpToDate",
"client": false,
"quorum": true,
"quorum": false,
"size": 10200,
"read": 654321,
"written": 123456,
Expand Down Expand Up @@ -166,6 +166,14 @@ func TestDrbdParsing(t *testing.T) {
t.Errorf("lower-pending should be 2")
}

if true != drbdDevs[0].Devices[0].Quorum {
t.Errorf("quorum should be true")
}

if false != drbdDevs[1].Devices[0].Quorum {
t.Errorf("quorum should be false")
}

if 456 != drbdDevs[0].Connections[0].PeerDevices[0].Received {
t.Errorf("received should be 456")
}
Expand Down
4 changes: 4 additions & 0 deletions test/drbd.metrics
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ ha_cluster_drbd_upper_pending{resource="1-single-1",volume="0"} 1 1234
# TYPE ha_cluster_drbd_lower_pending gauge
ha_cluster_drbd_lower_pending{resource="1-single-0",volume="0"} 2 1234
ha_cluster_drbd_lower_pending{resource="1-single-1",volume="0"} 2 1234
# HELP ha_cluster_drbd_quorum Quorum status per resource and per volume
# TYPE ha_cluster_drbd_quorum gauge
ha_cluster_drbd_quorum{resource="1-single-0",volume="0"} 1 1234
ha_cluster_drbd_quorum{resource="1-single-1",volume="0"} 0 1234
# HELP ha_cluster_drbd_resources The DRBD resources; 1 line per name, per volume
# TYPE ha_cluster_drbd_resources gauge
ha_cluster_drbd_resources{disk_state="uptodate",resource="1-single-0",role="Secondary",volume="0"} 1 1234
Expand Down
2 changes: 1 addition & 1 deletion test/fake_drbdsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ cat <<EOF
"minor": 3,
"disk-state": "UpToDate",
"client": false,
"quorum": true,
"quorum": false,
"size": 10200,
"read": 654321,
"written": 123456,
Expand Down

0 comments on commit 1262e07

Please sign in to comment.