Skip to content

Commit

Permalink
Merge pull request #75 from MalloZup/percent-sync
Browse files Browse the repository at this point in the history
Add delta metric: Percent in sync
  • Loading branch information
stefanotorresi authored Oct 29, 2019
2 parents 67953ef + 0cf99e5 commit 8f282c2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion doc/metric_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ The DRBD subsystems collect devices stats by parsing its configuration the JSON
0. [Sample](../test/drbd.metrics)
1. [`ha_cluster_drbd_resources`](#ha_cluster_drbd_resources)
2. [`ha_cluster_drbd_connections`](#ha_cluster_drbd_connections)

3. [`ha_cluster_drbd_connections_sync`](#ha_cluster_drbd_connections_sync`)

### `ha_cluster_drbd_connections`

Expand All @@ -192,6 +192,11 @@ Either the value is `1`, or the line is absent altogether.

The total number of lines for this metric will be the cardinality of `resource` times the cardinality of `peer_node_id`.

### `ha_cluster_drbd_connections_sync`

#### Descriptions

The DRBD disk connections in sync percentage. Values from 0 to 100.

### `ha_cluster_drbd_resources`

Expand Down
12 changes: 9 additions & 3 deletions drbd_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type drbdStatus struct {
PeerDevices []struct {
Volume int `json:"volume"`
PeerDiskState string `json:"peer-disk-state"`
PercentInSync int `json:"percent-in-sync"`
} `json:"peer_devices"`
} `json:"connections"`
}
Expand All @@ -34,8 +35,9 @@ var (
drbdMetrics = metricDescriptors{
// the map key will function as an identifier of the metric throughout the rest of the code;
// it is arbitrary, but by convention we use the actual metric name
"resources": NewMetricDesc("drbd", "resources", "The DRBD resources; 1 line per name, per volume", []string{"name", "role", "volume", "disk_state"}),
"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"}),
"resources": NewMetricDesc("drbd", "resources", "The DRBD resources; 1 line per name, per volume", []string{"name", "role", "volume", "disk_state"}),
"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"}),
}
drbdsetupPath = "/usr/sbin/drbdsetup"
)
Expand Down Expand Up @@ -94,7 +96,11 @@ func (c *drbdCollector) Collect(ch chan<- prometheus.Metric) {
continue
}
for _, peerDev := range conn.PeerDevices {
ch <- c.makeGaugeMetric("connections", float64(1), resource.Name, strconv.Itoa(conn.PeerNodeID), conn.PeerRole, strconv.Itoa(peerDev.Volume), strings.ToLower(peerDev.PeerDiskState))
ch <- c.makeGaugeMetric("connections", float64(1), resource.Name, strconv.Itoa(conn.PeerNodeID),
conn.PeerRole, strconv.Itoa(peerDev.Volume), strings.ToLower(peerDev.PeerDiskState))

ch <- c.makeGaugeMetric("connections_sync", float64(peerDev.PercentInSync), resource.Name, strconv.Itoa(conn.PeerNodeID), strconv.Itoa(peerDev.Volume))

}
}
}
Expand Down
6 changes: 5 additions & 1 deletion drbd_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func TestDrbdParsing(t *testing.T) {
}

// test attributes

if "1-single-0" != drbdDevs[0].Name {
t.Errorf("name doesn't correspond! fail got %s", drbdDevs[0].Name)
}
Expand All @@ -141,6 +140,11 @@ func TestDrbdParsing(t *testing.T) {
if 0 != drbdDevs[0].Devices[0].Volume {
t.Errorf("volumes should be 0")
}

if 100 != drbdDevs[0].Connections[0].PeerDevices[0].PercentInSync {
t.Errorf("PercentInSync doesn't correspond! fail got %d", drbdDevs[0].Connections[0].PeerDevices[0].PercentInSync)
}

}

func TestDrbdInfoError(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions test/drbd.metrics
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# TYPE ha_cluster_drbd_connections gauge
ha_cluster_drbd_connections{peer_disk_state="uptodate",peer_node_id="1",peer_role="Primary",resource="1-single-0",volume="0"} 1 1234
ha_cluster_drbd_connections{peer_disk_state="uptodate",peer_node_id="1",peer_role="Primary",resource="1-single-1",volume="0"} 1 1234
# HELP ha_cluster_drbd_connections_sync The in sync percentage value for DRBD resource connections
# TYPE ha_cluster_drbd_connections_sync gauge
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-0",volume="0"} 100 1234
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-1",volume="0"} 100 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",name="1-single-0",role="Secondary",volume="0"} 1 1234
Expand Down

0 comments on commit 8f282c2

Please sign in to comment.