read contents of objset file (#1632)
* added objread functionality Signed-off-by: Sudharshann D <sudhar287@gmail.com>
This commit is contained in:
parent
f87e566df9
commit
6807e5319b
9 changed files with 238 additions and 6 deletions
|
|
@ -90,6 +90,31 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error {
|
|||
}
|
||||
}
|
||||
|
||||
zpoolObjsetPaths, err := filepath.Glob(procFilePath(filepath.Join(c.linuxProcpathBase, c.linuxZpoolObjsetPath)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if zpoolObjsetPaths == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, zpoolPath := range zpoolObjsetPaths {
|
||||
file, err := os.Open(zpoolPath)
|
||||
if err != nil {
|
||||
// this file should exist, but there is a race where an exporting pool can remove the files -- ok to ignore
|
||||
level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath)
|
||||
return errZFSNotAvailable
|
||||
}
|
||||
|
||||
err = c.parsePoolObjsetFile(file, zpoolPath, func(poolName string, datasetName string, s zfsSysctl, v uint64) {
|
||||
ch <- c.constPoolObjsetMetric(poolName, datasetName, s, v)
|
||||
})
|
||||
file.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -168,3 +193,43 @@ func (c *zfsCollector) parsePoolProcfsFile(reader io.Reader, zpoolPath string, h
|
|||
|
||||
return scanner.Err()
|
||||
}
|
||||
|
||||
func (c *zfsCollector) parsePoolObjsetFile(reader io.Reader, zpoolPath string, handler func(string, string, zfsSysctl, uint64)) error {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
parseLine := false
|
||||
var zpoolName, datasetName string
|
||||
for scanner.Scan() {
|
||||
parts := strings.Fields(scanner.Text())
|
||||
|
||||
if !parseLine && len(parts) == 3 && parts[0] == "name" && parts[1] == "type" && parts[2] == "data" {
|
||||
parseLine = true
|
||||
continue
|
||||
}
|
||||
|
||||
if !parseLine || len(parts) < 3 {
|
||||
continue
|
||||
}
|
||||
if parts[0] == "dataset_name" {
|
||||
zpoolPathElements := strings.Split(zpoolPath, "/")
|
||||
pathLen := len(zpoolPathElements)
|
||||
zpoolName = zpoolPathElements[pathLen-2]
|
||||
datasetName = parts[2]
|
||||
continue
|
||||
}
|
||||
|
||||
if parts[1] == kstatDataUint64 {
|
||||
key := fmt.Sprintf("kstat.zfs.misc.objset.%s", parts[0])
|
||||
value, err := strconv.ParseUint(parts[2], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not parse expected integer value for %q", key)
|
||||
}
|
||||
handler(zpoolName, datasetName, zfsSysctl(key), value)
|
||||
}
|
||||
}
|
||||
if !parseLine {
|
||||
return fmt.Errorf("did not parse a single %s %s metric", zpoolName, datasetName)
|
||||
}
|
||||
|
||||
return scanner.Err()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue