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

Golang expvar.NewInt函数代码示例

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

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



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

示例1: init

func init() {
	recordsRead = expvar.NewInt("RecordsRead")
	recordsWritten = expvar.NewInt("RecordsWritten")
	bytesRead = expvar.NewInt("BytesRead")
	bytesWritten = expvar.NewInt("BytesWritten")
	seeks = expvar.NewInt("Seeks")
}
开发者ID:sburnett,项目名称:transformer,代码行数:7,代码来源:leveldb.go


示例2: init

func init() {
	stats.cacheTotal = expvar.NewInt("cache-total")
	stats.cacheBypassed = expvar.NewInt("cache-bypassed")
	stats.cacheHits = expvar.NewInt("cache-hits")
	stats.cacheMisses = expvar.NewInt("cache-misses")
	stats.cacheRecorded = expvar.NewInt("cache-recorded")
}
开发者ID:albertito,项目名称:dnss,代码行数:7,代码来源:resolver.go


示例3: NewPubMetrics

func NewPubMetrics(gw *Gateway) *pubMetrics {
	this := &pubMetrics{
		gw:         gw,
		PubOkMap:   make(map[string]metrics.Counter),
		PubFailMap: make(map[string]metrics.Counter),

		ClientError: metrics.NewRegisteredCounter("pub.clienterr", metrics.DefaultRegistry),
		PubQps:      metrics.NewRegisteredMeter("pub.qps", metrics.DefaultRegistry),
		PubTryQps:   metrics.NewRegisteredMeter("pub.try.qps", metrics.DefaultRegistry),
		JobQps:      metrics.NewRegisteredMeter("job.qps", metrics.DefaultRegistry),
		JobTryQps:   metrics.NewRegisteredMeter("job.try.qps", metrics.DefaultRegistry),
		PubMsgSize:  metrics.NewRegisteredHistogram("pub.msgsize", metrics.DefaultRegistry, metrics.NewExpDecaySample(1028, 0.015)),
		JobMsgSize:  metrics.NewRegisteredHistogram("job.msgsize", metrics.DefaultRegistry, metrics.NewExpDecaySample(1028, 0.015)),
		PubLatency:  metrics.NewRegisteredHistogram("pub.latency", metrics.DefaultRegistry, metrics.NewExpDecaySample(1028, 0.015)),
	}

	if Options.DebugHttpAddr != "" {
		this.expPubOk = expvar.NewInt("PubOk")
		this.expPubFail = expvar.NewInt("PubFail")
		this.expActiveConns = expvar.NewInt("PubConns")       // TODO
		this.expActiveUpstream = expvar.NewInt("PubUpstream") // TODO
	}

	return this
}
开发者ID:funkygao,项目名称:gafka,代码行数:25,代码来源:metrics_pub.go


示例4: init

/*
 * Initializations
 */
func init() {
	flag.Parse()
	status.InputEventCount = expvar.NewInt("input_event_count")
	status.OutputEventCount = expvar.NewInt("output_event_count")
	status.ErrorCount = expvar.NewInt("error_count")

	expvar.Publish("connection_status",
		expvar.Func(func() interface{} {
			res := make(map[string]interface{}, 0)
			res["last_connect_time"] = status.LastConnectTime
			res["last_error_text"] = status.LastConnectError
			res["last_error_time"] = status.ErrorTime
			if status.IsConnected {
				res["connected"] = true
				res["uptime"] = time.Now().Sub(status.LastConnectTime).Seconds()
			} else {
				res["connected"] = false
				res["uptime"] = 0.0
			}

			return res
		}))
	expvar.Publish("uptime", expvar.Func(func() interface{} {
		return time.Now().Sub(status.StartTime).Seconds()
	}))
	expvar.Publish("subscribed_events", expvar.Func(func() interface{} {
		return config.EventTypes
	}))

	results = make(chan string, 100)
	output_errors = make(chan error)

	status.StartTime = time.Now()
}
开发者ID:carbonblack,项目名称:cb-event-forwarder,代码行数:37,代码来源:main.go


示例5: NewMetrics

//NewMetrics creates
//Metrics object
func NewMetrics() *Metrics {
	metrics = &Metrics{
		true,
		expvar.NewInt("comparisons"),
		expvar.NewInt("errors"),
		expvar.NewString("database"),
	}
	return metrics
}
开发者ID:sohlich,项目名称:go-plag,代码行数:11,代码来源:metrics.go


示例6: main

