Skip to content

Commit 7a7dbdc

Browse files
author
Stefano Torresi
authored
Merge pull request #172 from MalloZup/qdevice
Add qdevice membership parsing and metric label
2 parents 62154d3 + 4a7e189 commit 7a7dbdc

File tree

5 files changed

+37
-30
lines changed

5 files changed

+37
-30
lines changed

collector/corosync/corosync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (c *corosyncCollector) CollectWithError(ch chan<- prometheus.Metric) error
4545

4646
// We suppress the exec errors because if any interface is faulty the tools will exit with code 1, but we still want to parse the output.
4747
cfgToolOutput, _ := exec.Command(c.cfgToolPath, "-s").Output()
48-
quorumToolOutput, _ := exec.Command(c.quorumToolPath).Output()
48+
quorumToolOutput, _ := exec.Command(c.quorumToolPath, "-p").Output()
4949

5050
status, err := c.parser.Parse(cfgToolOutput, quorumToolOutput)
5151
if err != nil {

collector/corosync/parser.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ type Ring struct {
3535
}
3636

3737
type Member struct {
38-
Id string
39-
Name string
40-
Votes uint64
41-
Local bool
38+
Id string
39+
Name string
40+
Qdevice string
41+
Votes uint64
42+
Local bool
4243
}
4344

4445
func NewParser() Parser {
@@ -211,21 +212,22 @@ func parseMembers(quorumToolOutput []byte) (members []Member, err error) {
211212
/*
212213
Membership information
213214
----------------------
214-
Nodeid Votes Name
215-
1 1 192.168.125.24
216-
2 1 192.168.125.25 (local)
215+
Nodeid Votes Qdevice Name
216+
1 1 A,V,NMW nfs01 (local)
217+
2 1 A,V,NMW nfs02
218+
0 1 Qdevice
217219
*/
218-
sectionRE := regexp.MustCompile(`(?m)Membership information\n-+\s+Nodeid\s+Votes\s+Name\n+((?:.*\n?)+)`)
220+
sectionRE := regexp.MustCompile(`(?m)Membership information\n-+\s+Nodeid\s+Votes\s+Qdevice\s+Name\n+((?:.*\n?)+)`)
219221
sectionMatch := sectionRE.FindSubmatch(quorumToolOutput)
220222
if sectionMatch == nil {
221223
return nil, errors.New("could not find membership information")
222224
}
223225

224226
// we also need a second regex to capture the single elements of each node line, e.g.:
225227
/*
226-
1 1 192.168.125.24 (local)
228+
1 1 A,V,NMW 192.168.125.24 (local)
227229
*/
228-
linesRE := regexp.MustCompile(`(?m)(?P<node_id>\w+)\s+(?P<votes>\d+)\s(?P<name>[\w-\.]+)(?:\s(?P<local>\(local\)))?\n?`)
230+
linesRE := regexp.MustCompile(`(?m)(?P<node_id>\w+)\s+(?P<votes>\d+)\s+(?P<qdevice>(\w,?)+)?\s+(?P<name>[\w-\.]+)(?:\s(?P<local>\(local\)))?\n?`)
229231
linesMatches := linesRE.FindAllSubmatch(sectionMatch[1], -1)
230232
for _, match := range linesMatches {
231233
matches := extractRENamedCaptureGroups(linesRE, match)
@@ -241,10 +243,11 @@ func parseMembers(quorumToolOutput []byte) (members []Member, err error) {
241243
}
242244

243245
members = append(members, Member{
244-
Id: matches["node_id"],
245-
Name: matches["name"],
246-
Votes: votes,
247-
Local: local,
246+
Id: matches["node_id"],
247+
Name: matches["name"],
248+
Votes: votes,
249+
Local: local,
250+
Qdevice: matches["qdevice"],
248251
})
249252
}
250253

collector/corosync/parser_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Flags: 2Node Quorate WaitForAll
3838
3939
Membership information
4040
----------------------
41-
Nodeid Votes Name
42-
1084780051 1 dma-dog-hana01 (local)
43-
1084780052 1 dma-dog-hana02`)
41+
Nodeid Votes Qdevice Name
42+
1084780051 1 NR dma-dog-hana01 (local)
43+
1084780052 1 A,V,NMW dma-dog-hana02`)
4444

4545
status, err := p.Parse(cfgToolOutput, quoromToolOutput)
4646
assert.NoError(t, err)
@@ -67,10 +67,12 @@ Membership information
6767
assert.Len(t, members, 2)
6868
assert.Exactly(t, "1084780051", members[0].Id)
6969
assert.Exactly(t, "dma-dog-hana01", members[0].Name)
70+
assert.Exactly(t, "NR", members[0].Qdevice)
7071
assert.True(t, members[0].Local)
7172
assert.EqualValues(t, 1, members[0].Votes)
7273
assert.Exactly(t, "1084780052", members[1].Id)
7374
assert.Exactly(t, "dma-dog-hana02", members[1].Name)
75+
assert.Exactly(t, "A,V,NMW", members[1].Qdevice)
7476
assert.False(t, members[1].Local)
7577
assert.EqualValues(t, 1, members[1].Votes)
7678
}
@@ -250,8 +252,8 @@ func TestParseMembersEmptyError(t *testing.T) {
250252
func TestParseMembersUintError(t *testing.T) {
251253
quoromToolOutput := []byte(`Membership information
252254
----------------------
253-
Nodeid Votes Name
254-
1084780051 10000000000000000000000000000000000000000000000 dma-dog-hana01`)
255+
Nodeid Votes Qdevice Name
256+
1084780051 10000000000000000000000000000000000000000000000 NW dma-dog-hana01`)
255257

256258
_, err := parseMembers(quoromToolOutput)
257259

@@ -280,9 +282,9 @@ Flags: 2Node Quorate WaitForAll
280282
281283
Membership information
282284
----------------------
283-
Nodeid Votes Name
284-
1 1 192.168.127.20
285-
2 1 192.168.127.21 (local)`)
285+
Nodeid Votes Qdevice Name
286+
1 1 NR 192.168.127.20
287+
2 1 NR 192.168.127.21 (local)`)
286288

287289
members, err := parseMembers(quorumToolOutput)
288290

test/corosync.metrics

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# HELP ha_cluster_corosync_member_votes How many votes each member node has contributed with to the current quorum
2+
# TYPE ha_cluster_corosync_member_votes gauge
3+
ha_cluster_corosync_member_votes{local="false",node="Qdevice",node_id="0"} 1
4+
ha_cluster_corosync_member_votes{local="false",node="stefanotorresi-hana02",node_id="1084783376"} 1
5+
ha_cluster_corosync_member_votes{local="true",node="stefanotorresi-hana01",node_id="1084783375"} 1
16
# HELP ha_cluster_corosync_quorate Whether or not the cluster is quorate
27
# TYPE ha_cluster_corosync_quorate gauge
38
ha_cluster_corosync_quorate 1
@@ -14,7 +19,3 @@ ha_cluster_corosync_ring_errors 1
1419
# TYPE ha_cluster_corosync_rings gauge
1520
ha_cluster_corosync_rings{address="10.0.0.1",node_id="1084783375",number="0",ring_id="1084783375/40"} 0
1621
ha_cluster_corosync_rings{address="172.16.0.1",node_id="1084783375",number="1",ring_id="1084783375/40"} 1
17-
# HELP ha_cluster_corosync_member_votes How many votes each member node has contributed with to the current quorum
18-
# TYPE ha_cluster_corosync_member_votes gauge
19-
ha_cluster_corosync_member_votes{local="true",node="stefanotorresi-hana01",node_id="1084783375"} 1
20-
ha_cluster_corosync_member_votes{local="false",node="stefanotorresi-hana02",node_id="1084783376"} 1

test/fake_corosync-quorumtool.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Flags: 2Node Quorate
2020
2121
Membership information
2222
----------------------
23-
Nodeid Votes Name
24-
1084783375 1 stefanotorresi-hana01 (local)
25-
1084783376 1 stefanotorresi-hana02
23+
Nodeid Votes Qdevice Name
24+
1084783375 1 NR stefanotorresi-hana01 (local)
25+
1084783376 1 A,V,NMW stefanotorresi-hana02
26+
0 1 Qdevice
2627
EOF

0 commit comments

Comments
 (0)