本文整理汇总了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

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng