本文整理汇总了Golang中expvar.Map类的典型用法代码示例。如果您正苦于以下问题:Golang Map类的具体用法?Golang Map怎么用?Golang Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: determineProperties
func determineProperties(sizes []int) *expvar.Map {
var sum int
props := new(expvar.Map).Init()
for _, n := range sizes {
sum += n
}
// Determine properties
sort.Ints(sizes)
if len(sizes) > 0 {
summary := map[string]int{
"min": sizes[0],
"max": sizes[len(sizes)-1],
"length": len(sizes),
"sum": sum,
"95e": sizes[int(float64(len(sizes))*0.95)],
}
mean := float64(sum) / float64(summary["length"])
// Pack them into an expvar Map
for k, v := range summary {
n := new(expvar.Int)
n.Set(int64(v))
props.Set(k, n)
}
avge := new(expvar.Float)
avge.Set(mean)
props.Set("avg", avge)
}
return props
}
示例2: Export
// Export populates a expvar.Map with the state of all
// of the features.
func Export(m *expvar.Map) {
fMu.RLock()
defer fMu.RUnlock()
for f, v := range features {
m.Set(f.String(), boolVar(v))
}
}
示例3: SanjoseProber
// HTTP Dynamic Streaming prober.
// Parse and probe F4M playlists and report time statistics and errors.
func SanjoseProber(ctl *bcast.Group, tasks chan *Task, debugvars *expvar.Map) {
for {
task := <-tasks
result := ExecHTTP(task)
task.ReplyTo <- result
debugvars.Add("hds-tasks-done", 1)
}
}
示例4: newListener
func newListener(nl net.Listener, ns *expvar.Map) *listener {
statNS := new(expvar.Map).Init()
ns.Set("handshake", statNS)
lis := &listener{
Listener: nl,
handshakeStats: newHandshakeStats(statNS),
}
return lis
}
示例5: snapshotMap
// snapshotMap recursively walks expvar Maps and records their integer expvars
// in a separate flat map.
func snapshotMap(varsMap map[string]int64, path string, mp *expvar.Map) {
mp.Do(func(kv expvar.KeyValue) {
switch kv.Value.(type) {
case *expvar.Int:
varsMap[path+"."+kv.Key], _ = strconv.ParseInt(kv.Value.String(), 10, 64)
case *expvar.Map:
snapshotMap(varsMap, path+"."+kv.Key, kv.Value.(*expvar.Map))
}
})
}
示例6: statsPageHandler
func statsPageHandler(w http.ResponseWriter, r *http.Request, bctx *BasePageContext) {
ctx := &struct {
*BasePageContext
Stats []*stat
}{
BasePageContext: bctx,
Stats: []*stat{},
}
var stats *expvar.Map
stats = expvar.Get("counters").(*expvar.Map)
servStat := expvar.Get("states").(*expvar.Map)
errors := expvar.Get("errors").(*expvar.Map)
for _, ep := range bctx.Globals.GetEndpoints() {
epname := ep.Name
all := stats.Get(epname)
success := stats.Get(epname + "|pass")
unauth := stats.Get(epname + "|401")
fail := stats.Get(epname + "|403")
status := servStat.Get(epname)
statusSSL := servStat.Get(epname + "|ssl")
err := errors.Get(epname)
errSSL := errors.Get(epname + "|ssl")
ctx.Stats = append(ctx.Stats, &stat{epname, fail, success, unauth, all, status, statusSSL,
err, errSSL})
}
RenderTemplateStd(w, ctx, "stats.tmpl")
}
示例7: resetVarMap
func resetVarMap(varMap *expvar.Map) {
// There is no easy way to delete/clear expvar.Map. As such there is a slight
// race here. *sigh*
keys := []string{}
varMap.Do(func(kv expvar.KeyValue) {
keys = append(keys, kv.Key)
})
for _, key := range keys {
varMap.Set(key, new(expvar.Int))
}
}
示例8: writeHistogramForDuration
func writeHistogramForDuration(expvarMap *expvar.Map, duration time.Duration, prefix string) {
if base.LogEnabled("PerfStats") {
var durationMs int
if duration < 1*time.Second {
durationMs = int(duration/(100*time.Millisecond)) * 100
} else {
durationMs = int(duration/(1000*time.Millisecond)) * 1000
}
expvarMap.Add(fmt.Sprintf("%s-%06dms", prefix, durationMs), 1)
}
}
示例9: TestSnapshotExpvarsMap
func TestSnapshotExpvarsMap(t *testing.T) {
test := expvar.NewMap("testMap")
test.Add("hello", 42)
map2 := new(expvar.Map).Init()
map2.Add("test", 5)
test.Set("map2", map2)
vals := map[string]int64{}
snapshotExpvars(vals)
assert.Equal(t, vals["testMap.hello"], int64(42))
assert.Equal(t, vals["testMap.map2.test"], int64(5))
}
示例10: init
func init() {
pacStatementSplit = regexp.MustCompile(`\s*;\s*`)
pacItemSplit = regexp.MustCompile(`\s+`)
pacCallFindProxyForURLResultCount = new(expvar.Map).Init()
pacCallFindProxyForURLParamHostCount = new(expvar.Map).Init()
callFindProxyForURLMap := new(expvar.Map).Init()
callFindProxyForURLMap.Set("resultCount", pacCallFindProxyForURLResultCount)
callFindProxyForURLMap.Set("urlHostCount", pacCallFindProxyForURLParamHostCount)
pacExpvarMap := expvar.NewMap("pac")
pacExpvarMap.Set("callFindProxyForURL", callFindProxyForURLMap)
}
示例11: getExpvarAsString
func getExpvarAsString(expvar *expvar.Map, name string) string {
value := expvar.Get(name)
if value != nil {
return value.String()
} else {
return ""
}
}
示例12: newOriginAllower
func newOriginAllower(blockedDomains []string, hostname string, gclog logClient, ns *expvar.Map) *originAllower {
mu := &sync.RWMutex{}
topKAllDomains := topk.New(100)
topKOfflistDomains := topk.New(100)
lifetime := new(expvar.Map).Init()
ns.Set("lifetime", lifetime)
lifetime.Set("top_all_domains", expvar.Func(func() interface{} {
mu.RLock()
defer mu.RUnlock()
return topKAllDomains.Keys()
}))
lifetime.Set("top_offlist_domains", expvar.Func(func() interface{} {
mu.RLock()
defer mu.RUnlock()
return topKOfflistDomains.Keys()
}))
oa := &originAllower{
m: make(map[string]struct{}),
ns: ns,
hostname: hostname,
gclog: gclog,
mu: mu,
topKAllDomains: topKAllDomains,
topKOfflistDomains: topKOfflistDomains,
}
for _, d := range blockedDomains {
oa.m[d] = struct{}{}
}
return oa
}
示例13: init
func init() {
// NOTE(stevvooe): Setup registry metrics structure to report to expvar.
// Ideally, we do more metrics through logging but we need some nice
// realtime metrics for queue state for now.
registry := expvar.Get("registry")
if registry == nil {
registry = expvar.NewMap("registry")
}
var notifications expvar.Map
notifications.Init()
notifications.Set("endpoints", expvar.Func(func() interface{} {
endpoints.mu.Lock()
defer endpoints.mu.Unlock()
var names []interface{}
for _, v := range endpoints.registered {
var epjson struct {
Name string `json:"name"`
URL string `json:"url"`
EndpointConfig
Metrics EndpointMetrics
}
epjson.Name = v.Name()
epjson.URL = v.URL()
epjson.EndpointConfig = v.EndpointConfig
v.ReadMetrics(&epjson.Metrics)
names = append(names, epjson)
}
return names
}))
registry.(*expvar.Map).Set("notifications", ¬ifications)
}
示例14: calculateTargetSummaryStats
// calculateTargetSummaryStats builds per-tier, per-target, metric-to-host summary stats
func calculateTargetSummaryStats(tiers *[]Tier) {
for _, tier := range *tiers {
totalSizes := []int{}
tierStats := new(expvar.Map).Init()
// Determine summary stats per target
for target, hosts := range tier.Mappings {
sizes := []int{}
for _, metrics := range hosts {
sizes = append(sizes, len(metrics))
totalSizes = append(totalSizes, len(metrics))
}
if len(sizes) == 0 {
continue
}
// Build summary
props := determineProperties(sizes)
tierStats.Set(target, props)
}
props := determineProperties(totalSizes)
tierStats.Set("total", props)
distCounts.Set(tier.Name, tierStats)
}
}
示例15: incrementMetric
// incrementMetric increments a value in the specified expvar.Map. The key
// should be a windows syscall.Errno or a string. Any other types will be
// reported under the "other" key.
func incrementMetric(v *expvar.Map, key interface{}) {
switch t := key.(type) {
default:
v.Add("other", 1)
case string:
v.Add(t, 1)
case syscall.Errno:
v.Add(strconv.Itoa(int(t)), 1)
}
}