func main() {
	region := "us-east-1"
	queueName := "example_queue"
	numFetchers := 3

	// set up an SQS service instance
	// note that you can modify the AWS config used - make your own sqsconsumer.AWSConfigOption
	// or just depend on ~/.aws/... or environment variables and don't pass any opts at all
	s, err := sqsconsumer.SQSServiceForQueue(queueName, sqsconsumer.OptAWSRegion(region))
	if err != nil {
		log.Fatalf("Could not set up queue '%s': %s", queueName, err)
	}

	// set up a context which will gracefully cancel the worker on interrupt
	fetchCtx, cancelFetch := context.WithCancel(context.Background())
	term := make(chan os.Signal, 1)
	signal.Notify(term, os.Interrupt, os.Kill)
	go func() {
		<-term
		log.Println("Starting graceful shutdown")
		cancelFetch()
	}()

	// set up metrics - note TrackMetrics does not run the http server, and uses expvar
	exposeMetrics()
	ms := expvar.NewInt(fmt.Sprintf("%s.success", queueName))
	mf := expvar.NewInt(fmt.Sprintf("%s.fail", queueName))
	mt := expvar.NewFloat(fmt.Sprintf("%s.time", queueName))
	track := middleware.TrackMetrics(ms, mf, mt)

	// wrap the handler
	handler := middleware.ApplyDecoratorsToHandler(processMessage, track)

	// start the consumers
	log.Println("Starting queue consumers")

	wg := &sync.WaitGroup{}
	wg.Add(numFetchers)
	for i := 0; i < numFetchers; i++ {
		go func() {
			// create the consumer and bind it to a queue and processor function
			c := sqsconsumer.NewConsumer(s, handler)

			// start running the consumer with a context that will be cancelled when a graceful shutdown is requested
			c.Run(fetchCtx)

			wg.Done()
		}()
	}

	// wait for all the consumers to exit cleanly
	wg.Wait()
	log.Println("Shutdown complete")
}
开发者ID:Wattpad,项目名称:sqsconsumer,代码行数:54,代码来源:main.go


示例7: main

