bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/dfstat_darwin.go (about)

     1  package collectors
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  
     7  	"bosun.org/metadata"
     8  	"bosun.org/opentsdb"
     9  	"bosun.org/util"
    10  )
    11  
    12  func init() {
    13  	collectors = append(collectors, &IntervalCollector{F: c_dfstat_darwin})
    14  }
    15  
    16  func c_dfstat_darwin() (opentsdb.MultiDataPoint, error) {
    17  	var md opentsdb.MultiDataPoint
    18  	util.ReadCommand(func(line string) error {
    19  		fields := strings.Fields(line)
    20  		if line == "" || len(fields) < 9 || !IsDigit(fields[2]) {
    21  			return nil
    22  		}
    23  		mount := fields[8]
    24  		if strings.HasPrefix(mount, "/Volumes/Time Machine Backups") {
    25  			return nil
    26  		}
    27  		f5, _ := strconv.Atoi(fields[5])
    28  		f6, _ := strconv.Atoi(fields[6])
    29  		tags := opentsdb.TagSet{"mount": mount}
    30  		Add(&md, "darwin.disk.fs.total", fields[1], tags, metadata.Unknown, metadata.None, "")
    31  		Add(&md, "darwin.disk.fs.used", fields[2], tags, metadata.Unknown, metadata.None, "")
    32  		Add(&md, "darwin.disk.fs.free", fields[3], tags, metadata.Unknown, metadata.None, "")
    33  		Add(&md, "darwin.disk.fs.inodes.total", f5+f6, tags, metadata.Unknown, metadata.None, "")
    34  		Add(&md, "darwin.disk.fs.inodes.used", fields[5], tags, metadata.Unknown, metadata.None, "")
    35  		Add(&md, "darwin.disk.fs.inodes.free", fields[6], tags, metadata.Unknown, metadata.None, "")
    36  		return nil
    37  	}, "df", "-lki")
    38  	return md, nil
    39  }