當前位置: 首頁>>代碼示例>>Golang>>正文


Golang g2s.Dial函數代碼示例

本文整理匯總了Golang中github.com/peterbourgon/g2s.Dial函數的典型用法代碼示例。如果您正苦於以下問題:Golang Dial函數的具體用法?Golang Dial怎麽用?Golang Dial使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Dial函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/peterbourgon/g2s.Dial函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。