parent
e3c8a1131a
commit
c89ef84df7
|
@ -1,3 +1,8 @@
|
||||||
|
## v0.2.5 [unreleased]
|
||||||
|
|
||||||
|
### Features
|
||||||
|
- [#427](https://github.com/influxdb/telegraf/pull/427): zfs plugin: pool stats added. Thanks @allenpetersen!
|
||||||
|
|
||||||
## v0.2.4 [2015-12-08]
|
## v0.2.4 [2015-12-08]
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
|
@ -16,6 +16,11 @@ type Zfs struct {
|
||||||
PoolMetrics bool
|
PoolMetrics bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type poolInfo struct {
|
||||||
|
name string
|
||||||
|
ioFilename string
|
||||||
|
}
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
# ZFS kstat path
|
# ZFS kstat path
|
||||||
# If not specified, then default is:
|
# If not specified, then default is:
|
||||||
|
@ -37,30 +42,34 @@ func (z *Zfs) Description() string {
|
||||||
return "Read metrics of ZFS from arcstats, zfetchstats and vdev_cache_stats"
|
return "Read metrics of ZFS from arcstats, zfetchstats and vdev_cache_stats"
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPoolStats(kstatPath string, poolMetrics bool, acc plugins.Accumulator) (map[string]string, error) {
|
func getPools(kstatPath string) []poolInfo {
|
||||||
var pools string
|
pools := make([]poolInfo, 0)
|
||||||
poolsDirs, _ := filepath.Glob(kstatPath + "/*/io")
|
poolsDirs, _ := filepath.Glob(kstatPath + "/*/io")
|
||||||
|
|
||||||
for _, poolDir := range poolsDirs {
|
for _, poolDir := range poolsDirs {
|
||||||
poolDirSplit := strings.Split(poolDir, "/")
|
poolDirSplit := strings.Split(poolDir, "/")
|
||||||
pool := poolDirSplit[len(poolDirSplit)-2]
|
pool := poolDirSplit[len(poolDirSplit)-2]
|
||||||
if len(pools) != 0 {
|
pools = append(pools, poolInfo{name: pool, ioFilename: poolDir})
|
||||||
pools += "::"
|
|
||||||
}
|
|
||||||
pools += pool
|
|
||||||
|
|
||||||
if poolMetrics {
|
|
||||||
err := readPoolStats(poolDir, pool, acc)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return map[string]string{"pools": pools}, nil
|
return pools
|
||||||
}
|
}
|
||||||
|
|
||||||
func readPoolStats(poolIoPath string, poolName string, acc plugins.Accumulator) error {
|
func getTags(pools []poolInfo) map[string]string {
|
||||||
lines, err := internal.ReadLines(poolIoPath)
|
var poolNames string
|
||||||
|
|
||||||
|
for _, pool := range pools {
|
||||||
|
if len(poolNames) != 0 {
|
||||||
|
poolNames += "::"
|
||||||
|
}
|
||||||
|
poolNames += pool.name
|
||||||
|
}
|
||||||
|
|
||||||
|
return map[string]string{"pools": poolNames}
|
||||||
|
}
|
||||||
|
|
||||||
|
func gatherPoolStats(pool poolInfo, acc plugins.Accumulator) error {
|
||||||
|
lines, err := internal.ReadLines(pool.ioFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -78,7 +87,7 @@ func readPoolStats(poolIoPath string, poolName string, acc plugins.Accumulator)
|
||||||
return fmt.Errorf("Key and value count don't match Keys:%v Values:%v", keys, values)
|
return fmt.Errorf("Key and value count don't match Keys:%v Values:%v", keys, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
tag := map[string]string{"pool": poolName}
|
tag := map[string]string{"pool": pool.name}
|
||||||
|
|
||||||
for i := 0; i < keyCount; i++ {
|
for i := 0; i < keyCount; i++ {
|
||||||
value, err := strconv.ParseInt(values[i], 10, 64)
|
value, err := strconv.ParseInt(values[i], 10, 64)
|
||||||
|
@ -103,9 +112,16 @@ func (z *Zfs) Gather(acc plugins.Accumulator) error {
|
||||||
kstatPath = "/proc/spl/kstat/zfs"
|
kstatPath = "/proc/spl/kstat/zfs"
|
||||||
}
|
}
|
||||||
|
|
||||||
tags, err := getPoolStats(kstatPath, z.PoolMetrics, acc)
|
pools := getPools(kstatPath)
|
||||||
if err != nil {
|
tags := getTags(pools)
|
||||||
return err
|
|
||||||
|
if z.PoolMetrics {
|
||||||
|
for _, pool := range pools {
|
||||||
|
err := gatherPoolStats(pool, acc)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range kstatMetrics {
|
for _, metric := range kstatMetrics {
|
||||||
|
|
Loading…
Reference in New Issue