mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-31 08:27:42 -08:00
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>
This commit is contained in:
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_
|
textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_
|
||||||
time | Exposes the current system time. | _any_
|
time | Exposes the current system time. | _any_
|
||||||
vmstat | Exposes statistics from `/proc/vmstat`. | Linux
|
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
|
### 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
|
package collector
|
||||||
|
|
||||||
// +build linux freebsd
|
// +build linux freebsd
|
||||||
|
@ -33,11 +46,6 @@ type zfsMetric struct {
|
||||||
sysctl zfsSysctl // The sysctl of the ZFS metric.
|
sysctl zfsSysctl // The sysctl of the ZFS metric.
|
||||||
}
|
}
|
||||||
|
|
||||||
type datasetMetric struct {
|
|
||||||
subsystem zfsSubsystemName
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collector
|
// Collector
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -53,8 +61,12 @@ func NewZFSCollector() (Collector, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err 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 {
|
switch {
|
||||||
case err == zfsNotAvailableError:
|
case err == zfsNotAvailableError:
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
|
@ -63,12 +75,6 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arcstats
|
|
||||||
err = c.updateArcstats(ch)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pool stats
|
// Pool stats
|
||||||
return c.updatePoolStats(ch)
|
return c.updatePoolStats(ch)
|
||||||
}
|
}
|
||||||
|
@ -78,8 +84,7 @@ func (s zfsSysctl) metricName() string {
|
||||||
return parts[len(parts)-1]
|
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()
|
metricName := sysctl.metricName()
|
||||||
|
|
||||||
return prometheus.MustNewConstMetric(
|
return prometheus.MustNewConstMetric(
|
||||||
|
@ -93,17 +98,3 @@ func (c *zfsCollector) ConstSysctlMetric(subsystem zfsSubsystemName, sysctl zfsS
|
||||||
float64(value),
|
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 {
|
err = c.RunOnStdout(cmd, func(stdout io.Reader) error {
|
||||||
return c.parseArcstatsSysctlOutput(stdout, func(sysctl zfsSysctl, value zfsMetricValue) {
|
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
|
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 {
|
err = c.RunOnStdout(cmd, func(stdout io.Reader) error {
|
||||||
return c.parseZpoolOutput(stdout, func(pool, name string, value float64) {
|
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
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -17,14 +30,6 @@ const (
|
||||||
zfsArcstatsProcpath = "spl/kstat/zfs/arcstats"
|
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) {
|
func (c *zfsCollector) openArcstatsFile() (file *os.File, err error) {
|
||||||
file, err = os.Open(procFilePath(zfsArcstatsProcpath))
|
file, err = os.Open(procFilePath(zfsArcstatsProcpath))
|
||||||
if err != nil {
|
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) {
|
func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) {
|
||||||
|
|
||||||
file, err := c.openArcstatsFile()
|
file, err := c.openArcstatsFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -43,13 +47,11 @@ func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
return c.parseArcstatsProcfsFile(file, func(s zfsSysctl, v zfsMetricValue) {
|
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) {
|
func (c *zfsCollector) parseArcstatsProcfsFile(reader io.Reader, handler func(zfsSysctl, zfsMetricValue)) (err error) {
|
||||||
|
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
|
|
||||||
parseLine := false
|
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
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -6,7 +19,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestArcstatsParsing(t *testing.T) {
|
func TestArcstatsParsing(t *testing.T) {
|
||||||
|
|
||||||
arcstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/arcstats")
|
arcstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/arcstats")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -40,5 +52,4 @@ func TestArcstatsParsing(t *testing.T) {
|
||||||
if !handlerCalled {
|
if !handlerCalled {
|
||||||
t.Fatal("Arcstats parsing handler was not called for some expected sysctls")
|
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
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -11,13 +24,12 @@ import (
|
||||||
// zpool metrics
|
// zpool metrics
|
||||||
|
|
||||||
func (c *zfsCollector) parseZpoolOutput(reader io.Reader, handler func(string, string, float64)) (err error) {
|
func (c *zfsCollector) parseZpoolOutput(reader io.Reader, handler func(string, string, float64)) (err error) {
|
||||||
|
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
|
||||||
fields := strings.Fields(scanner.Text())
|
fields := strings.Fields(scanner.Text())
|
||||||
if len(fields) != 4 {
|
if len(fields) != 4 {
|
||||||
return fmt.Errorf("Unexpected output of zpool command")
|
return fmt.Errorf("unexpected output of zpool command")
|
||||||
}
|
}
|
||||||
|
|
||||||
valueString := fields[2]
|
valueString := fields[2]
|
||||||
|
@ -37,5 +49,4 @@ func (c *zfsCollector) parseZpoolOutput(reader io.Reader, handler func(string, s
|
||||||
|
|
||||||
}
|
}
|
||||||
return scanner.Err()
|
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
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -6,7 +19,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestZpoolParsing(t *testing.T) {
|
func TestZpoolParsing(t *testing.T) {
|
||||||
|
|
||||||
zpoolOutput, err := os.Open("fixtures/zfs/zpool_stats_stdout.txt")
|
zpoolOutput, err := os.Open("fixtures/zfs/zpool_stats_stdout.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -55,5 +67,4 @@ func TestZpoolParsing(t *testing.T) {
|
||||||
if zrootCapacity != float64(0.5) {
|
if zrootCapacity != float64(0.5) {
|
||||||
t.Fatal("Unexpected value for pool 'zroot's capacity value")
|
t.Fatal("Unexpected value for pool 'zroot's capacity value")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue