diff --git a/drbd_metrics.go b/drbd_metrics.go index 06cd7f4..d50f2e4 100644 --- a/drbd_metrics.go +++ b/drbd_metrics.go @@ -173,11 +173,9 @@ func (c *drbdCollector) setDrbdSplitBrainMetric(ch chan<- prometheus.Metric) { // set split brain metric // by default if the custom hook is not set, the exporter will not be able to detect it - files, err := ioutil.ReadDir(c.drbdSplitBrainPath) - if err != nil { - log.Warnf("Error while reading directory %s: %s", c.drbdSplitBrainPath, err) - } + files, _ := ioutil.ReadDir(c.drbdSplitBrainPath) + // the split brain files exists for _, f := range files { // check if in directory there are file of syntax we expect (nil is when there is not any) match, _ := filepath.Glob(c.drbdSplitBrainPath + "/drbd-split-brain-detected-*") diff --git a/drbd_metrics_test.go b/drbd_metrics_test.go index 5d12269..1db6052 100644 --- a/drbd_metrics_test.go +++ b/drbd_metrics_test.go @@ -2,7 +2,10 @@ package main import ( "os" + "strings" "testing" + + "github.com/prometheus/client_golang/prometheus/testutil" ) func TestDrbdParsing(t *testing.T) { @@ -229,6 +232,14 @@ func TestNewDrbdCollectorChecksDrbdsetupExecutableBits(t *testing.T) { func TestDRBDCollector(t *testing.T) { clock = StoppedClock{} + + collector, _ := NewDrbdCollector("test/fake_drbdsetup.sh", "fake") + expectMetrics(t, collector, "drbd.metrics") + +} + +func TestDRBDSplitbrainCollector(t *testing.T) { + clock = StoppedClock{} splitBrainDir := "/var/tmp/drbd/splitbrain" testFiles := [3]string{ "drbd-split-brain-detected-resource01-vol01", @@ -247,8 +258,17 @@ func TestDRBDCollector(t *testing.T) { os.Create(splitBrainDir + "/" + testFile) } defer os.RemoveAll(splitBrainDir) + // we use by intent a wrong exec (cibadmin) so we can just have splitbrain metrics + collector, _ := NewDrbdCollector("test/fake_cibadmin.sh", splitBrainDir) - collector, _ := NewDrbdCollector("test/fake_drbdsetup.sh", splitBrainDir) - expectMetrics(t, collector, "drbd.metrics") + expect := ` + # HELP ha_cluster_drbd_split_brain Whether a split brain has been detected; 1 line per resource, per volume. + # TYPE ha_cluster_drbd_split_brain gauge + ha_cluster_drbd_split_brain{resource="resource01",volume="vol01"} 1 1234 + ha_cluster_drbd_split_brain{resource="resource02",volume="vol02"} 1 1234 + ` + if err := testutil.CollectAndCompare(collector, strings.NewReader(expect)); err != nil { + t.Fatal(err) + } } diff --git a/test/drbd.metrics b/test/drbd.metrics index 443ac1f..f6bbc92 100644 --- a/test/drbd.metrics +++ b/test/drbd.metrics @@ -1,11 +1,19 @@ +# HELP ha_cluster_drbd_al_writes Writes to activity log; 1 line per res, per volume +# TYPE ha_cluster_drbd_al_writes gauge +ha_cluster_drbd_al_writes{resource="1-single-0",volume="0"} 123 1234 +ha_cluster_drbd_al_writes{resource="1-single-1",volume="0"} 123 1234 +# HELP ha_cluster_drbd_bm_writes Writes to bitmap; 1 line per res, per volume +# TYPE ha_cluster_drbd_bm_writes gauge +ha_cluster_drbd_bm_writes{resource="1-single-0",volume="0"} 321 1234 +ha_cluster_drbd_bm_writes{resource="1-single-1",volume="0"} 321 1234 # HELP ha_cluster_drbd_connections The DRBD resource connections; 1 line per per resource, per peer_node_id # 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_connections_pending Pending value per connection +# TYPE ha_cluster_drbd_connections_pending gauge +ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-0",volume="0"} 3 1234 +ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-1",volume="0"} 3 1234 # HELP ha_cluster_drbd_connections_received KiB received per connection # TYPE ha_cluster_drbd_connections_received gauge ha_cluster_drbd_connections_received{peer_node_id="1",resource="1-single-0",volume="0"} 456 1234 @@ -14,34 +22,14 @@ ha_cluster_drbd_connections_received{peer_node_id="1",resource="1-single-1",volu # TYPE ha_cluster_drbd_connections_sent gauge ha_cluster_drbd_connections_sent{peer_node_id="1",resource="1-single-0",volume="0"} 654 1234 ha_cluster_drbd_connections_sent{peer_node_id="1",resource="1-single-1",volume="0"} 654 1234 -# HELP ha_cluster_drbd_connections_pending Pending value per connection -# TYPE ha_cluster_drbd_connections_pending gauge -ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-0",volume="0"} 3 1234 -ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-1",volume="0"} 3 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_connections_unacked Unacked value per connection # TYPE ha_cluster_drbd_connections_unacked gauge ha_cluster_drbd_connections_unacked{peer_node_id="1",resource="1-single-0",volume="0"} 4 1234 ha_cluster_drbd_connections_unacked{peer_node_id="1",resource="1-single-1",volume="0"} 4 1234 -# HELP ha_cluster_drbd_written KiB written to DRBD; 1 line per res, per volume -# TYPE ha_cluster_drbd_written gauge -ha_cluster_drbd_written{resource="1-single-0",volume="0"} 123456 1234 -ha_cluster_drbd_written{resource="1-single-1",volume="0"} 123456 1234 -# HELP ha_cluster_drbd_read KiB read from DRBD; 1 line per res, per volume -# TYPE ha_cluster_drbd_read gauge -ha_cluster_drbd_read{resource="1-single-0",volume="0"} 654321 1234 -ha_cluster_drbd_read{resource="1-single-1",volume="0"} 654321 1234 -# HELP ha_cluster_drbd_al_writes Writes to activity log; 1 line per res, per volume -# TYPE ha_cluster_drbd_al_writes gauge -ha_cluster_drbd_al_writes{resource="1-single-0",volume="0"} 123 1234 -ha_cluster_drbd_al_writes{resource="1-single-1",volume="0"} 123 1234 -# HELP ha_cluster_drbd_bm_writes Writes to bitmap; 1 line per res, per volume -# TYPE ha_cluster_drbd_bm_writes gauge -ha_cluster_drbd_bm_writes{resource="1-single-0",volume="0"} 321 1234 -ha_cluster_drbd_bm_writes{resource="1-single-1",volume="0"} 321 1234 -# HELP ha_cluster_drbd_upper_pending Upper pending; 1 line per res, per volume -# TYPE ha_cluster_drbd_upper_pending gauge -ha_cluster_drbd_upper_pending{resource="1-single-0",volume="0"} 1 1234 -ha_cluster_drbd_upper_pending{resource="1-single-1",volume="0"} 1 1234 # HELP ha_cluster_drbd_lower_pending Lower pending; 1 line per res, per volume # TYPE ha_cluster_drbd_lower_pending gauge ha_cluster_drbd_lower_pending{resource="1-single-0",volume="0"} 2 1234 @@ -50,11 +38,19 @@ ha_cluster_drbd_lower_pending{resource="1-single-1",volume="0"} 2 1234 # 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_read KiB read from DRBD; 1 line per res, per volume +# TYPE ha_cluster_drbd_read gauge +ha_cluster_drbd_read{resource="1-single-0",volume="0"} 654321 1234 +ha_cluster_drbd_read{resource="1-single-1",volume="0"} 654321 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 ha_cluster_drbd_resources{disk_state="uptodate",resource="1-single-1",role="Secondary",volume="0"} 1 1234 -# HELP ha_cluster_drbd_split_brain Whether a split brain has been detected; 1 line per resource, per volume. -# TYPE ha_cluster_drbd_split_brain gauge -ha_cluster_drbd_split_brain{resource="resource01",volume="vol01"} 1 1234 -ha_cluster_drbd_split_brain{resource="resource02",volume="vol02"} 1 1234 +# HELP ha_cluster_drbd_upper_pending Upper pending; 1 line per res, per volume +# TYPE ha_cluster_drbd_upper_pending gauge +ha_cluster_drbd_upper_pending{resource="1-single-0",volume="0"} 1 1234 +ha_cluster_drbd_upper_pending{resource="1-single-1",volume="0"} 1 1234 +# HELP ha_cluster_drbd_written KiB written to DRBD; 1 line per res, per volume +# TYPE ha_cluster_drbd_written gauge +ha_cluster_drbd_written{resource="1-single-0",volume="0"} 123456 1234 +ha_cluster_drbd_written{resource="1-single-1",volume="0"} 123456 1234