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


Golang expvar.NewInt函數代碼示例

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


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


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