bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/metadata_darwin.go (about) 1 package collectors 2 3 import ( 4 "fmt" 5 "strings" 6 "time" 7 8 "bosun.org/metadata" 9 "bosun.org/opentsdb" 10 "bosun.org/util" 11 ) 12 13 func init() { 14 collectors = append(collectors, &IntervalCollector{F: c_meta_darwin_version, Interval: time.Minute * 30}) 15 collectors = append(collectors, &IntervalCollector{F: c_meta_darwin_interfaces, Interval: time.Minute * 30}) 16 } 17 18 func c_meta_darwin_version() (opentsdb.MultiDataPoint, error) { 19 var md opentsdb.MultiDataPoint 20 util.ReadCommand(func(line string) error { 21 metadata.AddMeta("", nil, "uname", line, true) 22 return nil 23 }, "uname", "-a") 24 var name, vers, build string 25 util.ReadCommand(func(line string) error { 26 sp := strings.SplitN(line, ":", 2) 27 if len(sp) != 2 { 28 return nil 29 } 30 v := strings.TrimSpace(sp[1]) 31 switch sp[0] { 32 case "ProductName": 33 name = v 34 case "ProductVersion": 35 vers = v 36 case "BuildVersion": 37 build = v 38 } 39 return nil 40 }, "sw_vers") 41 if name != "" && vers != "" && build != "" { 42 metadata.AddMeta("", nil, "version", fmt.Sprintf("%s.%s", vers, build), true) 43 metadata.AddMeta("", nil, "versionCaption", fmt.Sprintf("%s %s", name, vers), true) 44 } 45 return md, nil 46 } 47 48 func c_meta_darwin_interfaces() (opentsdb.MultiDataPoint, error) { 49 var md opentsdb.MultiDataPoint 50 metaIfaces(nil) 51 return md, nil 52 }