bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/exim_linux.go (about) 1 package collectors 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 "time" 8 9 "bosun.org/metadata" 10 "bosun.org/opentsdb" 11 "bosun.org/util" 12 ) 13 14 const eximExiqsumm = "/usr/sbin/exiqsumm" 15 16 func init() { 17 collectors = append(collectors, &IntervalCollector{ 18 F: c_exim_mailq, 19 Interval: time.Minute, 20 Enable: enableExecutable(eximExiqsumm), 21 }) 22 } 23 24 func c_exim_mailq() (opentsdb.MultiDataPoint, error) { 25 var md opentsdb.MultiDataPoint 26 mailq, err := util.Command(time.Minute, nil, "/usr/bin/mailq") 27 if err != nil { 28 return nil, err 29 } 30 util.ReadCommandTimeout(time.Minute, func(line string) error { 31 f := strings.Fields(line) 32 if len(f) == 5 && f[4] == "TOTAL" { 33 Add(&md, "exim.mailq_count", f[0], nil, metadata.Gauge, metadata.EMail, "The number of emails in exim's mail queue.") 34 var multi int64 = 1 35 size, err := strconv.ParseInt(f[1], 10, 64) 36 if err != nil && len(f[1]) > 3 { 37 unit := f[1][len(f[1])-2:] 38 switch unit { 39 case "KB": 40 multi = 1024 41 case "MB": 42 multi = 1024 * 1024 43 default: 44 return fmt.Errorf("error parsing size unit of exim's mail queue") 45 } 46 size, err = strconv.ParseInt(f[1][:len(f[1])-2], 10, 64) 47 if err != nil { 48 return fmt.Errorf("error parsing exim size field") 49 } 50 } 51 Add(&md, "exim.mailq_size", size*multi, nil, metadata.Gauge, metadata.Bytes, descEximMailQSize) 52 oldest, err := opentsdb.ParseDuration(f[2]) 53 if err != nil { 54 return err 55 } 56 Add(&md, "exim.mailq_oldest", oldest.Seconds(), nil, metadata.Gauge, metadata.Second, descEximMailQOldest) 57 newest, err := opentsdb.ParseDuration(f[3]) 58 if err != nil { 59 return err 60 } 61 Add(&md, "exim.mailq_newest", newest.Seconds(), nil, metadata.Gauge, metadata.Second, descEximMailQNewest) 62 } 63 return nil 64 }, mailq, eximExiqsumm) 65 return md, nil 66 } 67 68 const ( 69 descEximMailQSize = "The size of all emails in exim's mail queue." 70 descEximMailQOldest = "Age of the oldest email in exim's mail queue." 71 descEximMailQNewest = "Age of the newest email in exim's mail queue." 72 )