diff options
author | Joe Handzik <joseph.t.handzik@hpe.com> | 2017-01-25 21:47:48 -0600 |
---|---|---|
committer | Joe Handzik <joseph.t.handzik@hpe.com> | 2017-01-27 14:02:28 -0600 |
commit | e213ccbc57a87016d683aeae1db78a58cf5c6a23 (patch) | |
tree | 5cc74e241d86b95265a242078d839be6f7b0a725 /collector/zfs_linux.go | |
parent | 1dde3ec31ba1d9e50eeff26c44179b411fd21349 (diff) | |
download | prometheus_node_collector-e213ccbc57a87016d683aeae1db78a58cf5c6a23.tar.bz2 prometheus_node_collector-e213ccbc57a87016d683aeae1db78a58cf5c6a23.tar.xz prometheus_node_collector-e213ccbc57a87016d683aeae1db78a58cf5c6a23.zip |
ZFS Collector: Refactor to use maps/slices and fewer globals
Removed all global types that were unnecessary, and refactored to use constructor-created values and inline values instead of globals.
Signed-Off-By: Joe Handzik <joseph.t.handzik@hpe.com>
Diffstat (limited to 'collector/zfs_linux.go')
-rw-r--r-- | collector/zfs_linux.go | 95 |
1 files changed, 6 insertions, 89 deletions
diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index a964da6..6ac5e5a 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go | |||
@@ -26,17 +26,6 @@ import ( | |||
26 | "github.com/prometheus/common/log" | 26 | "github.com/prometheus/common/log" |
27 | ) | 27 | ) |
28 | 28 | ||
29 | const ( | ||
30 | zfsProcpathBase = "spl/kstat/zfs/" | ||
31 | zfsArcstatsExt = "arcstats" | ||
32 | zfsDmuTxExt = "dmu_tx" | ||
33 | zfsFmExt = "fm" | ||
34 | zfsFetchstatsExt = "zfetchstats" | ||
35 | zfsVdevCacheStatsExt = "vdev_cache_stats" | ||
36 | zfsXuioStatsExt = "xuio_stats" | ||
37 | zfsZilExt = "zil" | ||
38 | ) | ||
39 | |||
40 | func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) { | 29 | func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) { |
41 | file, err = os.Open(procFilePath(path)) | 30 | file, err = os.Open(procFilePath(path)) |
42 | if err != nil { | 31 | if err != nil { |
@@ -46,91 +35,19 @@ func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) { | |||
46 | return | 35 | return |
47 | } | 36 | } |
48 | 37 | ||
49 | func (c *zfsCollector) updateArcstats(ch chan<- prometheus.Metric) (err error) { | 38 | func (c *zfsCollector) updateZfsStats(subsystem string, ch chan<- prometheus.Metric) (err error) { |
50 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsArcstatsExt)) | 39 | file, err := c.openProcFile(filepath.Join(c.linuxProcpathBase, c.linuxPathMap[subsystem])) |
51 | if err != nil { | ||
52 | return err | ||
53 | } | ||
54 | defer file.Close() | ||
55 | |||
56 | return c.parseProcfsFile(file, zfsArcstatsExt, func(s zfsSysctl, v zfsMetricValue) { | ||
57 | ch <- c.constSysctlMetric(arc, s, v) | ||
58 | }) | ||
59 | } | ||
60 | |||
61 | func (c *zfsCollector) updateZfetchstats(ch chan<- prometheus.Metric) (err error) { | ||
62 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsFetchstatsExt)) | ||
63 | if err != nil { | ||
64 | return err | ||
65 | } | ||
66 | defer file.Close() | ||
67 | |||
68 | return c.parseProcfsFile(file, zfsFetchstatsExt, func(s zfsSysctl, v zfsMetricValue) { | ||
69 | ch <- c.constSysctlMetric(zfetch, s, v) | ||
70 | }) | ||
71 | } | ||
72 | |||
73 | func (c *zfsCollector) updateZil(ch chan<- prometheus.Metric) (err error) { | ||
74 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsZilExt)) | ||
75 | if err != nil { | ||
76 | return err | ||
77 | } | ||
78 | defer file.Close() | ||
79 | |||
80 | return c.parseProcfsFile(file, zfsZilExt, func(s zfsSysctl, v zfsMetricValue) { | ||
81 | ch <- c.constSysctlMetric(zil, s, v) | ||
82 | }) | ||
83 | } | ||
84 | |||
85 | func (c *zfsCollector) updateVdevCacheStats(ch chan<- prometheus.Metric) (err error) { | ||
86 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsVdevCacheStatsExt)) | ||
87 | if err != nil { | ||
88 | return err | ||
89 | } | ||
90 | defer file.Close() | ||
91 | |||
92 | return c.parseProcfsFile(file, zfsVdevCacheStatsExt, func(s zfsSysctl, v zfsMetricValue) { | ||
93 | ch <- c.constSysctlMetric(vdevCache, s, v) | ||
94 | }) | ||
95 | } | ||
96 | |||
97 | func (c *zfsCollector) updateXuioStats(ch chan<- prometheus.Metric) (err error) { | ||
98 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsXuioStatsExt)) | ||
99 | if err != nil { | ||
100 | return err | ||
101 | } | ||
102 | defer file.Close() | ||
103 | |||
104 | return c.parseProcfsFile(file, zfsXuioStatsExt, func(s zfsSysctl, v zfsMetricValue) { | ||
105 | ch <- c.constSysctlMetric(xuio, s, v) | ||
106 | }) | ||
107 | } | ||
108 | |||
109 | func (c *zfsCollector) updateFm(ch chan<- prometheus.Metric) (err error) { | ||
110 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsFmExt)) | ||
111 | if err != nil { | ||
112 | return err | ||
113 | } | ||
114 | defer file.Close() | ||
115 | |||
116 | return c.parseProcfsFile(file, zfsFmExt, func(s zfsSysctl, v zfsMetricValue) { | ||
117 | ch <- c.constSysctlMetric(fm, s, v) | ||
118 | }) | ||
119 | } | ||
120 | |||
121 | func (c *zfsCollector) updateDmuTx(ch chan<- prometheus.Metric) (err error) { | ||
122 | file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsDmuTxExt)) | ||
123 | if err != nil { | 40 | if err != nil { |
124 | return err | 41 | return err |
125 | } | 42 | } |
126 | defer file.Close() | 43 | defer file.Close() |
127 | 44 | ||
128 | return c.parseProcfsFile(file, zfsDmuTxExt, func(s zfsSysctl, v zfsMetricValue) { | 45 | return c.parseProcfsFile(file, c.linuxPathMap[subsystem], func(s zfsSysctl, v int) { |
129 | ch <- c.constSysctlMetric(dmuTx, s, v) | 46 | ch <- c.constSysctlMetric(subsystem, s, v) |
130 | }) | 47 | }) |
131 | } | 48 | } |
132 | 49 | ||
133 | func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler func(zfsSysctl, zfsMetricValue)) (err error) { | 50 | func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler func(zfsSysctl, int)) (err error) { |
134 | scanner := bufio.NewScanner(reader) | 51 | scanner := bufio.NewScanner(reader) |
135 | 52 | ||
136 | parseLine := false | 53 | parseLine := false |
@@ -154,7 +71,7 @@ func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler | |||
154 | if err != nil { | 71 | if err != nil { |
155 | return fmt.Errorf("could not parse expected integer value for %q", key) | 72 | return fmt.Errorf("could not parse expected integer value for %q", key) |
156 | } | 73 | } |
157 | handler(zfsSysctl(key), zfsMetricValue(value)) | 74 | handler(zfsSysctl(key), value) |
158 | 75 | ||
159 | } | 76 | } |
160 | if !parseLine { | 77 | if !parseLine { |