support query endpoint and change default listen port
This commit is contained in:
parent
6b5a9d34bb
commit
6e791357ef
|
@ -5,7 +5,7 @@ The plugin expects messages in the InfluxDB line-protocol ONLY, other Telegraf i
|
|||
The intent of the plugin is to allow Telegraf to serve as a proxy/router for the /write endpoint of the InfluxDB HTTP API.
|
||||
|
||||
See: [Telegraf Input Data Formats](https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md#influx).
|
||||
Example: curl -i -XPOST 'http://localhost:8086/write' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
|
||||
Example: curl -i -XPOST 'http://localhost:8186/write' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
|
||||
|
||||
### Configuration:
|
||||
|
||||
|
@ -15,7 +15,7 @@ This is a sample configuration for the plugin.
|
|||
# # Influx HTTP write listener
|
||||
[[inputs.http_listener]]
|
||||
## Address and port to host HTTP listener on
|
||||
service_address = ":8086"
|
||||
service_address = ":8186"
|
||||
|
||||
## timeouts in seconds
|
||||
read_timeout = "10"
|
||||
|
|
|
@ -31,7 +31,7 @@ type HttpListener struct {
|
|||
|
||||
const sampleConfig = `
|
||||
## Address and port to host HTTP listener on
|
||||
service_address = ":8086"
|
||||
service_address = ":8186"
|
||||
|
||||
## timeouts in seconds
|
||||
read_timeout = "10"
|
||||
|
@ -103,7 +103,10 @@ 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 path = req.URL.Path[1:]
|
||||
|
||||
if path == "write" {
|
||||
log.Printf("Received write request: [%s]\n", string(body))
|
||||
|
||||
var metrics []telegraf.Metric
|
||||
if len(body) == 0 {
|
||||
|
@ -121,6 +124,17 @@ func (t *HttpListener) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|||
res.WriteHeader(204)
|
||||
res.Write([]byte(""))
|
||||
}
|
||||
} else if path == "query" {
|
||||
// Deliver a dummy response to the query endpoint, as some InfluxDB clients test endpoint availability with a query
|
||||
log.Printf("Received query request: [%s]\n", string(body))
|
||||
res.WriteHeader(200)
|
||||
res.Write([]byte("{\"results\":[]}"))
|
||||
} else {
|
||||
// Don't know how to respond to calls to other endpoints
|
||||
log.Printf("Received unknown %s request: [%s]\n", path, string(body))
|
||||
res.WriteHeader(404)
|
||||
res.Write([]byte("Not Found"))
|
||||
}
|
||||
} else {
|
||||
log.Printf("Problem reading request: [%s], Error: %s\n", string(body), err)
|
||||
res.WriteHeader(500)
|
||||
|
|
Loading…
Reference in New Issue