• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang statsd.NewStatsdClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/quipo/statsd.NewStatsdClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStatsdClient函数的具体用法?Golang NewStatsdClient怎么用?Golang NewStatsdClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewStatsdClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	// Initialize the StatsD client
	prefix := "test.rob-egan."
	statsdclient := statsd.NewStatsdClient(agentServer, prefix)
	err := statsdclient.CreateSocket()
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	interval := time.Second * 2 // aggregate stats and flush every 2 seconds
	stats := statsd.NewStatsdBuffer(interval, statsdclient)
	defer stats.Close()

	// Handler functions
	http.HandleFunc("/", handler)
	http.HandleFunc("/lissajous", func(w http.ResponseWriter, r *http.Request) {
		lissajous(w)
	})
	http.HandleFunc("/debug", debug)
	http.HandleFunc("/count", counter)
	http.HandleFunc("/help", help)

	// The actual web server
	log.Print("Starting web server...\n")
	log.Print("Point your browser to http://", webServerHost, "/help for more info...\n")
	log.Fatal(http.ListenAndServe(webServerHost, nil))
}
开发者ID:robert-egan-zefr,项目名称:Netuitive,代码行数:27,代码来源:webserver.go


示例2: runLoop

func runLoop(redisHost string, redisPort int64, redisDb int64, statsdHost string, statsdPort int64, statsPrefix string, interval int64, queues []string) {
	client := redis.NewClient(&redis.Options{
		Addr: fmt.Sprintf("%s:%d", redisHost, redisPort),
		DB:   redisDb,
	})
	_, connErr := client.Ping().Result()
	fmt.Println("connection errors? ", connErr)

	statsdClient := statsd.NewStatsdClient(
		fmt.Sprintf("%s:%d", statsdHost, statsdPort),
		fmt.Sprintf("%s.", statsPrefix),
	)
	statsdClient.CreateSocket()
	stats := statsd.NewStatsdBuffer(time.Second*2, statsdClient)
	defer stats.Close()
	timeoutInterval := time.Duration(interval) * time.Millisecond
	for true {
		for _, name := range queues {
			go func(oneName string) {
				listLength, err := client.LLen(oneName).Result()
				stats.Gauge(oneName, listLength)
				fmt.Println(oneName, listLength, err)
			}(name)
		}
		time.Sleep(timeoutInterval)
	}
}
开发者ID:scivey,项目名称:celery-statsd,代码行数:27,代码来源:celery_statsd.go


示例3: Connect

func (varnishncsa *Varnishncsa) Connect() {
	statsdclient := statsd.NewStatsdClient(varnishncsa.StatsdServer, varnishncsa.StatsdPrefix)
	statsdclient.CreateSocket()
	interval := time.Duration(int(time.Millisecond) * varnishncsa.StatsdSendInterval)
	stats := statsd.NewStatsdBuffer(interval, statsdclient)
	defer stats.Close()

	cmd := exec.Command("varnishncsa", "-F", `%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i" %{Varnish:time_firstbyte}x`)
	stdout, outerr := cmd.StdoutPipe()
	if outerr != nil {
		log.Fatal(outerr)
	}

	err := cmd.Start()
	if err != nil {
		log.Fatal(err)
	}

	scanner := bufio.NewScanner(stdout)
	for scanner.Scan() {
		r := Record{scanner.Text(), stats, varnishncsa.RecordRegex}
		r.Process()
	}
	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "There was an error with the scanner attached to varnishncsa", err)
	}
	cmd.Wait()
}
开发者ID:asgolding,项目名称:varnish-reporter,代码行数:28,代码来源:varnishncsa.go


示例4: CreateStatsdClient

