fix incredibly stupid bugs
This commit is contained in:
parent
933bdaa067
commit
c4e0452436
2
Godeps
2
Godeps
|
@ -25,6 +25,7 @@ github.com/gorilla/mux c9e326e2bdec29039a3761c07bece13133863e1e
|
|||
github.com/hailocab/go-hostpool e80d13ce29ede4452c43dea11e79b9bc8a15b478
|
||||
github.com/hashicorp/consul 5aa90455ce78d4d41578bafc86305e6e6b28d7d2
|
||||
github.com/hpcloud/tail b2940955ab8b26e19d43a43c4da0475dd81bdb56
|
||||
github.com/hydrogen18/stoppableListener dadc9ccc400c712e5a316107a5c462863919e579
|
||||
github.com/influxdata/config b79f6829346b8d6e78ba73544b1e1038f1f1c9da
|
||||
github.com/influxdata/influxdb e094138084855d444195b252314dfee9eae34cab
|
||||
github.com/influxdata/toml af4df43894b16e3fd2b788d01bd27ad0776ef2d0
|
||||
|
@ -37,7 +38,6 @@ github.com/naoina/go-stringutil 6b638e95a32d0c1131db0e7fe83775cbea4a0d0b
|
|||
github.com/nats-io/nats b13fc9d12b0b123ebc374e6b808c6228ae4234a3
|
||||
github.com/nats-io/nuid 4f84f5f3b2786224e336af2e13dba0a0a80b76fa
|
||||
github.com/nsqio/go-nsq 0b80d6f05e15ca1930e0c5e1d540ed627e299980
|
||||
github.com/opencontainers/runc 89ab7f2ccc1e45ddf6485eaa802c35dcf321dfc8
|
||||
github.com/prometheus/client_golang 18acf9993a863f4c4b40612e19cdd243e7c86831
|
||||
github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6
|
||||
github.com/prometheus/common e8eabff8812b05acf522b45fdcd725a785188e37
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
_ "github.com/influxdata/telegraf/plugins/inputs/filestat"
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/graylog"
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/haproxy"
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/http_listener"
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/http_response"
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/httpjson"
|
||||
_ "github.com/influxdata/telegraf/plugins/inputs/influxdb"
|
||||
|
|
|
@ -13,12 +13,13 @@ import (
|
|||
"io/ioutil"
|
||||
|
||||
"github.com/hydrogen18/stoppableListener"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type HttpListener struct {
|
||||
ServiceAddress string
|
||||
readTimeout int
|
||||
writeTimeout int
|
||||
ReadTimeout string
|
||||
WriteTimeout string
|
||||
|
||||
sync.Mutex
|
||||
|
||||
|
@ -84,44 +85,47 @@ func (t *HttpListener) Stop() {
|
|||
// httpListen listens for HTTP requests.
|
||||
func (t *HttpListener) httpListen() error {
|
||||
|
||||
readTimeout, err := strconv.ParseInt(t.ReadTimeout, 10, 32)
|
||||
writeTimeout, err := strconv.ParseInt(t.WriteTimeout, 10, 32)
|
||||
|
||||
var server = http.Server{
|
||||
Handler: t.writeHandler,
|
||||
ReadTimeout: t.readTimeout * time.Second,
|
||||
WriteTimeout: t.writeTimeout * time.Second,
|
||||
Handler: t,
|
||||
ReadTimeout: time.Duration(readTimeout) * time.Second,
|
||||
WriteTimeout: time.Duration(writeTimeout) * time.Second,
|
||||
}
|
||||
|
||||
var err = server.Serve(t.listener)
|
||||
err = server.Serve(t.listener)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *HttpListener) writeHandler(res http.ResponseWriter, req *http.Request) error {
|
||||
func (t *HttpListener) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
|
||||
if err == nil {
|
||||
log.Printf("Received request: [%s]\n", string(body))
|
||||
|
||||
var metrics []telegraf.Metric
|
||||
for {
|
||||
if len(body) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(body) == 0 {
|
||||
log.Printf("No metrics to parse\n")
|
||||
} else {
|
||||
metrics, err = t.parser.Parse(body)
|
||||
if err == nil {
|
||||
t.storeMetrics(metrics)
|
||||
log.Printf("Persisted %d metrics\n", len(metrics))
|
||||
} else {
|
||||
log.Printf("Problem parsing body: [%s], Error: %s\n", string(body), err)
|
||||
res.WriteHeader(500)
|
||||
res.Write([]byte("ERROR parsing metrics"))
|
||||
}
|
||||
res.WriteHeader(204)
|
||||
res.Write([]byte(""))
|
||||
}
|
||||
res.WriteHeader(204)
|
||||
res.Write([]byte(""))
|
||||
} else {
|
||||
log.Printf("Problem reading request: [%s], Error: %s\n", string(body), err)
|
||||
res.WriteHeader(500)
|
||||
res.Write([]byte("ERROR reading request"))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *HttpListener) storeMetrics(metrics []telegraf.Metric) error {
|
||||
|
|
Loading…
Reference in New Issue