本文整理汇总了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")
}
示例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")
}
示例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
}
示例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()
}
示例5: NewMetrics
//NewMetrics creates
//Metrics object
func NewMetrics() *Metrics {
metrics = &Metrics{
true,
expvar.NewInt("comparisons"),
expvar.NewInt("errors"),
expvar.NewString("database"),
}
return metrics
}
示例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")
}
示例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))
}
示例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,
}
}
示例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)),
}
}
示例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))
}
示例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()
}
示例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"),
}
}
示例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
}
示例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))
}
示例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")
}