func main() {
	countPckRecv := expvar.NewInt(keyCountPckRecv)
	countPckRecv.Set(0)

	countPckSent := expvar.NewInt(keyCountPckSent)
	countPckSent.Set(0)

	countPckErr := expvar.NewInt(keyCountPckErr)
	countPckErr.Set(0)

	UserMap := NewUsers(0, 100)

	http.HandleFunc(userPrefix, func(w http.ResponseWriter, r *http.Request) {
		countPckRecv.Add(1)

		uid := strings.TrimPrefix(r.URL.Path, userPrefix)

		w.Header().Set("Content-Type", "application/json")

		u := UserMap.Get(uid)
		ret := 0
		switch r.Method {
		case "GET":
			if u == nil {
				ret = 2
			}
			res := Response{ReturnCode: ret, Data: u}

			err := json.NewEncoder(w).Encode(res)
			if err != nil {
				http.Error(w, fmt.Sprintf("%s", err), http.StatusInternalServerError)
				return
			}
			// 		case "PUT":
			// 			if u == nil {
			// 				http.Error(w, fmt.Sprintf("%s not found", uid), http.StatusInternalServerError)
			// 				return
			// 			}

		case "POST":
		case "DELETE":
		default:
			http.Error(w, "Method not allow", http.StatusMethodNotAllowed)
			return
		}

		countPckSent.Add(1)
		return
	})

	log.Printf("Running server on :8080")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
开发者ID:phoorichet,项目名称:fserver,代码行数:53,代码来源:main.go


示例8: NewHelloWorldModule

func NewHelloWorldModule() *HelloWorldModule {

	var cfg Config

	ok := logging.ReadModuleConfig(&cfg, "config", "hello") || logging.ReadModuleConfig(&cfg, "files/etc/gosample", "hello")
	if !ok {
		// when the app is run with -e switch, this message will automatically be redirected to the log file specified
		log.Fatalln("failed to read config")
	}

	// this message only shows up if app is run with -debug option, so its great for debugging
	logging.Debug.Println("hello init called", cfg.Server.Name)

	// contohnya: caranya ciptakan nsq consumer
	nsqCfg := nsq.NewConfig()
	q := createNewConsumer(nsqCfg, "random-topic", "test", handler)
	q.SetLogger(log.New(os.Stderr, "nsq:", log.Ltime), nsq.LogLevelError)
	q.ConnectToNSQLookupd("nsqlookupd.local:4161")

	return &HelloWorldModule{
		cfg:       &cfg,
		something: "John Doe",
		stats:     expvar.NewInt("rpsStats"),
		q:         q,
	}

}
开发者ID:tokopedia,项目名称:gosample,代码行数:27,代码来源:init.go


示例9: New

// New returns a new cache with no built-in eviction strategy. The cache's name
// is exposed with stats in expvar.
func New(name string) Cache {
	return &cache{
		fetchers:        make(map[reflect.Type]reflect.Value),
		cache:           make(map[interface{}]*CacheEntry),
		cacheSizeExpVar: expvar.NewInt(fmt.Sprintf("cacheSize (%s)", name)),
	}
}
开发者ID:dpup,项目名称:rcache,代码行数:9,代码来源:cache.go


示例10: NewRedamoServer

func NewRedamoServer(port int, store store.Store) (*redis.Server, error) {
	redamo := &RedamoHandler{}
	redamo.store = store
	redamo.start = time.Now()
	redamo.tcp = expvar.NewInt("tcp")
	return redis.NewServer(redis.DefaultConfig().Port(port).Handler(redamo))
}
开发者ID:no777,项目名称:redamo,代码行数:7,代码来源:handler.go


示例11: main

func main() {
	app := cmd.NewAppShell("activity-monitor", "RPC activity monitor")

	app.Action = func(c cmd.Config, stats statsd.Statter, auditlogger *blog.AuditLogger) {
		go cmd.DebugServer(c.ActivityMonitor.DebugAddr)

		amqpConf := c.ActivityMonitor.AMQP
		server, err := rpc.NewMonitorServer(amqpConf, 0, stats)
		cmd.FailOnError(err, "Could not connect to AMQP")

		ae := analysisengine.NewLoggingAnalysisEngine()

		messages := expvar.NewInt("messages")
		server.HandleDeliveries(rpc.DeliveryHandler(func(d amqp.Delivery) {
			messages.Add(1)
			ae.ProcessMessage(d)
		}))

		go cmd.ProfileCmd("AM", stats)

		err = server.Start(amqpConf)
		cmd.FailOnError(err, "Unable to run Activity Monitor")
	}

	app.Run()
}
开发者ID:bretthoerner,项目名称:boulder,代码行数:26,代码来源:main.go


示例12: NewStats

// NewStats create a new empty stats object
func NewStats() Stats {
	return Stats{
		Status:          "OK",
		EventsReceived:  expvar.NewInt("events_received"),
		EventsSent:      expvar.NewInt("events_sent"),
		EventsIngested:  expvar.NewInt("events_ingested"),
		EventsError:     expvar.NewInt("events_error"),
		EventsDiscarded: expvar.NewInt("events_discarded"),
		QueueSize:       expvar.NewInt("queue_size"),
		QueueMaxSize:    expvar.NewInt("queue_max_size"),
		Clients:         expvar.NewInt("clients"),
		Connections:     expvar.NewInt("connections"),
	}
}
开发者ID:rayyang2000,项目名称:oplog,代码行数:15,代码来源:stats.go


示例13: NewSubMetrics

func NewSubMetrics(gw *Gateway) *subMetrics {
	this := &subMetrics{
		gw:          gw,
		ConsumeMap:  make(map[string]metrics.Counter),
		ConsumedMap: make(map[string]metrics.Counter),
		SubQps:      metrics.NewRegisteredMeter("sub.qps", metrics.DefaultRegistry),
		SubTryQps:   metrics.NewRegisteredMeter("sub.try.qps", metrics.DefaultRegistry),
		ClientError: metrics.NewRegisteredMeter(("sub.clienterr"), metrics.DefaultRegistry),
	}

	if Options.DebugHttpAddr != "" {
		this.expConsumeOk = expvar.NewInt("ConsumeOk")
		this.expActiveConns = expvar.NewInt("ConsumeConns")       // TODO
		this.expActiveUpstream = expvar.NewInt("ConsumeUpstream") // TODO
	}

	return this
}
开发者ID:funkygao,项目名称:gafka,代码行数:18,代码来源:metrics_sub.go


示例14: TestSnapshotExpvars

func TestSnapshotExpvars(t *testing.T) {
	test := expvar.NewInt("test")
	test.Add(42)

	vals := map[string]int64{}
	snapshotExpvars(vals)

	assert.Equal(t, vals["test"], int64(42))
}
开发者ID:ChongFeng,项目名称:beats,代码行数:9,代码来源:logp_test.go


示例15: init

func init() {
	currentTar = expvar.NewString("CurrentTar")
	tarBytesRead = expvar.NewInt("TarBytesRead")
	tarsFailed = expvar.NewInt("TarsFailed")
	nestedTarsFailed = expvar.NewInt("NestedTarsFailed")
	tarsIndexed = expvar.NewInt("TarsIndexed")
	nestedTarsIndexed = expvar.NewInt("NestedTarsIndexed")
	tarsSkipped = expvar.NewInt("TarsSkipped")
	logsFailed = expvar.NewInt("TracesFailed")
	logsIndexed = expvar.NewInt("TracesIndexed")
}
开发者ID:sburnett,项目名称:bismark-tools,代码行数:11,代码来源:index.go


示例16: TestPublish

func TestPublish(t *testing.T) {

	// setup
	port := 2003
	mock := NewMockGraphite(t, port)
	d := 25 * time.Millisecond
	attempts, maxAttempts := 0, 3
	var g *Graphite
	for {
		attempts++
		var err error
		g, err = NewGraphite(fmt.Sprintf("localhost:%d", port), d, d)
		if err == nil || attempts > maxAttempts {
			break
		}
		t.Logf("(%d/%d) %s", attempts, maxAttempts, err)
		time.Sleep(d)
	}
	if g == nil {
		t.Fatalf("Mock Graphite server never came up")
	}

	// register, wait, check
	i := expvar.NewInt("i")
	i.Set(34)
	g.Register("test.foo.i", i)

	time.Sleep(2 * d)
	count := mock.Count()
	if !(0 < count && count <= 2) {
		t.Errorf("expected 0 < publishes <= 2, got %d", count)
	}
	t.Logf("after %s, count=%d", 2*d, count)

	time.Sleep(2 * d)
	count = mock.Count()
	if !(1 < count && count <= 4) {
		t.Errorf("expected 1 < publishes <= 4, got %d", count)
	}
	t.Logf("after second %s, count=%d", 2*d, count)

	// teardown
	ok := make(chan bool)
	go func() {
		g.Shutdown()
		mock.Shutdown()
		ok <- true
	}()
	select {
	case <-ok:
		t.Logf("shutdown OK")
	case <-time.After(d):
		t.Errorf("timeout during shutdown")
	}

}
开发者ID:kachayev,项目名称:g2g,代码行数:56,代码来源:g2g_test.go


示例17: main

// Monitoring: export variables via an HTTP handler registered at /debug/vars (http://localhost:8080/debug/vars)
func main() {
	count := expvar.NewInt("count")
	go func() {
		for {
			count.Add(1)
			time.Sleep(time.Second)
		}
	}()
	log.Fatal(http.ListenAndServe("localhost:8080", nil))
}
开发者ID:islomar,项目名称:poc-golang,代码行数:11,代码来源:expvar.go


示例18: main

func main() {
	log.SetFlags(log.LstdFlags | log.Lmicroseconds)

	go collector_updateInfo(ch_update_info_in)
	go collector_stat(ch_ws_counter)
	go queue_reader(ch_update_info_in)

	http.HandleFunc("/ccus", wsHandler)

	g_dt_count_updates = expvar.NewInt("dt_count_updates")
	g_count_updates = expvar.NewInt("count_updates")
	g_count_ws_sessions = expvar.NewInt("count_ws_sessions")
	g_count_request = expvar.NewInt("count_request")

	log.Printf("Listen and serve: %s", WS_LISTEN_ADDR)
	if err := http.ListenAndServe(WS_LISTEN_ADDR, nil); err != nil {
		log.Fatal("ERR! listen and serve:", err)
	}
}
开发者ID:semantic-machines,项目名称:veda,代码行数:19,代码来源:ccus.go


示例19: init

func init() {
	flag.DurationVar(&outageThreshold, "outage_threshold", 5*time.Minute, "Trigger an outage when the duration between two pings from a router is longer than this threshold.")
	flag.StringVar(&outputFile, "output_file", "/tmp/bismark-availability.json", "Write avilability to this file in JSON format")
	flag.StringVar(&outputLevelDb, "output_leveldb", "/tmp/bismark-availability-leveldb", "Write avilability to this leveldb")
	flag.StringVar(&cacheDirectory, "cache_dir", "/tmp/bismark-availability-intervals", "Cache avilability intervals in this directory")
	flag.BoolVar(&excludeGatech, "exclude_gatech", false, "Whether to exclude probes from GT addresses.")
	var dateString string
	flag.StringVar(&dateString, "min_date", "2012-04-13", "Calculate intervals starting at this date")
	flag.Parse()

	dateParsed, err := time.Parse("2006-01-02", dateString)
	if err != nil {
		panic(fmt.Errorf("Invalid date %s: %s", dateString, err))
	}
	minDate = dateParsed

	rowsProcessed = expvar.NewInt("RowsProcessed")
	intervalsCreated = expvar.NewInt("IntervalsCreated")
}
开发者ID:sburnett,项目名称:bismark-tools,代码行数:19,代码来源:main.go


示例20: NewWebInterface

func NewWebInterface(addr string, cm *CallManager, rt RoutingTable) *WebInterface {
	wi := new(WebInterface)
	wi.addr = addr
	wi.cm = cm
	wi.rt = rt
	wi.sm = http.NewServeMux()
	wi.reqcounter = expvar.NewInt("")

	wi.sm.Handle("/", http.HandlerFunc(wi.getDummy()))

	return wi
}
开发者ID:spikebike,项目名称:malus,代码行数:12,代码来源:webinterface.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang expvar.NewMap函数代码示例发布时间:2022-05-24
下一篇:
Golang expvar.Get函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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