bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/opentsdb.go (about) 1 package collectors 2 3 import ( 4 "encoding/json" 5 "net/http" 6 7 "bosun.org/metadata" 8 "bosun.org/opentsdb" 9 ) 10 11 func init() { 12 collectors = append(collectors, &IntervalCollector{F: c_opentsdb, Enable: enableURL(tsdbURL)}) 13 } 14 15 const tsdbURL = "http://localhost:4242/api/stats" 16 17 func c_opentsdb() (opentsdb.MultiDataPoint, error) { 18 resp, err := http.Get(tsdbURL) 19 if err != nil { 20 return nil, err 21 } 22 defer resp.Body.Close() 23 var md, tmp opentsdb.MultiDataPoint 24 if err := json.NewDecoder(resp.Body).Decode(&tmp); err != nil { 25 return nil, err 26 } 27 for _, v := range tmp { 28 delete(v.Tags, "host") 29 AddTS(&md, v.Metric, v.Timestamp, v.Value, v.Tags, metadata.Unknown, metadata.None, "") 30 } 31 return md, nil 32 }