Rename TwemproxyInstance.StatsAddr to TwemproxyInstance.Addr

This commit is contained in:
Codeb Fan
2015-11-13 00:38:45 +08:00
parent 8f218ba04a
commit 41c8d74ef0
2 changed files with 10 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ type Twemproxy struct {
} }
type TwemproxyInstance struct { type TwemproxyInstance struct {
StatsAddr string Addr string
Pools []string Pools []string
} }
@@ -26,7 +26,7 @@ var sampleConfig = `
[twemproxy] [twemproxy]
[[twemproxy.instances]] [[twemproxy.instances]]
# Twemproxy stats address and port(NO scheme!) # Twemproxy stats address and port(NO scheme!)
statsAddr = "10.16.29.1:22222" addr = "10.16.29.1:22222"
# Monitor pool name # Monitor pool name
pools = ["redis_pool", "mc_pool"] pools = ["redis_pool", "mc_pool"]
` `
@@ -69,7 +69,7 @@ func (t *Twemproxy) Gather(acc plugins.Accumulator) error {
func (ti *TwemproxyInstance) Gather( func (ti *TwemproxyInstance) Gather(
acc plugins.Accumulator, acc plugins.Accumulator,
) error { ) error {
conn, err := net.DialTimeout("tcp", ti.StatsAddr, 1*time.Second) conn, err := net.DialTimeout("tcp", ti.Addr, 1*time.Second)
if err != nil { if err != nil {
return err return err
} }
@@ -84,7 +84,7 @@ func (ti *TwemproxyInstance) Gather(
} }
tags := make(map[string]string) tags := make(map[string]string)
tags["twemproxy"] = ti.StatsAddr tags["twemproxy"] = ti.Addr
ti.processStat(acc, tags, stats) ti.processStat(acc, tags, stats)
return nil return nil

View File

@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const sampleStatsAddr = "127.0.0.1:22222" const sampleAddr = "127.0.0.1:22222"
const sampleStats = `{ const sampleStats = `{
"total_connections": 276448, "total_connections": 276448,
@@ -61,7 +61,7 @@ const sampleStats = `{
}` }`
func mockTwemproxyServer() (net.Listener, error) { func mockTwemproxyServer() (net.Listener, error) {
listener, err := net.Listen("tcp", sampleStatsAddr) listener, err := net.Listen("tcp", sampleAddr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -87,7 +87,7 @@ func TestGather(t *testing.T) {
twemproxy := &Twemproxy{ twemproxy := &Twemproxy{
Instances: []TwemproxyInstance{ Instances: []TwemproxyInstance{
TwemproxyInstance{ TwemproxyInstance{
StatsAddr: sampleStatsAddr, Addr: sampleAddr,
Pools: []string{"demo"}, Pools: []string{"demo"},
}, },
}, },
@@ -104,7 +104,7 @@ func TestGather(t *testing.T) {
metrics := []string{"total_connections", "curr_connections", "timestamp"} metrics := []string{"total_connections", "curr_connections", "timestamp"}
tags := map[string]string{ tags := map[string]string{
"twemproxy": sampleStatsAddr, "twemproxy": sampleAddr,
"source": sourceData["source"].(string), "source": sourceData["source"].(string),
} }
for _, m := range metrics { for _, m := range metrics {