diff --git a/doc/metric_spec.md b/doc/metric_spec.md index 6c9fdad..ea033db 100644 --- a/doc/metric_spec.md +++ b/doc/metric_spec.md @@ -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` @@ -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` diff --git a/drbd_metrics.go b/drbd_metrics.go index ede1c77..e474b7d 100644 --- a/drbd_metrics.go +++ b/drbd_metrics.go @@ -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"` } @@ -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" ) @@ -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)) + } } } diff --git a/drbd_metrics_test.go b/drbd_metrics_test.go index 29110d7..8f88355 100644 --- a/drbd_metrics_test.go +++ b/drbd_metrics_test.go @@ -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) } @@ -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) { diff --git a/test/drbd.metrics b/test/drbd.metrics index cb30a47..6b58272 100644 --- a/test/drbd.metrics +++ b/test/drbd.metrics @@ -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