// CreateStatsdClient creates a local instances of a statsd client. Any errors will be logged to
// console and ignored.
func CreateStatsdClient(statsdURL, statsdPrefix string) error {
	lock.Lock()
	defer lock.Unlock()

	if stats != noopClient {
		// Already initialized. Don't overwrite
		return nil
	}

	if statsdURL != "" {
		hostname, err := os.Hostname()
		if err != nil {
			log.Printf("Could not read hostname. Using default noop statsd client: %s", err)
			return err
		}
		prefix := fmt.Sprintf("%s.%s.artifacts.", statsdPrefix, hostname)

		statsdClient := statsd.NewStatsdClient(statsdURL, prefix)

		if statsdClient != nil {
			stats = statsd.NewStatsdBuffer(updateInterval, statsdClient)
		}
	} else {
		log.Println("No statsd URL provided. Using default noop statsd client")
	}

	return nil
}
开发者ID:dropbox,项目名称:changes-artifacts,代码行数:30,代码来源:stats.go


示例5: InitStatsd

func InitStatsd(ch chan *map[string]map[string]int64, conf *StatsdConfig) error {
	go func() {
		statsdclient := statsd.NewStatsdClient(conf.Host, conf.Prefix)
		statsdclient.CreateSocket()
		interval, err := time.ParseDuration(conf.Interval)
		if err != nil {
			Conf.Logger.Fatalf("can't parse interval %+v", err)
		}
		stats := statsd.NewStatsdBuffer(interval, statsdclient)
		defer stats.Close()
		for data := range statsdCh {
			for op, values := range *data {
				for key, val := range values {
					switch op {
					case "increment":
						debug("send incr", key, val)
						go stats.Incr(key, val)
					case "timing":
						debug("send timing", key, val)
						go stats.Timing(key, val)
					case "gauge":
						debug("send gauge", key, val)
						go stats.Gauge(key, val)
					}
				}

			}
		}
	}()
	return nil
}
开发者ID:pronix,项目名称:logsend,代码行数:31,代码来源:statsd.go


示例6: initStatsd

func initStatsd(address string, prefix string) *statsd.StatsdBuffer {
	statsdclient := statsd.NewStatsdClient(address, prefix)
	statsdclient.CreateSocket()
	interval := time.Second * 10 // aggregate stats and flush every 2 seconds
	stats := statsd.NewStatsdBuffer(interval, statsdclient)
	return stats
}
开发者ID:kureikain,项目名称:fdns,代码行数:7,代码来源:server.go


示例7: mustStartStatsd

func mustStartStatsd(host string, prefix string, frequency time.Duration) *statsd.StatsdBuffer {
	sClient := statsd.NewStatsdClient(opts.StatsDHost, opts.StatsDPrefix)
	if err := sClient.CreateSocket(); err != nil {
		log.WithField("error", err).Fatal("could not open socket to statsd")
	}

	return statsd.NewStatsdBuffer(opts.statsdFrequency, sClient)
}
开发者ID:christian-blades-cb,项目名称:docker-event-metrics,代码行数:8,代码来源:main.go


示例8: main

func main() {

	setupHTTP()

	uaaURL, err := url.Parse(uaa)

	if nil != err {
		panic("Failed to parse uaa url!")
	}

	creds, err := uaaclientcredentials.New(uaaURL, true, clientID, clientSecret)

	if nil != err {
		panic("Failed to obtain creds!")
	}

	consumer := noaa.NewConsumer(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)

	httpStartStopProcessor := processors.NewHttpStartStopProcessor()
	sender := statsd.NewStatsdClient(statsdAddress, statsdPrefix)
	sender.CreateSocket()

	var processedMetrics []metrics.Metric

	msgChan := make(chan *events.Envelope)
	go func() {
		defer close(msgChan)
		errorChan := make(chan error)
		token, err := creds.GetBearerToken()
		if nil != err {
			panic(err)
		}
		go consumer.Firehose(firehoseSubscriptionID, token, msgChan, errorChan, nil)

		for err := range errorChan {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}
	}()

	for msg := range msgChan {
		eventType := msg.GetEventType()

		switch eventType {
		case events.Envelope_HttpStartStop:
			processedMetrics = httpStartStopProcessor.Process(msg)
		default:
			atomic.AddUint64(&count, 1)
			// do nothing
		}

		if len(processedMetrics) > 0 {
			for _, metric := range processedMetrics {
				metric.Send(sender)
			}
		}
		processedMetrics = nil
	}
}
开发者ID:malston,项目名称:watchman,代码行数:58,代码来源:main.go


