Style changes and cleanup

This patch makes stylistic changes to error strings, unexports method names by lower casing them, removes unused dataSetMetric, and adds copyright/licence information.

Signed-Off-By: Corey Stewart <stewa169@purdue.edu>
pull/410/head
Corey Stewart 8 years ago committed by Joe Handzik
parent c95bfa705e
commit a8c94d48e6

@ -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.<br/> 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.<br/> Linux (ARC) | [Linux](http://zfsonlinux.org/)
### Disabled by default

@ -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,
)
}

@ -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)
})
})

@ -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

@ -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")
}
}

@ -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()
}

@ -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")
}
}

Loading…
Cancel
Save