Don't fail parsing of zpool stats if pool health is UNAVAIL on FreeBSD (#3149)

This commit is contained in:
Rickard von Essen 2017-08-25 21:57:35 +02:00 committed by Daniel Nelson
parent 9d65670d19
commit c77b8f2e77
2 changed files with 86 additions and 29 deletions

View File

@ -33,6 +33,12 @@ func (z *Zfs) gatherPoolStats(acc telegraf.Accumulator) (string, error) {
tags := map[string]string{"pool": col[0], "health": col[8]} tags := map[string]string{"pool": col[0], "health": col[8]}
fields := map[string]interface{}{} fields := map[string]interface{}{}
if tags["health"] == "UNAVAIL" {
fields["size"] = int64(0)
} else {
size, err := strconv.ParseInt(col[1], 10, 64) size, err := strconv.ParseInt(col[1], 10, 64)
if err != nil { if err != nil {
return "", fmt.Errorf("Error parsing size: %s", err) return "", fmt.Errorf("Error parsing size: %s", err)
@ -68,6 +74,7 @@ func (z *Zfs) gatherPoolStats(acc telegraf.Accumulator) (string, error) {
return "", fmt.Errorf("Error parsing dedupratio: %s", err) return "", fmt.Errorf("Error parsing dedupratio: %s", err)
} }
fields["dedupratio"] = dedup fields["dedupratio"] = dedup
}
acc.AddFields("zfs_pool", fields, tags) acc.AddFields("zfs_pool", fields, tags)
} }

View File

@ -22,6 +22,15 @@ func mock_zpool() ([]string, error) {
return zpool_output, nil return zpool_output, nil
} }
// $ zpool list -Hp
var zpool_output_unavail = []string{
"temp2 - - - - - - - UNAVAIL -",
}
func mock_zpool_unavail() ([]string, error) {
return zpool_output_unavail, nil
}
// sysctl -q kstat.zfs.misc.arcstats // sysctl -q kstat.zfs.misc.arcstats
// sysctl -q kstat.zfs.misc.vdev_cache_stats // sysctl -q kstat.zfs.misc.vdev_cache_stats
@ -82,6 +91,41 @@ func TestZfsPoolMetrics(t *testing.T) {
acc.AssertContainsTaggedFields(t, "zfs_pool", poolMetrics, tags) acc.AssertContainsTaggedFields(t, "zfs_pool", poolMetrics, tags)
} }
func TestZfsPoolMetrics_unavail(t *testing.T) {
var acc testutil.Accumulator
z := &Zfs{
KstatMetrics: []string{"vdev_cache_stats"},
sysctl: mock_sysctl,
zpool: mock_zpool_unavail,
}
err := z.Gather(&acc)
require.NoError(t, err)
require.False(t, acc.HasMeasurement("zfs_pool"))
acc.Metrics = nil
z = &Zfs{
KstatMetrics: []string{"vdev_cache_stats"},
PoolMetrics: true,
sysctl: mock_sysctl,
zpool: mock_zpool_unavail,
}
err = z.Gather(&acc)
require.NoError(t, err)
//one pool, UNAVAIL
tags := map[string]string{
"pool": "temp2",
"health": "UNAVAIL",
}
poolMetrics := getTemp2PoolMetrics()
acc.AssertContainsTaggedFields(t, "zfs_pool", poolMetrics, tags)
}
func TestZfsGeneratesMetrics(t *testing.T) { func TestZfsGeneratesMetrics(t *testing.T) {
var acc testutil.Accumulator var acc testutil.Accumulator
@ -128,6 +172,12 @@ func getFreeNasBootPoolMetrics() map[string]interface{} {
} }
} }
func getTemp2PoolMetrics() map[string]interface{} {
return map[string]interface{}{
"size": int64(0),
}
}
func getKstatMetricsVdevOnly() map[string]interface{} { func getKstatMetricsVdevOnly() map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
"vdev_cache_stats_misses": int64(87789), "vdev_cache_stats_misses": int64(87789),