示例9: getStatsdBuffer

func getStatsdBuffer(host string) (*statsd.StatsdBuffer, error) {
	statsdclient := statsd.NewStatsdClient(host, "aws.sqs.")
	if err := statsdclient.CreateSocket(); err != nil {
		log.WithField("error", err).Warn("unable to open socket for statsd")
		return nil, err
	}

	return statsd.NewStatsdBuffer(time.Minute, statsdclient), nil
}
开发者ID:christian-blades-cb,项目名称:sqs-statsd,代码行数:9,代码来源:main.go


示例10: NewStatsdClient

func NewStatsdClient(simulationPrefix string) *StatsdClient {
	statsdClient := statsd.NewStatsdClient("localhost:8125", simulationPrefix)
	statsdClient.CreateSocket()
	interval := time.Second * 2
	stats := statsd.NewStatsdBuffer(interval, statsdClient)
	return &StatsdClient{
		Stats: stats,
	}
}
开发者ID:kvasukib,项目名称:go-chord,代码行数:9,代码来源:stats.go


示例11: ConnectToURL

func ConnectToURL(s string, prefix string) (c *statsd.StatsdClient, err error) {
	statsdUrl, err := url.Parse(s)

	if err != nil {
		return nil, err
	}

	c = statsd.NewStatsdClient(statsdUrl.Host, prefix)
	err = c.CreateSocket()
	return c, err
}
开发者ID:seatgeek,项目名称:go-statsdurl,代码行数:11,代码来源:statsdurl.go


示例12: main

func main() {
	consumer := noaa.NewConsumer(DopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)

	httpStartStopProcessor := processors.NewHttpStartStopProcessor()
	valueMetricProcessor := processors.NewValueMetricProcessor()
	containerMetricProcessor := processors.NewContainerMetricProcessor()
	heartbeatProcessor := processors.NewHeartbeatProcessor()
	counterProcessor := processors.NewCounterProcessor()

	sender := statsd.NewStatsdClient(statsdAddress, statsdPrefix)
	sender.CreateSocket()

	var processedMetrics []metrics.Metric

	msgChan := make(chan *events.Envelope)
	go func() {
		defer close(msgChan)
		errorChan := make(chan error)
		go consumer.Firehose(firehoseSubscriptionId, authToken, msgChan, errorChan, nil)

		for err := range errorChan {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}
	}()

	for msg := range msgChan {
		eventType := msg.GetEventType()

		// graphite-nozzle can handle CounterEvent, ContainerMetric, Heartbeat,
		// HttpStartStop and ValueMetric events
		switch eventType {
		case events.Envelope_ContainerMetric:
			processedMetrics = containerMetricProcessor.Process(msg)
		case events.Envelope_CounterEvent:
			processedMetrics = counterProcessor.Process(msg)
		case events.Envelope_Heartbeat:
			processedMetrics = heartbeatProcessor.Process(msg)
		case events.Envelope_HttpStartStop:
			processedMetrics = httpStartStopProcessor.Process(msg)
		case events.Envelope_ValueMetric:
			processedMetrics = valueMetricProcessor.Process(msg)
		default:
			// do nothing
		}

		if len(processedMetrics) > 0 {
			for _, metric := range processedMetrics {
				metric.Send(sender)
			}
		}
		processedMetrics = nil
	}
}
开发者ID:simonjohansson,项目名称:graphite-nozzle,代码行数:53,代码来源:main.go


示例13: Initialize

