本文整理汇总了Golang中expvar.NewMap函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMap函数的具体用法?Golang NewMap怎么用?Golang NewMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: fanout
func fanout(
pubc chan Line,
subc, unsubc chan Subscription,
histc <-chan HistoryRequest,
histSize int,
) {
var (
hist = NewHistory(histSize)
reg = registry{}
publishs = expvar.NewMap("publishs")
subscribes = expvar.NewMap("subscribes")
unsubscribes = expvar.NewMap("unsubscribes")
)
expvar.Publish("history", hist)
expvar.Publish("subscriptions", reg)
for {
select {
case l := <-pubc:
for _, s := range reg[l.Topic()] {
s.In() <- l
}
hist.Store(l)
publishs.Add(l.Topic(), 1)
case s := <-subc:
_, ok := reg[s.Topic()]
if !ok {
reg[s.Topic()] = map[string]Subscription{}
}
reg[s.Topic()][s.ID()] = s
subscribes.Add(s.Topic(), 1)
logf("fanout: subscribed %s\n", s.ID())
case s := <-unsubc:
subs, ok := reg[s.Topic()]
if !ok {
continue
}
_, ok = subs[s.ID()]
if !ok {
continue
}
delete(subs, s.ID())
unsubscribes.Add(s.Topic(), 1)
logf("fanout: unsubscribed %s\n", s.ID())
case req := <-histc:
req.Respond(hist.Get(req.Topic(), req.Size()))
}
}
}
开发者ID:mehulsbhatt,项目名称:log,代码行数:53,代码来源:bazooka-log.go
示例2: NewExpHandler
// NewExpHandler creates a new ExpHandler, publishes a new expvar.Map to track
// it, sets a default Durations={"min": time.Minute}, sets Log=DefaultLogger,
// and adds name to the exposed "exphttp" map so that stats polling code
// can auto-discover.
func NewExpHandler(name string, h ExpHandlerFunc) *ExpHandler {
if expHandlers == nil {
expHandlers = expvar.NewMap("exphttp")
}
e := &ExpHandler{
Name: name,
Stats: expvar.NewMap(name),
Durations: map[string]time.Duration{"min": time.Minute},
HandlerFunc: h,
Log: DefaultLogger,
}
expHandlers.Add(name, 1)
return e
}
开发者ID:pbnjay,项目名称:exphttp,代码行数:19,代码来源:handlerfunc.go
示例3: NewRPCExt
func NewRPCExt(name string, maxIdleConnections int, clientBuilder ClientBuilder) *RPCExt {
r := &RPCExt{
name: name,
clients: make([]*rpc.Client, 0, maxIdleConnections),
maxIdleConnections: maxIdleConnections,
clientBuilder: clientBuilder,
closed: false,
statRequests: metrics.NewCounter(),
statEstablishedConnections: metrics.NewCounter(),
statLiveConnections: metrics.NewCounter(),
}
m := expvar.NewMap(name + "-rpc")
m.Set("requests", r.statRequests)
m.Set("connections.established", r.statEstablishedConnections)
m.Set("connections.inuse", r.statLiveConnections)
m.Set("connections.idle", expvar.Func(func() interface{} {
r.mu.RLock()
n := len(r.clients)
r.mu.RUnlock()
return n
}))
return r
}
开发者ID:guanglinlv,项目名称:go-rpcext,代码行数:26,代码来源:rpcext.go
示例4: init
func init() {
m := expvar.NewMap("io")
m.Set("w_B", &metrics.HistogramExport{
Histogram: writeBytes,
Percentiles: []float64{0.1, 0.2, 0.80, 0.90, 0.99},
PercentileNames: []string{"p10", "p20", "p80", "p90", "p99"}})
m.Set("r_B", &metrics.HistogramExport{
Histogram: readBytes,
Percentiles: []float64{0.1, 0.2, 0.80, 0.90, 0.99},
PercentileNames: []string{"p10", "p20", "p80", "p90", "p99"}})
expHistos = expvar.NewMap("cb")
cb.ConnPoolCallback = recordConnPoolStat
}
开发者ID:zhgwenming,项目名称:cbfs,代码行数:16,代码来源:debug.go
示例5: NewRuntimeWare
func NewRuntimeWare(prefixes []string, trackPageview bool, logInterval ...time.Duration) Middleware {
expvar.NewString("at_server_start").Set(time.Now().Format("2006-01-02 15:04:05"))
expvar.NewInt("cpu_count").Set(int64(runtime.NumCPU()))
ware := &RuntimeWare{
serverStarted: time.Now(),
trackPageview: trackPageview,
ignoredUrls: prefixes,
cQps: ratecounter.NewRateCounter(time.Minute),
c4xx: ratecounter.NewRateCounter(5 * time.Minute),
c5xx: ratecounter.NewRateCounter(5 * time.Minute),
lc: NewLatencyCounter(50),
hitsTotal: expvar.NewInt("hits_total"),
hitsQps: expvar.NewInt("hits_per_minute"),
hits4xx: expvar.NewInt("hits_4xx_per_5min"),
hits5xx: expvar.NewInt("hits_5xx_per_5min"),
hitsServed: expvar.NewString("latency_recent"),
hitsLatMax: expvar.NewString("latency_max"),
hitsLatMin: expvar.NewString("latency_min"),
hitsLat95: expvar.NewString("latency_p95"),
hitsLat50: expvar.NewString("latency_p50"),
numGoroutine: expvar.NewInt("goroutine_count"),
}
if trackPageview {
ware.pageviews = expvar.NewMap("hits_pageviews")
}
if len(logInterval) > 0 && logInterval[0] > 0 {
go ware.logSnapshot(logInterval[0])
}
return ware
}
开发者ID:haobaozhong,项目名称:sweb,代码行数:30,代码来源:runtime.go
示例6: NewStatistics
// NewStatistics returns an expvar-based map with the given key. Within that map
// is another map. Within there "name" is the Measurement name, "tags" are the tags,
// and values are placed at the key "values".
func NewStatistics(key, name string, tags map[string]string) *expvar.Map {
expvarMu.Lock()
defer expvarMu.Unlock()
// Add expvar for this service.
var v expvar.Var
if v = expvar.Get(key); v == nil {
v = expvar.NewMap(key)
}
m := v.(*expvar.Map)
// Set the name
nameVar := &expvar.String{}
nameVar.Set(name)
m.Set("name", nameVar)
// Set the tags
tagsVar := &expvar.Map{}
tagsVar.Init()
for k, v := range tags {
value := &expvar.String{}
value.Set(v)
tagsVar.Set(k, value)
}
m.Set("tags", tagsVar)
// Create and set the values entry used for actual stats.
statMap := &expvar.Map{}
statMap.Init()
m.Set("values", statMap)
return statMap
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:36,代码来源:influxvar.go
示例7: init
func init() {
registry := expvar.Get("registry")
if registry == nil {
registry = expvar.NewMap("registry")
}
cache := registry.(*expvar.Map).Get("cache")
if cache == nil {
cache = &expvar.Map{}
cache.(*expvar.Map).Init()
registry.(*expvar.Map).Set("cache", cache)
}
storage := cache.(*expvar.Map).Get("storage")
if storage == nil {
storage = &expvar.Map{}
storage.(*expvar.Map).Init()
cache.(*expvar.Map).Set("storage", storage)
}
storage.(*expvar.Map).Set("blobdescriptor", expvar.Func(func() interface{} {
// no need for synchronous access: the increments are atomic and
// during reading, we don't care if the data is up to date. The
// numbers will always *eventually* be reported correctly.
return blobStatterCacheMetrics
}))
}
开发者ID:emerald-ci,项目名称:test-runner,代码行数:27,代码来源:blobcachemetrics.go
示例8: init
func init() {
couchbase.ConnPoolCallback = recordConnPoolStat
expCb := expvar.NewMap("cb")
expHistos = &expvar.Map{}
expHistos.Init()
expCb.Set("pools", expHistos)
}
开发者ID:nod,项目名称:sync_gateway,代码行数:8,代码来源:debug.go
示例9: init
func init() {
rm := expvar.NewMap("retention")
rm.Set("SecondsSinceScanCompleted", expvar.Func(secondsSinceRetentionScanCompleted))
rm.Set("DeletesHist", expRetentionDeletesHist)
rm.Set("DeletesTotal", expRetentionDeletesTotal)
rm.Set("Period", expRetentionPeriod)
rm.Set("RetainedHist", expRetainedHist)
rm.Set("RetainedCurrent", expRetainedCurrent)
}
开发者ID:jhillyerd,项目名称:inbucket,代码行数:9,代码来源:retention.go
示例10: TestExport
func TestExport(t *testing.T) {
features = map[FeatureFlag]bool{
unused: false,
}
m := expvar.NewMap("testing")
Export(m)
v := m.Get("unused")
test.AssertEquals(t, v.String(), "false")
}
开发者ID:jfrazelle,项目名称:boulder,代码行数:9,代码来源:features_test.go
示例11: TestVHostCalculation
func TestVHostCalculation(t *testing.T) {
tests := []vhostTest{
vhostTest{
rawVHost: "www.howsmyssl.com",
httpsAddr: "0:10443",
expectedRouteHost: "www.howsmyssl.com",
expectedRedirectHost: "www.howsmyssl.com",
},
vhostTest{
rawVHost: "localhost:10443",
httpsAddr: "localhost:10443",
expectedRouteHost: "localhost",
expectedRedirectHost: "localhost:10443",
},
vhostTest{
rawVHost: "example.com:10443",
httpsAddr: "localhost:10443",
expectedRouteHost: "example.com",
expectedRedirectHost: "example.com:10443",
},
vhostTest{
rawVHost: "example.com:443",
httpsAddr: "0:443",
expectedRouteHost: "example.com",
expectedRedirectHost: "example.com",
},
}
staticVars := expvar.NewMap("testStatic")
staticHandler := makeStaticHandler("/static", staticVars)
for i, vt := range tests {
routeHost, redirectHost := calculateDomains(vt.rawVHost, vt.httpsAddr)
if routeHost != vt.expectedRouteHost {
t.Errorf("#%d vhost %#v, httpsAddr %#v: want routeHost %#v, got %s", i, vt.rawVHost, vt.httpsAddr, vt.expectedRouteHost, routeHost)
}
if redirectHost != vt.expectedRedirectHost {
t.Errorf("#%d vhost %#v, httpsAddr %#v: want redirectHost %#v, got %#v", i, vt.rawVHost, vt.httpsAddr, vt.expectedRedirectHost, redirectHost)
}
tm := tlsMux(vt.expectedRouteHost, vt.expectedRedirectHost, staticHandler)
r, err := http.NewRequest("GET", "https://howsmyssl.com/", nil)
if err != nil {
t.Fatalf("borked request")
}
w := httptest.NewRecorder()
tm.ServeHTTP(w, r)
expectedLocation := "https://" + vt.expectedRedirectHost + "/"
location := w.Header()["Location"][0]
if w.Code != http.StatusMovedPermanently {
t.Errorf("#%d vhost %#v, httpsAddr %#v: want Code %d, got %d", i, vt.rawVHost, vt.httpsAddr, http.StatusMovedPermanently, w.Code)
}
if location != expectedLocation {
t.Errorf("#%d vhost %#v, httpsAddr %#v: want Location %s, got %s", i, vt.rawVHost, vt.httpsAddr, expectedLocation, location)
}
}
}
开发者ID:Swyter,项目名称:howsmyssl,代码行数:56,代码来源:index_test.go
示例12: init
func init() {
m := expvar.NewMap("io")
m.Set("w_B", &metrics.HistogramExport{writeBytes,
[]float64{0.1, 0.2, 0.80, 0.90, 0.99},
[]string{"p10", "p20", "p80", "p90", "p99"}})
m.Set("r_B", &metrics.HistogramExport{readBytes,
[]float64{0.1, 0.2, 0.80, 0.90, 0.99},
[]string{"p10", "p20", "p80", "p90", "p99"}})
}
开发者ID:norulesbozo,项目名称:cbfs,代码行数:10,代码来源:debug.go
示例13: init
func init() {
DBVersion, _, _ = sqlite3.Version()
stats = expvar.NewMap("db")
stats.Add(numExecutions, 0)
stats.Add(numExecutionErrors, 0)
stats.Add(numQueries, 0)
stats.Add(numETx, 0)
stats.Add(numQTx, 0)
}
开发者ID:rqlite,项目名称:rqlite,代码行数:10,代码来源:db.go
示例14: init
func init() {
expvar.Publish("now", expvar.Func(func() interface{} {
return time.Now().Format("\"2006-01-02 15:04:05\"")
}))
stats = &Stats{}
expvar.Publish("stats", stats)
hits = expvar.NewMap("hits").Init()
}
开发者ID:EthanCai,项目名称:ethancai.github.io,代码行数:11,代码来源:expvarsample.go
示例15: PublishExpvarMetrics
/*
PublishExpvarMetrics - Publishes the NumWorkers and NumPendingAsyncJobs to expvars
*/
func (pool *WorkPool) PublishExpvarMetrics(poolName string) {
ret := expvar.NewMap(poolName)
asyncJobsFn := func() string {
return strconv.FormatInt(int64(pool.NumPendingAsyncJobs()), 10)
}
numWorkersFn := func() string {
return strconv.FormatInt(int64(pool.NumWorkers()), 10)
}
ret.Set("pendingAsyncJobs", liveVarAccessor(asyncJobsFn))
ret.Set("numWorkers", liveVarAccessor(numWorkersFn))
}
开发者ID:whosonfirst,项目名称:go-whosonfirst-clone,代码行数:14,代码来源:tunny.go
示例16: init
func init() {
m := expvar.NewMap("metricsd")
m.Set("requests", statRequestCount)
m.Set("requests_per_sec", statRequestRate)
m.Set("graphite_latency_us", &metrics.HistogramExport{Histogram: statGraphiteLatency,
Percentiles: []float64{0.5, 0.9, 0.99, 0.999}, PercentileNames: []string{"p50", "p90", "p99", "p999"}})
m.Set("librato_latency_us", &metrics.HistogramExport{Histogram: statLibratoLatency,
Percentiles: []float64{0.5, 0.9, 0.99, 0.999}, PercentileNames: []string{"p50", "p90", "p99", "p999"}})
m.Set("stathat_latency_us", &metrics.HistogramExport{Histogram: statStatHatLatency,
Percentiles: []float64{0.5, 0.9, 0.99, 0.999}, PercentileNames: []string{"p50", "p90", "p99", "p999"}})
}
开发者ID:couchbasedeps,项目名称:go-metrics-1,代码行数:11,代码来源:main.go
示例17: GetOrCreate
func (s *chatBotStats) GetOrCreate(identifier string) (*expvar.Map, bool) {
s.RLock()
chatbotStats, ok := s.m[identifier]
s.RUnlock()
if !ok {
chatbotStats = expvar.NewMap(identifier)
s.Lock()
s.m[identifier] = chatbotStats
s.Unlock()
}
return chatbotStats, ok
}
开发者ID:fazzzmZozo,项目名称:botbot-bot,代码行数:12,代码来源:irc.go
示例18: setExpvar
// setExpvar configures the expvar based collection for this service. It must be done within a
// lock so previous registrations for this key can be checked. Re-registering a key will result
// in a panic.
func (s *Service) setExpvar() {
expvarMu.Lock()
defer expvarMu.Unlock()
key := strings.Join([]string{"graphite", s.protocol, s.bindAddress}, ":")
// Add expvar for this service.
var m expvar.Var
if m = expvar.Get(key); m == nil {
m = expvar.NewMap(key)
}
s.statMap = m.(*expvar.Map)
}
开发者ID:adriantam,项目名称:influxdb,代码行数:16,代码来源:service.go
示例19: init
func init() {
couchbase.ConnPoolCallback = recordConnPoolStat
couchbase.ClientOpCallback = recordCBClientStat
expCb := expvar.NewMap("cb")
expPoolHistos = &expvar.Map{}
expPoolHistos.Init()
expCb.Set("pools", expPoolHistos)
expOpsHistos = &expvar.Map{}
expOpsHistos.Init()
expCb.Set("ops", expOpsHistos)
}
开发者ID:rajasaur,项目名称:sync_gateway,代码行数:13,代码来源:debug.go
示例20: init
func init() {
mcSent := &mcops{}
mcRecvd := &mcops{}
tapRecvd := &mcops{}
memcached.TransmitHook = mcSent.countReq
memcached.ReceiveHook = mcRecvd.countRes
memcached.TapRecvHook = tapRecvd.countReq
mcStats := expvar.NewMap("mc")
mcStats.Set("xmit", mcSent)
mcStats.Set("recv", mcRecvd)
mcStats.Set("tap", tapRecvd)
}
开发者ID:mbrukman,项目名称:gomemcached,代码行数:14,代码来源:mcdebug.go
注:本文中的expvar.NewMap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论