本文整理汇总了Golang中github.com/peterbourgon/g2s.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dial函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
s, err := g2s.Dial("udp", "54.200.145.61:8125")
if err != nil {
return
}
s.Counter(1.0, "test.g2s", 1)
}
开发者ID:magastzheng,项目名称:go-2,代码行数:7,代码来源:statsd.go
示例2: setupServices
// setup connections to other services running on this host
func setupServices() {
var error error
services.Statsd, error = g2s.Dial("udp", "localhost:8125")
if error != nil {
log.Fatal("could not set up statsd client.")
}
services.Memcached = memcache.New("localhost:11211")
// setup push service
usingSandbox := "true" // true or false
uniqushResponse, uniqushError := http.PostForm("http://localhost:9898/addpsp", url.Values{
"pushservicetype": {"apns"},
"service": {"newspeak"},
"cert": {"/etc/newspeak/apns-certs/cert.pem"},
"key": {"/etc/newspeak/apns-certs/priv-noenc.pem"},
"sandbox": {usingSandbox},
})
if uniqushError != nil {
log.Fatal("could not add push service provider for apple push notifications: " + string(uniqushError.Error()))
} else {
uniqushResponseBodyBytes, uniqushError := ioutil.ReadAll(uniqushResponse.Body)
uniqushResponseBody := string(uniqushResponseBodyBytes)
uniqushResponse.Body.Close()
if uniqushError != nil {
log.Fatal("could not read response when adding push service provider for apple push notifications: " + string(uniqushError.Error()))
} else if uniqushResponseBody[0:30] != "[AddPushServiceProvider][Info]" {
log.Fatal("invalid response when adding push service provider for apple push notifications: " + uniqushResponseBody)
} else {
fmt.Println("added push service provider for apple push notifications. usingSandbox:" + usingSandbox + ", uniqush response:" + uniqushResponseBody)
}
}
}
开发者ID:newspeak,项目名称:newspeak-server,代码行数:33,代码来源:main.go
示例3: main
func main() {
// Parse command line arguments
var (
config_file = flag.String("config", "", "Path to configuration file")
)
flag.Parse()
// Load configuration into package variable Config
config_error := gcfg.ReadFileInto(&Config, *config_file)
if config_error != nil {
log.Fatal("Could not load config file: " + config_error.Error())
}
// Instantiate StatsD connection
if Config.Statsd.Host == "" {
StatsD = g2s.Noop()
} else {
StatsD, _ = g2s.Dial(Config.Statsd.Protocol, Config.Statsd.Host+":"+Config.Statsd.Port)
}
// Log startup
log.Println("go-airbrake-proxy started")
// Fire up an HTTP server and handle it
http.HandleFunc("/", httpHandler)
http.ListenAndServe(Config.Listen.Host+":"+Config.Listen.Port, nil)
}
开发者ID:WheresWardy,项目名称:go-airbrake-proxy,代码行数:27,代码来源:server.go
示例4: Dial
func Dial(proto, addr string) *Statsd {
st, err := g2s.Dial(proto, addr)
if err != nil {
log.Printf("Couldn't initiate statsd with address: '%s'", addr)
return nil
}
return &Statsd{st}
}
开发者ID:vinays,项目名称:goodies,代码行数:9,代码来源:statsd.go
示例5: loadStatsd
func loadStatsd(addr string) g2s.Statter {
s, err := g2s.Dial("udp", addr)
if err != nil {
log.Warnf("Error initialising statsd connection to %v", addr)
return nil
}
return s
}
开发者ID:armada-io,项目名称:h2,代码行数:9,代码来源:instrumentation.go
示例6: CreateClient
func (s *StatsD) CreateClient() {
if s.Enabled && s.Client == nil {
log.Println("StatsD is enabled")
client, err := g2s.Dial("udp", s.Host)
if err != nil {
log.Fatalf("Cannot connect to statsd server %v: %v ", s.Host, err)
}
s.Client = client
}
}
开发者ID:rthomas,项目名称:bamboo,代码行数:11,代码来源:statsd.go
示例7: init
func init() {
addr := DEFAULT_STATSD_HOST
if env := os.Getenv(ENV_STATSD); env != "" {
addr = env
}
s, err := g2s.Dial("udp", addr)
if err != nil {
log.Critical(err)
os.Exit(-1)
}
_statter = s
}
开发者ID:gameogre,项目名称:agent,代码行数:13,代码来源:proxy.go
示例8: main
func main() {
configtoml := flag.String("f", "moxy.toml", "Path to config. (default moxy.toml)")
flag.Parse()
file, err := ioutil.ReadFile(*configtoml)
if err != nil {
log.Fatal(err)
}
err = toml.Unmarshal(file, &config)
if err != nil {
log.Fatal("Problem parsing config: ", err)
}
if config.Statsd != "" {
statsd, _ = g2s.Dial("udp", config.Statsd)
}
moxystats := stats.New()
mux := http.NewServeMux()
mux.HandleFunc("/moxy_callback", moxy_callback)
mux.HandleFunc("/moxy_apps", moxy_apps)
mux.HandleFunc("/moxy_stats", func(w http.ResponseWriter, req *http.Request) {
if config.Xproxy != "" {
w.Header().Add("X-Proxy", config.Xproxy)
}
stats := moxystats.Data()
b, _ := json.MarshalIndent(stats, "", " ")
w.Write(b)
return
})
mux.HandleFunc("/", moxy_proxy)
// In case we want to log req/resp.
//trace, _ := trace.New(redirect, os.Stdout)
handler := moxystats.Handler(mux)
s := &http.Server{
Addr: ":" + config.Port,
Handler: handler,
}
callbackworker()
callbackqueue <- true
if config.TLS {
log.Println("Starting moxy tls on :" + config.Port)
err := s.ListenAndServeTLS(config.Cert, config.Key)
if err != nil {
log.Fatal(err)
}
} else {
log.Println("Starting moxy on :" + config.Port)
err := s.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}
}
开发者ID:abhishekamralkar,项目名称:moxy,代码行数:51,代码来源:moxy.go
示例9: loadStatsd
func loadStatsd(addr string) g2s.Statter {
disabled := config.AtPath("hailo", "service", "instrumentation", "statsd", "disabled").AsBool()
if disabled {
return g2s.Noop()
}
s, err := g2s.Dial("udp", addr)
if err != nil {
log.Warnf("Error initialising statsd connection to %v", addr)
return nil
}
return s
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:14,代码来源:instrumentation.go
示例10: init
func init() {
addr := DEFAULT_STATSD_HOST
if env := os.Getenv(ENV_STATSD); env != "" {
addr = env
}
s, err := g2s.Dial("udp", addr)
if err != nil {
println(err)
os.Exit(-1)
}
_statter = s
go pprof_task()
}
开发者ID:tonycoming,项目名称:libs,代码行数:15,代码来源:pprof.go
示例11: BenchmarkG2s
func BenchmarkG2s(b *testing.B) {
s := newServer()
c, err := g2s.Dial("udp", addr)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
c.Counter(1, counterKey, 1)
c.Gauge(1, gaugeKey, strconv.Itoa(gaugeValue))
c.Timing(1, timingKey, tValDur)
}
b.StopTimer()
s.Close()
}
开发者ID:Dieterbe,项目名称:statsdbench,代码行数:15,代码来源:statsdbench_test.go
示例12: init
func init() {
addr := DEFAULT_STATSD_HOST
if env := os.Getenv(ENV_STATSD); env != "" {
addr = env
}
s, err := g2s.Dial("udp", addr)
if err == nil {
_statter = s
} else {
_statter = g2s.Noop()
log.Println(err)
}
go pprof_task()
}
开发者ID:gonet2,项目名称:auth,代码行数:16,代码来源:pprof.go
示例13: setupStatsd
func setupStatsd() (g2s.Statter, error) {
if config.Statsd.Addr == "" {
return g2s.Noop(), nil
}
if config.Statsd.Namespace == "" {
hostname, _ := os.Hostname()
config.Statsd.Namespace = "nixy." + hostname
}
if config.Statsd.SampleRate < 1 || config.Statsd.SampleRate > 100 {
config.Statsd.SampleRate = 100
}
return g2s.Dial("udp", config.Statsd.Addr)
}
开发者ID:martensson,项目名称:nixy,代码行数:16,代码来源:stats.go
示例14: main
func main() {
configtoml := flag.String("f", "nixy.toml", "Path to config. (default nixy.toml)")
version := flag.Bool("v", false, "prints current nixy version")
flag.Parse()
if *version {
fmt.Println(VERSION)
os.Exit(0)
}
file, err := ioutil.ReadFile(*configtoml)
if err != nil {
log.Fatal(err)
}
err = toml.Unmarshal(file, &config)
if err != nil {
log.Fatal("Problem parsing config: ", err)
}
if config.Statsd != "" {
statsd, _ = g2s.Dial("udp", config.Statsd)
}
nixystats := stats.New()
//mux := http.NewServeMux()
mux := mux.NewRouter()
mux.HandleFunc("/", nixy_version)
mux.HandleFunc("/v1/reload", nixy_reload)
mux.HandleFunc("/v1/apps", nixy_apps)
mux.HandleFunc("/v1/health", nixy_health)
mux.HandleFunc("/v1/stats", func(w http.ResponseWriter, req *http.Request) {
stats := nixystats.Data()
b, _ := json.MarshalIndent(stats, "", " ")
w.Write(b)
return
})
handler := nixystats.Handler(mux)
s := &http.Server{
Addr: ":" + config.Port,
Handler: handler,
}
eventStream()
eventWorker()
log.Println("Starting nixy on :" + config.Port)
err = s.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}
开发者ID:abhishekamralkar,项目名称:nixy,代码行数:45,代码来源:nixy.go
示例15: ExamplePanel_stats
func ExamplePanel_stats() {
// This example demonstrates how to push circuit breaker stats to statsd via a Panel.
// This example uses g2s. Anything conforming to the Statter interface can be used.
s, err := g2s.Dial("udp", "statsd-server:8125")
if err != nil {
log.Fatal(err)
}
breaker := NewThresholdBreaker(10)
panel := NewPanel()
panel.Statter = s
panel.StatsPrefixf = "sys.production"
panel.Add("x", breaker)
breaker.Trip() // sys.production.circuit.x.tripped
breaker.Reset() // sys.production.circuit.x.reset, sys.production.circuit.x.trip-time
breaker.Fail() // sys.production.circuit.x.fail
breaker.Ready() // sys.production.circuit.x.ready (if it's tripped and ready to retry)
}
开发者ID:andreas,项目名称:circuitbreaker,代码行数:19,代码来源:example_test.go
示例16: main
func main() {
var conf Config
fn := Nop
confpath := flag.String("conf", "servers.json", "")
flag.Parse()
file, _ := ioutil.ReadFile(*confpath)
json.Unmarshal(file, &conf)
if conf.Statsd != "" {
e, _ := g2s.Dial("udp", conf.Statsd)
fn = (&Statsd{e}).Report
}
NewYardstick(conf.Listen, conf.Peers, fn).Run()
<-make(chan struct{})
}
开发者ID:hugopeixoto,项目名称:yardstick,代码行数:22,代码来源:main.go
示例17: main
func main() {
configtoml := flag.String("f", "nixy.toml", "Path to config. (default nixy.toml)")
version := flag.Bool("v", false, "prints current nixy version")
flag.Parse()
if *version {
fmt.Println(VERSION)
os.Exit(0)
}
file, err := ioutil.ReadFile(*configtoml)
if err != nil {
log.Fatal(err)
}
err = toml.Unmarshal(file, &config)
if err != nil {
log.Fatal("Problem parsing config: ", err)
}
if config.Statsd != "" {
statsd, _ = g2s.Dial("udp", config.Statsd)
}
mux := mux.NewRouter()
mux.HandleFunc("/", nixy_version)
mux.HandleFunc("/v1/reload", nixy_reload)
mux.HandleFunc("/v1/config", nixy_config)
mux.HandleFunc("/v1/health", nixy_health)
s := &http.Server{
Addr: ":" + config.Port,
Handler: mux,
}
endpoint = config.Marathon[0] // lets start with the first node.
endpointHealth()
eventStream()
eventWorker()
log.Println("Starting nixy on :" + config.Port)
err = s.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}
开发者ID:burakbostancioglu,项目名称:nixy,代码行数:38,代码来源:nixy.go
示例18: runCollector
func runCollector() {
for !flag.Parsed() {
// Defer execution of this goroutine.
runtime.Gosched()
// Add an initial delay while the program initializes to avoid attempting to collect
// metrics prior to our flags being available / parsed.
time.Sleep(1 * time.Second)
}
s, err := g2s.Dial("udp", *statsd)
if err != nil {
panic(fmt.Sprintf("Unable to connect to Statsd on %s - %s", *statsd, err))
}
if *prefix == "<detect-hostname>" {
hn, err := os.Hostname()
if err != nil {
*prefix = "go.unknown"
} else {
*prefix = "go." + hn
}
}
*prefix += "."
gaugeFunc := func(key string, val uint64) {
s.Gauge(1.0, *prefix+key, strconv.FormatUint(val, 10))
}
c := collector.New(gaugeFunc)
c.PauseDur = time.Duration(*pause) * time.Second
c.EnableCPU = *cpu
c.EnableMem = *mem
c.EnableGC = *gc
c.Run()
}
开发者ID:brunoqc,项目名称:go-runtime-metrics,代码行数:36,代码来源:runstats.go
示例19: NewStatsdBackend
// Instanciate a new Backend that will send data to a statsd instance
func NewStatsdBackend(host, port, protocol, prefix string) (Backend, error) {
if host == "" {
return nil, fmt.Errorf("Statsd host cannot be empty")
}
if port == "" {
port = "8125"
}
if protocol == "" {
protocol = "udp"
}
if prefix == "" {
prefix = "checks."
}
statsd, err := g2s.Dial(protocol, net.JoinHostPort(host, port))
if err != nil {
return nil, err
}
return &statsdBackend{statsd: statsd, prefix: prefix}, nil
}
开发者ID:40a,项目名称:libpoller,代码行数:25,代码来源:backend_statsd.go
示例20: main
func main() {
var (
redisInstances = flag.String("redis.instances", "", "Semicolon-separated list of comma-separated lists of Redis instances")
redisConnectTimeout = flag.Duration("redis.connect.timeout", 3*time.Second, "Redis connect timeout")
redisReadTimeout = flag.Duration("redis.read.timeout", 3*time.Second, "Redis read timeout")
redisWriteTimeout = flag.Duration("redis.write.timeout", 3*time.Second, "Redis write timeout")
redisMCPI = flag.Int("redis.mcpi", 2, "Max connections per Redis instance")
redisHash = flag.String("redis.hash", "murmur3", "Redis hash function: murmur3, fnv, fnva")
maxSize = flag.Int("max.size", 10000, "Maximum number of events per key")
batchSize = flag.Int("batch.size", 100, "keys to select per request")
maxKeysPerSecond = flag.Int64("max.keys.per.second", 1000, "max keys per second to walk")
scanLogInterval = flag.Duration("scan.log.interval", 5*time.Second, "how often to report scan rates in log")
once = flag.Bool("once", false, "walk entire keyspace once and exit (default false, walk forever)")
statsdAddress = flag.String("statsd.address", "", "Statsd address (blank to disable)")
statsdSampleRate = flag.Float64("statsd.sample.rate", 0.1, "Statsd sample rate for normal metrics")
statsdBucketPrefix = flag.String("statsd.bucket.prefix", "myservice.", "Statsd bucket key prefix, including trailing period")
httpAddress = flag.String("http.address", ":6060", "HTTP listen address (profiling endpoints only)")
)
flag.Parse()
log.SetFlags(log.Lmicroseconds)
// Validate integer arguments.
if *maxKeysPerSecond < int64(*batchSize) {
log.Fatal("max keys per second should be bigger than batch size")
}
// Set up statsd instrumentation, if it's specified.
stats := g2s.Noop()
if *statsdAddress != "" {
var err error
stats, err = g2s.Dial("udp", *statsdAddress)
if err != nil {
log.Fatal(err)
}
}
instr := statsd.New(stats, float32(*statsdSampleRate), *statsdBucketPrefix)
// Parse hash function.
var hashFunc func(string) uint32
switch strings.ToLower(*redisHash) {
case "murmur3":
hashFunc = pool.Murmur3
case "fnv":
hashFunc = pool.FNV
case "fnva":
hashFunc = pool.FNVa
default:
log.Fatalf("unknown hash '%s'", *redisHash)
}
// Set up the clusters.
clusters, err := makeClusters(
*redisInstances,
*redisConnectTimeout, *redisReadTimeout, *redisWriteTimeout,
*redisMCPI,
hashFunc,
*maxSize,
instr,
)
if err != nil {
log.Fatal(err)
}
// HTTP server for profiling
go func() { log.Print(http.ListenAndServe(*httpAddress, nil)) }()
// Set up our rate limiter. Remember: it's per-key, not per-request.
freq := time.Duration(1/(*maxKeysPerSecond)) * time.Second
bucket := tb.NewBucket(*maxKeysPerSecond, freq)
// Build the farm
readStrategy := farm.SendAllReadAll
repairStrategy := farm.AllRepairs // blocking
dst := farm.New(clusters, len(clusters), readStrategy, repairStrategy, instr)
// Perform the walk
begin := time.Now()
for {
src := scan(clusters, *batchSize, *scanLogInterval) // new key set
walkOnce(dst, bucket, src, *maxSize, instr)
if *once {
break
}
}
log.Printf("walk complete in %s", time.Since(begin))
}
开发者ID:jbouwman,项目名称:roshi,代码行数:86,代码来源:main.go
注:本文中的github.com/peterbourgon/g2s.Dial函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论