func (driver *QuipoStatsdDriver) Initialize(connectionString string) error {
	client := quipo.NewStatsdClient(connectionString, "")
	err := client.CreateSocket()

	if err != nil {
		return err
	}

	driver.conn = client
	driver.connectionString = connectionString

	return nil
}
开发者ID:descomplica,项目名称:pencil,代码行数:13,代码来源:pencil.go


示例14: main

func main() {
	fmt.Println("Starting eISCP (ethernet Integra Serial Communication Protocol) Gateway")
	// Command line options
	flag.BoolVar(&debug, "debug", false, "enable verbose debugging")
	flag.BoolVar(&statsEnabled, "stats", false, "enable stats collecting")
	flag.StringVar(&defaultDevice, "device", "192.168.2.143", "IP address of device to connect to")
	flag.IntVar(&devicePort, "port", 60128, "port on device to commmunicate with")
	flag.IntVar(&defaultPort, "serve", 3000, "port to host REST API on")
	flag.StringVar(&statsdAddress, "statsd", "localhost:8125", "IP and Port of Statsd server")
	flag.StringVar(&statsdPrefix, "prefix", "eiscp", "A prefix prepended to all stats")

	// Now that we've defined our flags, parse them
	flag.Parse()

	if debug {
		fmt.Println("Displaying debug output.")
	}

	// init
	statsdclient := statsd.NewStatsdClient(statsdAddress, statsdPrefix)
	if statsEnabled {
		if debug {
			fmt.Println("Attempting connection to statsd")
		}
		statsdclient.CreateSocket()
		interval := time.Second * 2 // aggregate stats and flush every 2 seconds
		stats = statsd.NewStatsdBuffer(interval, statsdclient)
		defer stats.Close()
	}

	fmt.Println("Searching for device on port", devicePort, "at", defaultDevice)

	// Do our device stuff here
	go func() {
		for true {
			deviceLoop()
		}
	}()

	r := mux.NewRouter()
	r.HandleFunc("/kill", HandleKill) //Debug Function
	r.HandleFunc("/status/", GetStatus).Methods("GET")
	r.HandleFunc("/device/", DeleteDevice).Methods("DELETE")
	r.HandleFunc("/device/{ip}/{port}", PutDevice).Methods("PUT")
	r.HandleFunc("/device/{property}", GetProperty).Methods("GET")
	r.HandleFunc("/device/{property}/{value}", PostProperty).Methods("POST")
	http.Handle("/", r)

	fmt.Println("REST API listening on port", strconv.Itoa(defaultPort))
	http.ListenAndServe(":"+strconv.Itoa(defaultPort), nil)
}
开发者ID:Lyr3x,项目名称:eiscp-gateway,代码行数:51,代码来源:gateway.go


示例15: TestMain

func TestMain(m *testing.M) {
	var statsdHost = flag.String("test_statsd_host", "", "Statsd server hostname or IP")
	var statsdInterval = flag.Int("test_statsd_interval", 3, "Seconds between metric flush")
	var statsdPrefix = flag.String("test_statsd_prefix", "gopassivedns", "statsd metric prefix")

	flag.Parse()

	if *statsdHost != "" {
		statsdclient := statsd.NewStatsdClient(*statsdHost, *statsdPrefix)
		stats = statsd.NewStatsdBuffer(time.Duration(*statsdInterval)*time.Second, statsdclient)
	}

	os.Exit(m.Run())
}
开发者ID:Phillipmartin,项目名称:gopassivedns,代码行数:14,代码来源:main_test.go


示例16: connect

func (s *StatsdPump) connect() *statsd.StatsdClient {
	client := statsd.NewStatsdClient(s.dbConf.Address, "")

	err := client.CreateSocket()
	if err != nil {
		log.WithFields(logrus.Fields{
			"prefix": statsdPrefix,
		}).Error("StatsD connection failed:", err)
		time.Sleep(5)
		s.connect()
	}

	return client
}
开发者ID:TykTechnologies,项目名称:tyk-pump,代码行数:14,代码来源:statsd.go


