Skip to content

Commit bc84e82

Browse files
author
Stefano Torresi
authored
Merge pull request #110 from MalloZup/minor-fixes
Remove unrelevant warning for splitbrain file
2 parents 1262e07 + 10a0b83 commit bc84e82

File tree

3 files changed

+52
-38
lines changed

3 files changed

+52
-38
lines changed

drbd_metrics.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,9 @@ func (c *drbdCollector) setDrbdSplitBrainMetric(ch chan<- prometheus.Metric) {
173173

174174
// set split brain metric
175175
// by default if the custom hook is not set, the exporter will not be able to detect it
176-
files, err := ioutil.ReadDir(c.drbdSplitBrainPath)
177-
if err != nil {
178-
log.Warnf("Error while reading directory %s: %s", c.drbdSplitBrainPath, err)
179-
}
176+
files, _ := ioutil.ReadDir(c.drbdSplitBrainPath)
180177

178+
// the split brain files exists
181179
for _, f := range files {
182180
// check if in directory there are file of syntax we expect (nil is when there is not any)
183181
match, _ := filepath.Glob(c.drbdSplitBrainPath + "/drbd-split-brain-detected-*")

drbd_metrics_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package main
22

33
import (
44
"os"
5+
"strings"
56
"testing"
7+
8+
"github.com/prometheus/client_golang/prometheus/testutil"
69
)
710

811
func TestDrbdParsing(t *testing.T) {
@@ -229,6 +232,14 @@ func TestNewDrbdCollectorChecksDrbdsetupExecutableBits(t *testing.T) {
229232

230233
func TestDRBDCollector(t *testing.T) {
231234
clock = StoppedClock{}
235+
236+
collector, _ := NewDrbdCollector("test/fake_drbdsetup.sh", "fake")
237+
expectMetrics(t, collector, "drbd.metrics")
238+
239+
}
240+
241+
func TestDRBDSplitbrainCollector(t *testing.T) {
242+
clock = StoppedClock{}
232243
splitBrainDir := "/var/tmp/drbd/splitbrain"
233244
testFiles := [3]string{
234245
"drbd-split-brain-detected-resource01-vol01",
@@ -247,8 +258,17 @@ func TestDRBDCollector(t *testing.T) {
247258
os.Create(splitBrainDir + "/" + testFile)
248259
}
249260
defer os.RemoveAll(splitBrainDir)
261+
// we use by intent a wrong exec (cibadmin) so we can just have splitbrain metrics
262+
collector, _ := NewDrbdCollector("test/fake_cibadmin.sh", splitBrainDir)
250263

251-
collector, _ := NewDrbdCollector("test/fake_drbdsetup.sh", splitBrainDir)
252-
expectMetrics(t, collector, "drbd.metrics")
264+
expect := `
265+
# HELP ha_cluster_drbd_split_brain Whether a split brain has been detected; 1 line per resource, per volume.
266+
# TYPE ha_cluster_drbd_split_brain gauge
267+
ha_cluster_drbd_split_brain{resource="resource01",volume="vol01"} 1 1234
268+
ha_cluster_drbd_split_brain{resource="resource02",volume="vol02"} 1 1234
269+
`
253270

271+
if err := testutil.CollectAndCompare(collector, strings.NewReader(expect)); err != nil {
272+
t.Fatal(err)
273+
}
254274
}

test/drbd.metrics

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
# HELP ha_cluster_drbd_al_writes Writes to activity log; 1 line per res, per volume
2+
# TYPE ha_cluster_drbd_al_writes gauge
3+
ha_cluster_drbd_al_writes{resource="1-single-0",volume="0"} 123 1234
4+
ha_cluster_drbd_al_writes{resource="1-single-1",volume="0"} 123 1234
5+
# HELP ha_cluster_drbd_bm_writes Writes to bitmap; 1 line per res, per volume
6+
# TYPE ha_cluster_drbd_bm_writes gauge
7+
ha_cluster_drbd_bm_writes{resource="1-single-0",volume="0"} 321 1234
8+
ha_cluster_drbd_bm_writes{resource="1-single-1",volume="0"} 321 1234
19
# HELP ha_cluster_drbd_connections The DRBD resource connections; 1 line per per resource, per peer_node_id
210
# TYPE ha_cluster_drbd_connections gauge
311
ha_cluster_drbd_connections{peer_disk_state="uptodate",peer_node_id="1",peer_role="Primary",resource="1-single-0",volume="0"} 1 1234
412
ha_cluster_drbd_connections{peer_disk_state="uptodate",peer_node_id="1",peer_role="Primary",resource="1-single-1",volume="0"} 1 1234
5-
# HELP ha_cluster_drbd_connections_sync The in sync percentage value for DRBD resource connections
6-
# TYPE ha_cluster_drbd_connections_sync gauge
7-
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-0",volume="0"} 100 1234
8-
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-1",volume="0"} 100 1234
13+
# HELP ha_cluster_drbd_connections_pending Pending value per connection
14+
# TYPE ha_cluster_drbd_connections_pending gauge
15+
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-0",volume="0"} 3 1234
16+
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-1",volume="0"} 3 1234
917
# HELP ha_cluster_drbd_connections_received KiB received per connection
1018
# TYPE ha_cluster_drbd_connections_received gauge
1119
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
1422
# TYPE ha_cluster_drbd_connections_sent gauge
1523
ha_cluster_drbd_connections_sent{peer_node_id="1",resource="1-single-0",volume="0"} 654 1234
1624
ha_cluster_drbd_connections_sent{peer_node_id="1",resource="1-single-1",volume="0"} 654 1234
17-
# HELP ha_cluster_drbd_connections_pending Pending value per connection
18-
# TYPE ha_cluster_drbd_connections_pending gauge
19-
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-0",volume="0"} 3 1234
20-
ha_cluster_drbd_connections_pending{peer_node_id="1",resource="1-single-1",volume="0"} 3 1234
25+
# HELP ha_cluster_drbd_connections_sync The in sync percentage value for DRBD resource connections
26+
# TYPE ha_cluster_drbd_connections_sync gauge
27+
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-0",volume="0"} 100 1234
28+
ha_cluster_drbd_connections_sync{peer_node_id="1",resource="1-single-1",volume="0"} 100 1234
2129
# HELP ha_cluster_drbd_connections_unacked Unacked value per connection
2230
# TYPE ha_cluster_drbd_connections_unacked gauge
2331
ha_cluster_drbd_connections_unacked{peer_node_id="1",resource="1-single-0",volume="0"} 4 1234
2432
ha_cluster_drbd_connections_unacked{peer_node_id="1",resource="1-single-1",volume="0"} 4 1234
25-
# HELP ha_cluster_drbd_written KiB written to DRBD; 1 line per res, per volume
26-
# TYPE ha_cluster_drbd_written gauge
27-
ha_cluster_drbd_written{resource="1-single-0",volume="0"} 123456 1234
28-
ha_cluster_drbd_written{resource="1-single-1",volume="0"} 123456 1234
29-
# HELP ha_cluster_drbd_read KiB read from DRBD; 1 line per res, per volume
30-
# TYPE ha_cluster_drbd_read gauge
31-
ha_cluster_drbd_read{resource="1-single-0",volume="0"} 654321 1234
32-
ha_cluster_drbd_read{resource="1-single-1",volume="0"} 654321 1234
33-
# HELP ha_cluster_drbd_al_writes Writes to activity log; 1 line per res, per volume
34-
# TYPE ha_cluster_drbd_al_writes gauge
35-
ha_cluster_drbd_al_writes{resource="1-single-0",volume="0"} 123 1234
36-
ha_cluster_drbd_al_writes{resource="1-single-1",volume="0"} 123 1234
37-
# HELP ha_cluster_drbd_bm_writes Writes to bitmap; 1 line per res, per volume
38-
# TYPE ha_cluster_drbd_bm_writes gauge
39-
ha_cluster_drbd_bm_writes{resource="1-single-0",volume="0"} 321 1234
40-
ha_cluster_drbd_bm_writes{resource="1-single-1",volume="0"} 321 1234
41-
# HELP ha_cluster_drbd_upper_pending Upper pending; 1 line per res, per volume
42-
# TYPE ha_cluster_drbd_upper_pending gauge
43-
ha_cluster_drbd_upper_pending{resource="1-single-0",volume="0"} 1 1234
44-
ha_cluster_drbd_upper_pending{resource="1-single-1",volume="0"} 1 1234
4533
# HELP ha_cluster_drbd_lower_pending Lower pending; 1 line per res, per volume
4634
# TYPE ha_cluster_drbd_lower_pending gauge
4735
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
5038
# TYPE ha_cluster_drbd_quorum gauge
5139
ha_cluster_drbd_quorum{resource="1-single-0",volume="0"} 1 1234
5240
ha_cluster_drbd_quorum{resource="1-single-1",volume="0"} 0 1234
41+
# HELP ha_cluster_drbd_read KiB read from DRBD; 1 line per res, per volume
42+
# TYPE ha_cluster_drbd_read gauge
43+
ha_cluster_drbd_read{resource="1-single-0",volume="0"} 654321 1234
44+
ha_cluster_drbd_read{resource="1-single-1",volume="0"} 654321 1234
5345
# HELP ha_cluster_drbd_resources The DRBD resources; 1 line per name, per volume
5446
# TYPE ha_cluster_drbd_resources gauge
5547
ha_cluster_drbd_resources{disk_state="uptodate",resource="1-single-0",role="Secondary",volume="0"} 1 1234
5648
ha_cluster_drbd_resources{disk_state="uptodate",resource="1-single-1",role="Secondary",volume="0"} 1 1234
57-
# HELP ha_cluster_drbd_split_brain Whether a split brain has been detected; 1 line per resource, per volume.
58-
# TYPE ha_cluster_drbd_split_brain gauge
59-
ha_cluster_drbd_split_brain{resource="resource01",volume="vol01"} 1 1234
60-
ha_cluster_drbd_split_brain{resource="resource02",volume="vol02"} 1 1234
49+
# HELP ha_cluster_drbd_upper_pending Upper pending; 1 line per res, per volume
50+
# TYPE ha_cluster_drbd_upper_pending gauge
51+
ha_cluster_drbd_upper_pending{resource="1-single-0",volume="0"} 1 1234
52+
ha_cluster_drbd_upper_pending{resource="1-single-1",volume="0"} 1 1234
53+
# HELP ha_cluster_drbd_written KiB written to DRBD; 1 line per res, per volume
54+
# TYPE ha_cluster_drbd_written gauge
55+
ha_cluster_drbd_written{resource="1-single-0",volume="0"} 123456 1234
56+
ha_cluster_drbd_written{resource="1-single-1",volume="0"} 123456 1234

0 commit comments

Comments
 (0)