Use explicit zpool properties to fix parse error on FreeBSD 11.2 (#4510)
This commit is contained in:
parent
0759c8b22b
commit
a5409d7cf2
|
@ -30,7 +30,11 @@ func (z *Zfs) gatherPoolStats(acc telegraf.Accumulator) (string, error) {
|
|||
if z.PoolMetrics {
|
||||
for _, line := range lines {
|
||||
col := strings.Split(line, "\t")
|
||||
tags := map[string]string{"pool": col[0], "health": col[8]}
|
||||
if len(col) != 8 {
|
||||
continue
|
||||
}
|
||||
|
||||
tags := map[string]string{"pool": col[0], "health": col[1]}
|
||||
fields := map[string]interface{}{}
|
||||
|
||||
if tags["health"] == "UNAVAIL" {
|
||||
|
@ -39,19 +43,19 @@ func (z *Zfs) gatherPoolStats(acc telegraf.Accumulator) (string, error) {
|
|||
|
||||
} else {
|
||||
|
||||
size, err := strconv.ParseInt(col[1], 10, 64)
|
||||
size, err := strconv.ParseInt(col[2], 10, 64)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error parsing size: %s", err)
|
||||
}
|
||||
fields["size"] = size
|
||||
|
||||
alloc, err := strconv.ParseInt(col[2], 10, 64)
|
||||
alloc, err := strconv.ParseInt(col[3], 10, 64)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error parsing allocation: %s", err)
|
||||
}
|
||||
fields["allocated"] = alloc
|
||||
|
||||
free, err := strconv.ParseInt(col[3], 10, 64)
|
||||
free, err := strconv.ParseInt(col[4], 10, 64)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error parsing free: %s", err)
|
||||
}
|
||||
|
@ -130,7 +134,7 @@ func run(command string, args ...string) ([]string, error) {
|
|||
}
|
||||
|
||||
func zpool() ([]string, error) {
|
||||
return run("zpool", []string{"list", "-Hp"}...)
|
||||
return run("zpool", []string{"list", "-Hp", "-o", "name,health,size,alloc,free,fragmentation,capacity,dedupratio"}...)
|
||||
}
|
||||
|
||||
func sysctl(metric string) ([]string, error) {
|
||||
|
|
|
@ -10,21 +10,21 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// $ zpool list -Hp
|
||||
// $ zpool list -Hp -o name,health,size,alloc,free,fragmentation,capacity,dedupratio
|
||||
var zpool_output = []string{
|
||||
"freenas-boot 30601641984 2022177280 28579464704 - - 6 1.00x ONLINE -",
|
||||
"red1 8933531975680 1126164848640 7807367127040 - 8% 12 1.83x ONLINE /mnt",
|
||||
"temp1 2989297238016 1626309320704 1362987917312 - 38% 54 1.28x ONLINE /mnt",
|
||||
"temp2 2989297238016 626958278656 2362338959360 - 12% 20 1.00x ONLINE /mnt",
|
||||
"freenas-boot ONLINE 30601641984 2022177280 28579464704 - 6 1.00x",
|
||||
"red1 ONLINE 8933531975680 1126164848640 7807367127040 8% 12 1.83x",
|
||||
"temp1 ONLINE 2989297238016 1626309320704 1362987917312 38% 54 1.28x",
|
||||
"temp2 ONLINE 2989297238016 626958278656 2362338959360 12% 20 1.00x",
|
||||
}
|
||||
|
||||
func mock_zpool() ([]string, error) {
|
||||
return zpool_output, nil
|
||||
}
|
||||
|
||||
// $ zpool list -Hp
|
||||
// $ zpool list -Hp -o name,health,size,alloc,free,fragmentation,capacity,dedupratio
|
||||
var zpool_output_unavail = []string{
|
||||
"temp2 - - - - - - - UNAVAIL -",
|
||||
"temp2 UNAVAIL - - - - - -",
|
||||
}
|
||||
|
||||
func mock_zpool_unavail() ([]string, error) {
|
||||
|
|
Loading…
Reference in New Issue