MCPcopy
hub / github.com/prometheus/node_exporter / updatePoolStats

Method updatePoolStats

collector/zfs_linux.go:138–212  ·  view source on GitHub ↗
(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

136}
137
138func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error {
139 zpoolPaths, err := filepath.Glob(procFilePath(filepath.Join(c.linuxProcpathBase, c.linuxZpoolIoPath)))
140 if err != nil {
141 return err
142 }
143
144 for _, zpoolPath := range zpoolPaths {
145 file, err := os.Open(zpoolPath)
146 if err != nil {
147 // this file should exist, but there is a race where an exporting pool can remove the files -- ok to ignore
148 c.logger.Debug("Cannot open file for reading", "path", zpoolPath)
149 return errZFSNotAvailable
150 }
151
152 err = c.parsePoolProcfsFile(file, zpoolPath, func(poolName string, s zfsSysctl, v uint64) {
153 ch <- c.constPoolMetric(poolName, s, v)
154 })
155 file.Close()
156 if err != nil {
157 return err
158 }
159 }
160
161 zpoolObjsetPaths, err := filepath.Glob(procFilePath(filepath.Join(c.linuxProcpathBase, c.linuxZpoolObjsetPath)))
162 if err != nil {
163 return err
164 }
165
166 for _, zpoolPath := range zpoolObjsetPaths {
167 file, err := os.Open(zpoolPath)
168 if err != nil {
169 // This file should exist, but there is a race where an exporting pool can remove the files. Ok to ignore.
170 c.logger.Debug("Cannot open file for reading", "path", zpoolPath)
171 return errZFSNotAvailable
172 }
173
174 err = c.parsePoolObjsetFile(file, zpoolPath, func(poolName string, datasetName string, s zfsSysctl, v uint64) {
175 ch <- c.constPoolObjsetMetric(poolName, datasetName, s, v)
176 })
177 file.Close()
178 if err != nil {
179 return err
180 }
181 }
182
183 zpoolStatePaths, err := filepath.Glob(procFilePath(filepath.Join(c.linuxProcpathBase, c.linuxZpoolStatePath)))
184 if err != nil {
185 return err
186 }
187
188 if zpoolStatePaths == nil {
189 c.logger.Debug("No pool state files found")
190 return nil
191 }
192
193 for _, zpoolPath := range zpoolStatePaths {
194 file, err := os.Open(zpoolPath)
195 if err != nil {

Callers 1

UpdateMethod · 0.95

Calls 8

parsePoolProcfsFileMethod · 0.95
constPoolMetricMethod · 0.95
parsePoolObjsetFileMethod · 0.95
constPoolObjsetMetricMethod · 0.95
parsePoolStateFileMethod · 0.95
constPoolStateMetricMethod · 0.95
procFilePathFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected