0.3.0 Removing internal parallelism: twemproxy and rabbitmq

This commit is contained in:
Cameron Sparr
2015-12-19 20:26:18 -07:00
parent c8914679b7
commit 2e764cb22d
2 changed files with 43 additions and 93 deletions

View File

@@ -5,28 +5,21 @@ import (
"errors"
"io/ioutil"
"net"
"strings"
"sync"
"time"
"github.com/influxdb/telegraf/plugins"
)
type Twemproxy struct {
Instances []TwemproxyInstance
}
type TwemproxyInstance struct {
Addr string
Pools []string
}
var sampleConfig = `
[[plugins.twemproxy.instances]]
# Twemproxy stats address and port (no scheme)
addr = "localhost:22222"
# Monitor pool name
pools = ["redis_pool", "mc_pool"]
# Twemproxy stats address and port (no scheme)
addr = "localhost:22222"
# Monitor pool name
pools = ["redis_pool", "mc_pool"]
`
func (t *Twemproxy) SampleConfig() string {
@@ -39,35 +32,7 @@ func (t *Twemproxy) Description() string {
// Gather data from all Twemproxy instances
func (t *Twemproxy) Gather(acc plugins.Accumulator) error {
var wg sync.WaitGroup
errorChan := make(chan error, len(t.Instances))
for _, inst := range t.Instances {
wg.Add(1)
go func(inst TwemproxyInstance) {
defer wg.Done()
if err := inst.Gather(acc); err != nil {
errorChan <- err
}
}(inst)
}
wg.Wait()
close(errorChan)
errs := []string{}
for err := range errorChan {
errs = append(errs, err.Error())
}
if len(errs) == 0 {
return nil
}
return errors.New(strings.Join(errs, "\n"))
}
// Gather data from one Twemproxy
func (ti *TwemproxyInstance) Gather(
acc plugins.Accumulator,
) error {
conn, err := net.DialTimeout("tcp", ti.Addr, 1*time.Second)
conn, err := net.DialTimeout("tcp", t.Addr, 1*time.Second)
if err != nil {
return err
}
@@ -82,14 +47,14 @@ func (ti *TwemproxyInstance) Gather(
}
tags := make(map[string]string)
tags["twemproxy"] = ti.Addr
ti.processStat(acc, tags, stats)
tags["twemproxy"] = t.Addr
t.processStat(acc, tags, stats)
return nil
}
// Process Twemproxy server stats
func (ti *TwemproxyInstance) processStat(
func (t *Twemproxy) processStat(
acc plugins.Accumulator,
tags map[string]string,
data map[string]interface{},
@@ -111,19 +76,19 @@ func (ti *TwemproxyInstance) processStat(
}
acc.AddFields("twemproxy", fields, tags)
for _, pool := range ti.Pools {
for _, pool := range t.Pools {
if poolStat, ok := data[pool]; ok {
if data, ok := poolStat.(map[string]interface{}); ok {
poolTags := copyTags(tags)
poolTags["pool"] = pool
ti.processPool(acc, poolTags, data)
t.processPool(acc, poolTags, data)
}
}
}
}
// Process pool data in Twemproxy stats
func (ti *TwemproxyInstance) processPool(
func (t *Twemproxy) processPool(
acc plugins.Accumulator,
tags map[string]string,
data map[string]interface{},
@@ -143,7 +108,7 @@ func (ti *TwemproxyInstance) processPool(
serverTags[key] = copyTags(tags)
serverTags[key]["server"] = key
}
ti.processServer(acc, serverTags[key], data)
t.processServer(acc, serverTags[key], data)
}
}
}
@@ -151,7 +116,7 @@ func (ti *TwemproxyInstance) processPool(
}
// Process backend server(redis/memcached) stats
func (ti *TwemproxyInstance) processServer(
func (t *Twemproxy) processServer(
acc plugins.Accumulator,
tags map[string]string,
data map[string]interface{},