bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/iostat_darwin.go (about) 1 package collectors 2 3 import ( 4 "fmt" 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_iostat_darwin}) 14 } 15 16 func c_iostat_darwin() (opentsdb.MultiDataPoint, error) { 17 var categories []string 18 var md opentsdb.MultiDataPoint 19 ln := 0 20 i := 0 21 util.ReadCommand(func(line string) error { 22 ln++ 23 if ln == 1 { 24 categories = strings.Fields(line) 25 } 26 if ln < 4 { 27 return nil 28 } 29 values := strings.Fields(line) 30 for _, cat := range categories { 31 if i+3 > len(values) { 32 break 33 } else if strings.HasPrefix(cat, "disk") { 34 Add(&md, "darwin.disk.kilobytes_transfer", values[i], opentsdb.TagSet{"disk": cat}, metadata.Unknown, metadata.None, "") 35 i++ 36 Add(&md, "darwin.disk.transactions", values[i], opentsdb.TagSet{"disk": cat}, metadata.Unknown, metadata.None, "") 37 i++ 38 Add(&md, "darwin.disk.megabytes", values[i], opentsdb.TagSet{"disk": cat}, metadata.Unknown, metadata.None, "") 39 i++ 40 } else if cat == "cpu" { 41 Add(&md, "darwin.cpu.user", values[i], nil, metadata.Gauge, metadata.Pct, descDarwinCPUUser) 42 i++ 43 Add(&md, "darwin.cpu.sys", values[i], nil, metadata.Gauge, metadata.Pct, descDarwinCPUSys) 44 i++ 45 Add(&md, "darwin.cpu.idle", values[i], nil, metadata.Gauge, metadata.Pct, descDarwinCPUIdle) 46 i++ 47 } else if cat == "load" { 48 Add(&md, "darwin.loadavg_1_min", values[i], nil, metadata.Unknown, metadata.None, "") 49 i++ 50 Add(&md, "darwin.loadavg_5_min", values[i], nil, metadata.Unknown, metadata.None, "") 51 i++ 52 Add(&md, "darwin.loadavg_15_min", values[i], nil, metadata.Unknown, metadata.None, "") 53 i++ 54 } 55 } 56 return nil 57 }, "iostat", "-c2", "-w1") 58 if ln < 4 { 59 return nil, fmt.Errorf("bad return value") 60 } 61 return md, nil 62 } 63 64 const ( 65 descDarwinCPUUser = "Percent of time in user mode." 66 descDarwinCPUSys = "Percent of time in system mode." 67 descDarwinCPUIdle = "Percent of time in idle mode." 68 )