diff --git a/README.md b/README.md
index ae9e4a54..ba0b74bb 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ stat | Exposes various statistics from `/proc/stat`. This includes CPU usage, bo
textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_
time | Exposes the current system time. | _any_
vmstat | Exposes statistics from `/proc/vmstat`. | Linux
-zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics.
FreeBSD (ARC, zpool), Linux (ARC) | [FreeBSD](https://www.freebsd.org/doc/handbook/zfs.html), [Linux](http://zfsonlinux.org/)
+zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics.
Linux (ARC) | [Linux](http://zfsonlinux.org/)
### Disabled by default
diff --git a/collector/zfs.go b/collector/zfs.go
index 9749a0b3..71e59eba 100644
--- a/collector/zfs.go
+++ b/collector/zfs.go
@@ -1,3 +1,16 @@
+// Copyright 2016 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package collector
// +build linux freebsd
@@ -33,11 +46,6 @@ type zfsMetric struct {
sysctl zfsSysctl // The sysctl of the ZFS metric.
}
-type datasetMetric struct {
- subsystem zfsSubsystemName
- name string
-}
-
// Collector
func init() {
@@ -53,8 +61,12 @@ func NewZFSCollector() (Collector, error) {
}
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
+ // Arcstats
+ err = c.updateArcstats(ch)
+ if err != nil {
+ return err
+ }
- err = c.zfsAvailable()
switch {
case err == zfsNotAvailableError:
log.Debug(err)
@@ -63,12 +75,6 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
return err
}
- // Arcstats
- err = c.updateArcstats(ch)
- if err != nil {
- return err
- }
-
// Pool stats
return c.updatePoolStats(ch)
}
@@ -78,8 +84,7 @@ func (s zfsSysctl) metricName() string {
return parts[len(parts)-1]
}
-func (c *zfsCollector) ConstSysctlMetric(subsystem zfsSubsystemName, sysctl zfsSysctl, value zfsMetricValue) prometheus.Metric {
-
+func (c *zfsCollector) constSysctlMetric(subsystem zfsSubsystemName, sysctl zfsSysctl, value zfsMetricValue) prometheus.Metric {
metricName := sysctl.metricName()
return prometheus.MustNewConstMetric(
@@ -93,17 +98,3 @@ func (c *zfsCollector) ConstSysctlMetric(subsystem zfsSubsystemName, sysctl zfsS
float64(value),
)
}
-
-func (c *zfsCollector) ConstZpoolMetric(pool, name string, value float64) prometheus.Metric {
- return prometheus.MustNewConstMetric(
- prometheus.NewDesc(
- prometheus.BuildFQName(Namespace, string(zpoolSubsystem), name),
- name,
- []string{"pool"},
- nil,
- ),
- prometheus.UntypedValue,
- float64(value),
- pool,
- )
-}
diff --git a/collector/zfs_freebsd.go b/collector/zfs_freebsd.go
index 9d344dc8..ed90a7e2 100644
--- a/collector/zfs_freebsd.go
+++ b/collector/zfs_freebsd.go
@@ -58,7 +58,7 @@ func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) {
err = c.RunOnStdout(cmd, func(stdout io.Reader) error {
return c.parseArcstatsSysctlOutput(stdout, func(sysctl zfsSysctl, value zfsMetricValue) {
- ch <- c.ConstSysctlMetric(arc, sysctl, zfsMetricValue(value))
+ ch <- c.constSysctlMetric(arc, sysctl, zfsMetricValue(value))
})
})
return err
@@ -102,7 +102,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) (err error)
err = c.RunOnStdout(cmd, func(stdout io.Reader) error {
return c.parseZpoolOutput(stdout, func(pool, name string, value float64) {
- ch <- c.ConstZpoolMetric(pool, name, value)
+ ch <- c.constZpoolMetric(pool, name, value)
})
})
diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go
index 0a1c10e1..17cfcaed 100644
--- a/collector/zfs_linux.go
+++ b/collector/zfs_linux.go
@@ -1,3 +1,16 @@
+// Copyright 2016 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package collector
import (
@@ -17,14 +30,6 @@ const (
zfsArcstatsProcpath = "spl/kstat/zfs/arcstats"
)
-func (c *zfsCollector) zfsAvailable() (err error) {
- file, err := c.openArcstatsFile()
- if err != nil {
- file.Close()
- }
- return err
-}
-
func (c *zfsCollector) openArcstatsFile() (file *os.File, err error) {
file, err = os.Open(procFilePath(zfsArcstatsProcpath))
if err != nil {
@@ -35,7 +40,6 @@ func (c *zfsCollector) openArcstatsFile() (file *os.File, err error) {
}
func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) {
-
file, err := c.openArcstatsFile()
if err != nil {
return err
@@ -43,13 +47,11 @@ func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) {
defer file.Close()
return c.parseArcstatsProcfsFile(file, func(s zfsSysctl, v zfsMetricValue) {
- ch <- c.ConstSysctlMetric(arc, s, v)
+ ch <- c.constSysctlMetric(arc, s, v)
})
-
}
func (c *zfsCollector) parseArcstatsProcfsFile(reader io.Reader, handler func(zfsSysctl, zfsMetricValue)) (err error) {
-
scanner := bufio.NewScanner(reader)
parseLine := false
diff --git a/collector/zfs_linux_test.go b/collector/zfs_linux_test.go
index 2640ebac..7583281d 100644
--- a/collector/zfs_linux_test.go
+++ b/collector/zfs_linux_test.go
@@ -1,3 +1,16 @@
+// Copyright 2016 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package collector
import (
@@ -6,7 +19,6 @@ import (
)
func TestArcstatsParsing(t *testing.T) {
-
arcstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/arcstats")
if err != nil {
t.Fatal(err)
@@ -40,5 +52,4 @@ func TestArcstatsParsing(t *testing.T) {
if !handlerCalled {
t.Fatal("Arcstats parsing handler was not called for some expected sysctls")
}
-
}
diff --git a/collector/zfs_zpool.go b/collector/zfs_zpool.go
index 8ebdba9a..a8dc36dd 100644
--- a/collector/zfs_zpool.go
+++ b/collector/zfs_zpool.go
@@ -1,3 +1,16 @@
+// Copyright 2016 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package collector
import (
@@ -11,13 +24,12 @@ import (
// zpool metrics
func (c *zfsCollector) parseZpoolOutput(reader io.Reader, handler func(string, string, float64)) (err error) {
-
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
if len(fields) != 4 {
- return fmt.Errorf("Unexpected output of zpool command")
+ return fmt.Errorf("unexpected output of zpool command")
}
valueString := fields[2]
@@ -37,5 +49,4 @@ func (c *zfsCollector) parseZpoolOutput(reader io.Reader, handler func(string, s
}
return scanner.Err()
-
}
diff --git a/collector/zfs_zpool_test.go b/collector/zfs_zpool_test.go
index fd09babe..c5822f42 100644
--- a/collector/zfs_zpool_test.go
+++ b/collector/zfs_zpool_test.go
@@ -1,3 +1,16 @@
+// Copyright 2016 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package collector
import (
@@ -6,7 +19,6 @@ import (
)
func TestZpoolParsing(t *testing.T) {
-
zpoolOutput, err := os.Open("fixtures/zfs/zpool_stats_stdout.txt")
if err != nil {
t.Fatal(err)
@@ -55,5 +67,4 @@ func TestZpoolParsing(t *testing.T) {
if zrootCapacity != float64(0.5) {
t.Fatal("Unexpected value for pool 'zroot's capacity value")
}
-
}