示例17: BenchmarkQuipoTimingAsDuration

func BenchmarkQuipoTimingAsDuration(b *testing.B) {
	s := newServer()
	c := quipo.NewStatsdBuffer(flushPeriod, quipo.NewStatsdClient(addr, prefix))
	c.Logger = logger{}
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		c.Incr(counterKey, 1)
		c.Gauge(gaugeKey, gaugeValue)
		c.PrecisionTiming(timingKey, tValDur)
	}
	c.Close()
	b.StopTimer()
	s.Close()
}
开发者ID:Dieterbe,项目名称:statsdbench,代码行数:14,代码来源:statsdbench_test.go


示例18: BenchmarkQuipo

func BenchmarkQuipo(b *testing.B) {
	s := newServer()
	c := quipo.NewStatsdBuffer(flushPeriod, quipo.NewStatsdClient(s.Addr(), prefix))
	c.Logger = logger{}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		c.Incr(counterKey, 1)
		c.Gauge(gaugeKey, gaugeValue)
		c.Timing(timingKey, int64(timingValue))
	}
	c.Close()
	s.Close()
}
开发者ID:alexcesaro,项目名称:statsdbench,代码行数:15,代码来源:statsdbench_test.go


示例19: main

func main() {

	//insert the ENV as defaults here, then after the parse we add the true defaults if nothing has been set
	//also convert true/false strings to true/false types

	config := initConfig()

	if config.cpuprofile != "" {
		f, err := os.Create(config.cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	var stats *statsd.StatsdBuffer = nil

	if config.statsdHost != "" {
		statsdclient := statsd.NewStatsdClient(config.statsdHost, config.statsdPrefix+"."+config.sensorName+".")
		stats = statsd.NewStatsdBuffer(time.Duration(config.statsdInterval)*time.Second, statsdclient)
	}

	handle := initHandle(config)

	if handle == nil {
		log.Fatal("Could not initilize the capture.")
	}

	logOpts := NewLogOptions(config)

	logChan := initLogging(logOpts)

	reChan := make(chan tcpDataStruct)

	//spin up logging thread(s)
	go logConn(logChan, logOpts, stats)

	//spin up the actual capture threads
	doCapture(handle, logChan, config, reChan, stats)

	log.Debug("Done!  Goodbye.")
	os.Exit(0)

}
开发者ID:Phillipmartin,项目名称:gopassivedns,代码行数:45,代码来源:main.go


示例20: InitStatsd

func InitStatsd(conf interface{}) {
	host := conf.(map[string]interface{})["host"].(string)
	prefix := ""
	_interval := "1s"
	if val, ok := conf.(map[string]interface{})["prefix"].(string); ok {
		prefix = val
	}
	if val, ok := conf.(map[string]interface{})["interval"].(string); ok {
		_interval = val
	}
	statsdclient := statsd.NewStatsdClient(host, prefix)

	statsdclient.CreateSocket()
	interval, err := time.ParseDuration(_interval)
	if err != nil {
		Conf.Logger.Fatalf("can't parse interval %+v", err)
	}
	stats := statsd.NewStatsdBuffer(interval, statsdclient)
	go func() {
		defer stats.Close()
		Conf.Logger.Println("Statsd queue is starts")
		for data := range statsdCh {
			for op, values := range *data {
				for key, val := range values {
					switch op {
					case "increment":
						debug("send incr", key, val)
						go stats.Incr(key, val)
					case "timing":
						debug("send timing", key, val)
						go stats.Timing(key, val)
					case "gauge":
						debug("send gauge", key, val)
						go stats.Gauge(key, val)
					}
				}

			}
		}

	}()
	return
}
开发者ID:4honor,项目名称:logsend,代码行数:43,代码来源:statsd_sender.go



注:本文中的github.com/quipo/statsd.NewStatsdClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang uritemplates.Expand函数代码示例发布时间:2022-05-28
下一篇:
Golang toolkit.NewStrBuffer函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap