예제 #1
0
func NewRPCExt(name string, maxIdleConnections int, clientBuilder ClientBuilder) *RPCExt {
	r := &RPCExt{
		name:               name,
		clients:            make([]*rpc.Client, 0, maxIdleConnections),
		maxIdleConnections: maxIdleConnections,
		clientBuilder:      clientBuilder,
		closed:             false,

		statRequests:               metrics.NewCounter(),
		statEstablishedConnections: metrics.NewCounter(),
		statLiveConnections:        metrics.NewCounter(),
	}

	m := expvar.NewMap(name + "-rpc")
	m.Set("requests", r.statRequests)
	m.Set("connections.established", r.statEstablishedConnections)
	m.Set("connections.inuse", r.statLiveConnections)
	m.Set("connections.idle", expvar.Func(func() interface{} {
		r.mu.RLock()
		n := len(r.clients)
		r.mu.RUnlock()
		return n
	}))

	return r
}
예제 #2
0
	flagListenAddr      = flag.String("l", "0.0.0.0:5252", "the address to listen on")
	flagPercentiles     = flag.String("p", "0.90,0.99,0.999", "comma separated list of percentiles to record")
	flagGraphite        = flag.String("g", "", "host:port for Graphite's Carbon")
	flagLibratoUsername = flag.String("u", "", "librato metrics username")
	flagLibratoToken    = flag.String("t", "", "librato metrics token")
	flagStatHatEmail    = flag.String("s", "", "StatHat email")
)

var (
	mu              sync.Mutex
	counters        = make(map[string]int64)
	histograms      = make(map[string]metrics.Histogram)
	percentiles     = []float64{}
	percentileNames = []string{}

	statRequestCount    = metrics.NewCounter()
	statRequestRate     = metrics.NewMeter()
	statGraphiteLatency = metrics.NewBiasedHistogram()
	statLibratoLatency  = metrics.NewBiasedHistogram()
	statStatHatLatency  = metrics.NewBiasedHistogram()
)

func init() {
	m := expvar.NewMap("metricsd")
	m.Set("requests", statRequestCount)
	m.Set("requests_per_sec", statRequestRate)
	m.Set("graphite_latency_us", &metrics.HistogramExport{Histogram: statGraphiteLatency,
		Percentiles: []float64{0.5, 0.9, 0.99, 0.999}, PercentileNames: []string{"p50", "p90", "p99", "p999"}})
	m.Set("librato_latency_us", &metrics.HistogramExport{Histogram: statLibratoLatency,
		Percentiles: []float64{0.5, 0.9, 0.99, 0.999}, PercentileNames: []string{"p50", "p90", "p99", "p999"}})
	m.Set("stathat_latency_us", &metrics.HistogramExport{Histogram: statStatHatLatency,
예제 #3
0
파일: client.go 프로젝트: samuel/go-scribe
package scribe

import (
	"expvar"
	"log"
	"net/rpc"

	"github.com/samuel/go-metrics/metrics"
	"github.com/samuel/go-rpcext"
	"github.com/samuel/go-thrift"
)

var (
	statResponseOk       = metrics.NewCounter()
	statResponseTryLater = metrics.NewCounter()
)

func init() {
	m := expvar.NewMap("scribe")
	m.Set("response.ok", statResponseOk)
	m.Set("response.try_later", statResponseTryLater)
}

type ScribeClient struct {
	network string
	addr    string
	client  *rpcext.RPCExt
}

func NewScribeClient(network string, addr string, maxConnections int) (*ScribeClient, error) {
	s := &ScribeClient{