diff options
author | Joe Handzik <joseph.t.handzik@hpe.com> | 2017-01-23 10:39:32 -0600 |
---|---|---|
committer | Joe Handzik <joseph.t.handzik@hpe.com> | 2017-01-23 16:28:11 -0600 |
commit | a3125ab4d90e8905017b375579598e77b7966330 (patch) | |
tree | 4bd173da412df60fe94d87c1d3c4905195757046 /collector/zfs_linux.go | |
parent | 2a0c80cbe219cd565a777410d760d2919ed19759 (diff) | |
download | prometheus_node_collector-a3125ab4d90e8905017b375579598e77b7966330.tar.bz2 prometheus_node_collector-a3125ab4d90e8905017b375579598e77b7966330.tar.xz prometheus_node_collector-a3125ab4d90e8905017b375579598e77b7966330.zip |
ZFS Collector: Add zfetchstats functionality
Signed-Off-By: Joe Handzik <joseph.t.handzik@hpe.com>
Diffstat (limited to 'collector/zfs_linux.go')
-rw-r--r-- | collector/zfs_linux.go | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index 17cfcae..02404a4 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go | |||
@@ -15,10 +15,10 @@ package collector | |||
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "bufio" | 17 | "bufio" |
18 | "errors" | ||
19 | "fmt" | 18 | "fmt" |
20 | "io" | 19 | "io" |
21 | "os" | 20 | "os" |
21 | "path/filepath" | ||
22 | "strconv" | 22 | "strconv" |
23 | "strings" | 23 | "strings" |
24 | 24 | ||
@@ -27,31 +27,45 @@ import ( | |||
27 | ) | 27 | ) |
28 | 28 | ||
29 | const ( | 29 | const ( |
30 | zfsArcstatsProcpath = "spl/kstat/zfs/arcstats" | 30 | zfsProcpathBase = "spl/kstat/zfs/" |
31 | zfsArcstatsExt = "arcstats" | ||
32 | zfsFetchstatsExt = "zfetchstats" | ||
31 | ) | 33 | ) |
32 | 34 | ||
33 | func (c *zfsCollector) openArcstatsFile() (file *os.File, err error) { | 35 | func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) { |
34 | file, err = os.Open(procFilePath(zfsArcstatsProcpath)) | 36 | file, err = os.Open(procFilePath(path)) |
35 | if err != nil { | 37 | if err != nil { |
36 | log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", procFilePath(zfsArcstatsProcpath)) | 38 | log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", procFilePath(path)) |
37 | err = zfsNotAvailableError | 39 | err = zfsNotAvailableError |
38 | } | 40 | } |
39 | return | 41 | return |
40 | } | 42 | } |
41 | 43 | ||
42 | func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) { | 44 | func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) { |
43 | file, err := c.openArcstatsFile() | 45 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsArcstatsExt)) |
44 | if err != nil { | 46 | if err != nil { |
45 | return err | 47 | return err |
46 | } | 48 | } |
47 | defer file.Close() | 49 | defer file.Close() |
48 | 50 | ||
49 | return c.parseArcstatsProcfsFile(file, func(s zfsSysctl, v zfsMetricValue) { | 51 | return c.parseProcfsFile(file, zfsArcstatsExt, func(s zfsSysctl, v zfsMetricValue) { |
50 | ch <- c.constSysctlMetric(arc, s, v) | 52 | ch <- c.constSysctlMetric(arc, s, v) |
51 | }) | 53 | }) |
52 | } | 54 | } |
53 | 55 | ||
54 | func (c *zfsCollector) parseArcstatsProcfsFile(reader io.Reader, handler func(zfsSysctl, zfsMetricValue)) (err error) { | 56 | func (c *zfsCollector) updateZfetchstats(ch chan<- prometheus.Metric) (err error) { |
57 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsFetchstatsExt)) | ||
58 | if err != nil { | ||
59 | return err | ||
60 | } | ||
61 | defer file.Close() | ||
62 | |||
63 | return c.parseProcfsFile(file, zfsFetchstatsExt, func(s zfsSysctl, v zfsMetricValue) { | ||
64 | ch <- c.constSysctlMetric(zfetch, s, v) | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmt_ext string, handler func(zfsSysctl, zfsMetricValue)) (err error) { | ||
55 | scanner := bufio.NewScanner(reader) | 69 | scanner := bufio.NewScanner(reader) |
56 | 70 | ||
57 | parseLine := false | 71 | parseLine := false |
@@ -69,7 +83,7 @@ func (c *zfsCollector) parseArcstatsProcfsFile(reader io.Reader, handler func(zf | |||
69 | continue | 83 | continue |
70 | } | 84 | } |
71 | 85 | ||
72 | key := fmt.Sprintf("kstat.zfs.misc.arcstats.%s", parts[0]) | 86 | key := fmt.Sprintf("kstat.zfs.misc.%s.%s", fmt_ext, parts[0]) |
73 | 87 | ||
74 | value, err := strconv.Atoi(parts[2]) | 88 | value, err := strconv.Atoi(parts[2]) |
75 | if err != nil { | 89 | if err != nil { |
@@ -79,7 +93,7 @@ func (c *zfsCollector) parseArcstatsProcfsFile(reader io.Reader, handler func(zf | |||
79 | 93 | ||
80 | } | 94 | } |
81 | if !parseLine { | 95 | if !parseLine { |
82 | return errors.New("did not parse a single arcstat metric") | 96 | return fmt.Errorf("did not parse a single %q metric", fmt_ext) |
83 | } | 97 | } |
84 | 98 | ||
85 | return scanner.Err() | 99 | return scanner.Err() |