Fix multiple redis server bug, do not cache the TCP connections

Fixes #178
This commit is contained in:
Cameron Sparr 2015-09-10 11:21:40 -06:00
parent a55f6498c8
commit f7a4317990
2 changed files with 29 additions and 35 deletions

View File

@ -11,6 +11,7 @@ will still be backwards compatible if only `url` is specified.
### Bugfixes ### Bugfixes
- [#170](https://github.com/influxdb/telegraf/issues/170): Systemd support - [#170](https://github.com/influxdb/telegraf/issues/170): Systemd support
- [#175](https://github.com/influxdb/telegraf/issues/175): Set write precision before gathering metrics - [#175](https://github.com/influxdb/telegraf/issues/175): Set write precision before gathering metrics
- [#178](https://github.com/influxdb/telegraf/issues/178): redis plugin, multiple server thread hang bug
## v0.1.8 [2015-09-04] ## v0.1.8 [2015-09-04]

View File

@ -15,9 +15,6 @@ import (
type Redis struct { type Redis struct {
Servers []string Servers []string
c net.Conn
buf []byte
} }
var sampleConfig = ` var sampleConfig = `
@ -112,8 +109,6 @@ func (r *Redis) Gather(acc plugins.Accumulator) error {
const defaultPort = "6379" const defaultPort = "6379"
func (r *Redis) gatherServer(addr *url.URL, acc plugins.Accumulator) error { func (r *Redis) gatherServer(addr *url.URL, acc plugins.Accumulator) error {
if r.c == nil {
_, _, err := net.SplitHostPort(addr.Host) _, _, err := net.SplitHostPort(addr.Host)
if err != nil { if err != nil {
addr.Host = addr.Host + ":" + defaultPort addr.Host = addr.Host + ":" + defaultPort
@ -123,6 +118,7 @@ func (r *Redis) gatherServer(addr *url.URL, acc plugins.Accumulator) error {
if err != nil { if err != nil {
return fmt.Errorf("Unable to connect to redis server '%s': %s", addr.Host, err) return fmt.Errorf("Unable to connect to redis server '%s': %s", addr.Host, err)
} }
defer c.Close()
if addr.User != nil { if addr.User != nil {
pwd, set := addr.User.Password() pwd, set := addr.User.Password()
@ -141,12 +137,9 @@ func (r *Redis) gatherServer(addr *url.URL, acc plugins.Accumulator) error {
} }
} }
r.c = c c.Write([]byte("info\r\n"))
}
r.c.Write([]byte("info\r\n")) rdr := bufio.NewReader(c)
rdr := bufio.NewReader(r.c)
line, err := rdr.ReadString('\n') line, err := rdr.ReadString('\n')
if err != nil { if err != nil {