Skip to content

Commit 7b52fa5

Browse files
authored
Fix for mountstats error due to multiline "impl_id" on FreeNAS (prometheus#339)
* Fix for mountstats error due to multiline "impl_id" on FreeNAS This commit fixes an error happening when trying to parse data from FreeNAS NFS mount point. "impl_id" is printed in multiple lines, which triggers "not enough information for NFS stats" error. Signed-off-by: Jakub Wesolowski <[email protected]>
1 parent 910e685 commit 7b52fa5

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

mountstats.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e
338338
if len(ss) == 0 {
339339
break
340340
}
341-
if len(ss) < 2 {
342-
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
343-
}
344341

345342
switch ss[0] {
346343
case fieldOpts:
344+
if len(ss) < 2 {
345+
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
346+
}
347347
if stats.Opts == nil {
348348
stats.Opts = map[string]string{}
349349
}
@@ -356,6 +356,9 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e
356356
}
357357
}
358358
case fieldAge:
359+
if len(ss) < 2 {
360+
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
361+
}
359362
// Age integer is in seconds
360363
d, err := time.ParseDuration(ss[1] + "s")
361364
if err != nil {
@@ -364,13 +367,19 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e
364367

365368
stats.Age = d
366369
case fieldBytes:
370+
if len(ss) < 2 {
371+
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
372+
}
367373
bstats, err := parseNFSBytesStats(ss[1:])
368374
if err != nil {
369375
return nil, err
370376
}
371377

372378
stats.Bytes = *bstats
373379
case fieldEvents:
380+
if len(ss) < 2 {
381+
return nil, fmt.Errorf("not enough information for NFS stats: %v", ss)
382+
}
374383
estats, err := parseNFSEventsStats(ss[1:])
375384
if err != nil {
376385
return nil, err

mountstats_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestMountStats(t *testing.T) {
6464
},
6565
{
6666
name: "NFSv4 device with too little info",
67-
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nhello",
67+
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nopts:",
6868
invalid: true,
6969
},
7070
{
@@ -253,6 +253,26 @@ func TestMountStats(t *testing.T) {
253253
},
254254
}},
255255
},
256+
{
257+
name: "NFS4.1 device with multiline impl_id OK",
258+
s: "device 192.168.0.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nopts: rw,vers=4.1,rsize=131072,wsize=131072,namlen=255,acregmin=3,acregmax=60,acdirmin=30,acdirmax=60,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.0.2,fsc,local_lock=none\nage: 1234567\nimpl_id: name='FreeBSD 11.2-STABLE #0 r325575+c9231c7d6bd(HEAD): Mon Nov 18 22:46:47 UTC 2019\nuser@host:/path/to/something'\n,domain='something.org',date='1293840000,0'",
259+
mounts: []*Mount{{
260+
Device: "192.168.0.1:/srv",
261+
Mount: "/mnt/nfs",
262+
Type: "nfs4",
263+
Stats: &MountStatsNFS{
264+
StatVersion: "1.1",
265+
Opts: map[string]string{"rw": "", "vers": "4.1",
266+
"rsize": "131072", "wsize": "131072", "namlen": "255", "acregmin": "3",
267+
"acregmax": "60", "acdirmin": "30", "acdirmax": "60", "fsc": "", "hard": "",
268+
"proto": "tcp", "timeo": "600", "retrans": "2",
269+
"sec": "sys", "clientaddr": "192.168.0.2",
270+
"local_lock": "none",
271+
},
272+
Age: 1234567 * time.Second,
273+
},
274+
}},
275+
},
256276
{
257277
name: "fixtures/proc OK",
258278
mounts: []*Mount{

0 commit comments

Comments
 (0)