• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang expvar.Get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中expvar.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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")
}
开发者ID:KarolBedkowski,项目名称:secproxy,代码行数:30,代码来源:stats.go


示例2: GetStatus

func GetStatus(w rest.ResponseWriter, r *rest.Request) {
	// b := GetBase(r)
	status := make(map[string]string)
	status["status"] = "ok"
	status["attemptsError"] = expvar.Get("attemptsError").String()
	status["attemptsSuccess"] = expvar.Get("attemptsSuccess").String()
	w.WriteJson(status)
}
开发者ID:yonglehou,项目名称:hooky,代码行数:8,代码来源:status.go


示例3: TestNew

func TestNew(t *testing.T) {
	// Publishes prefix in expvar, panics the second time
	assert.Nil(t, expvar.Get("name"))
	New("name")
	assert.NotNil(t, expvar.Get("name"))
	assert.IsType(t, expvar.Get("name"), &expvar.Map{})
	assert.Panics(t, func() {
		New("name")
	})
}
开发者ID:patrickToca,项目名称:xstats,代码行数:10,代码来源:expvar_test.go


示例4: TestPublished

func TestPublished(t *testing.T) {
	l, err := Listen("")
	if err != nil {
		t.Fatal(err)
	}
	opened := make(chan struct{})
	closed := make(chan struct{})
	go func() {
		for {
			conn, err := l.Accept()
			opened <- struct{}{}
			if err != nil {
				t.Fatal(err)
			}
			go func() {
				b := make([]byte, 100)
				for {
					_, err := conn.Read(b)
					if err != nil {
						conn.Close()
						closed <- struct{}{}
						return
					}
				}
			}()
		}
	}()

	addr := l.Addr().String()
	for i := 1; i <= 3; i++ {
		conn1, err := net.Dial("tcp", addr)
		if err != nil {
			t.Fatal(err)
		}
		<-opened
		if v := expvar.Get("ConnCount").String(); v != "1" {
			t.Errorf("ConnCount: %v, want 1", v)
		}
		conn1.Close()
		<-closed
		if v := expvar.Get("ConnCount").String(); v != "0" {
			t.Errorf("ConnCount: %v, want 1", v)
		}
		if v := expvar.Get("ConnAccepted").String(); v != fmt.Sprintf("%d", i) {
			t.Errorf("ConnAccepted: %v, want %d", v, i)
		}
	}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:48,代码来源:counting_listener_test.go


示例5: wsServer

func wsServer(ws *websocket.Conn) {
	var buf string
	defer func() {
		if err := ws.Close(); err != nil {
			log.Println("Websocket could not be closed", err.Error())
		} else {
			log.Println("Websocket closed")
		}
	}()
	//q := ws.Request().URL.Query()
	//name := q.Get("name")
	stopped := false
	ticker := time.Tick(time.Duration(1) * time.Second)
	for !stopped {
		select {
		case <-ticker:
			val := expvar.Get(metricsVar)
			if val == nil {
				buf = ""
			} else {
				buf = val.String()
			}
			_, err := ws.Write([]byte(buf))
			if err != nil {
				log.Printf("Websocket error: %s\n", err.Error())
				stopped = true
			}

		}
	}
}
开发者ID:millken,项目名称:kaman,代码行数:31,代码来源:server.go


示例6: TestDerive

func TestDerive(t *testing.T) {
	d := NewDerive(api.Identifier{
		Host:   "example.com",
		Plugin: "golang",
		Type:   "derive",
	})

	for i := 0; i < 10; i++ {
		d.Add(i)
	}

	want := api.ValueList{
		Identifier: api.Identifier{
			Host:   "example.com",
			Plugin: "golang",
			Type:   "derive",
		},
		Values: []api.Value{api.Derive(45)},
	}
	got := d.ValueList()

	if !reflect.DeepEqual(got, want) {
		t.Errorf("got %#v, want %#v", got, want)
	}

	s := expvar.Get("example.com/golang/derive").String()
	if s != "45" {
		t.Errorf("got %q, want %q", s, "45")
	}
}
开发者ID:zj8487,项目名称:go-collectd,代码行数:30,代码来源:export_test.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: GetStringVar

// Gets an exported var and returns its unquoted string contents
func GetStringVar(name string) string {
	s, err := strconv.Unquote(expvar.Get(name).String())
	if err != nil {
		panic(err)
	}
	return s
}
开发者ID:md14454,项目名称:kapacitor,代码行数:8,代码来源:stats.go


示例9: 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


示例10: GetFloatVar

// Gets an exported var and returns its float value
func GetFloatVar(name string) float64 {
	f, err := strconv.ParseFloat(expvar.Get(name).String(), 64)
	if err != nil {
		panic(err)
	}
	return f
}
开发者ID:md14454,项目名称:kapacitor,代码行数:8,代码来源:stats.go


示例11: GetIntVar

// Gets an exported var and returns its int value
func GetIntVar(name string) int64 {
	i, err := strconv.ParseInt(expvar.Get(name).String(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}
开发者ID:md14454,项目名称:kapacitor,代码行数:8,代码来源:stats.go


示例12: TestGauge

func TestGauge(t *testing.T) {
	g := NewGauge(api.Identifier{
		Host:   "example.com",
		Plugin: "golang",
		Type:   "gauge",
	})

	g.Set(42.0)

	want := api.ValueList{
		Identifier: api.Identifier{
			Host:   "example.com",
			Plugin: "golang",
			Type:   "gauge",
		},
		Values: []api.Value{api.Gauge(42)},
	}
	got := g.ValueList()

	if !reflect.DeepEqual(got, want) {
		t.Errorf("got %#v, want %#v", got, want)
	}

	s := expvar.Get("example.com/golang/gauge").String()
	if s != "42" {
		t.Errorf("got %q, want %q", s, "42")
	}
}
开发者ID:zj8487,项目名称:go-collectd,代码行数:28,代码来源:export_test.go


示例13: TestGauge

func TestGauge(t *testing.T) {
	s := New("gauge")
	v := expvar.Get("gauge").(*expvar.Map)
	s.Gauge("test", 1)
	assert.Equal(t, "1", v.Get("test").String())
	s.Gauge("test", -1)
	assert.Equal(t, "-1", v.Get("test").String())
}
开发者ID:patrickToca,项目名称:xstats,代码行数:8,代码来源:expvar_test.go


示例14: TestCount

func TestCount(t *testing.T) {
	s := New("count")
	v := expvar.Get("count").(*expvar.Map)
	s.Count("test", 1)
	assert.Equal(t, "1", v.Get("test").String())
	s.Count("test", -1)
	assert.Equal(t, "0", v.Get("test").String())
}
开发者ID:patrickToca,项目名称:xstats,代码行数:8,代码来源:expvar_test.go


示例15: TestCallbackGauge

func TestCallbackGauge(t *testing.T) {
	value := 42.43
	metricName := "foo"
	expvar.PublishCallbackGauge(metricName, func() float64 { return value })
	if want, have := fmt.Sprint(value), stdexpvar.Get(metricName).String(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}
开发者ID:jllopis,项目名称:kit,代码行数:8,代码来源:expvar_test.go


示例16: checkMemcacheExpvar

func checkMemcacheExpvar(t *testing.T, name string, expectedVal string) {
	val := expvar.Get(name)
	if val == nil {
		t.Fatalf("cannot find exported variable: %s", name)
	}
	if val.String() != expectedVal {
		t.Fatalf("name: %s, expect to get %s, but got: %s", name, expectedVal, val.String())
	}
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:9,代码来源:memcache_stats_test.go


示例17: TestWatcherErrors

func TestWatcherErrors(t *testing.T) {
	orig, err := strconv.ParseInt(expvar.Get("log_watcher_error_count").String(), 10, 64)
	if err != nil {
		t.Fatalf("couldn't convert expvar %q", expvar.Get("log_watcher_error_count").String())
	}
	w, err := NewLogWatcher()
	if err != nil {
		t.Fatalf("couldn't create a watcher")
	}
	w.Errors <- errors.New("just a test, not really an error")
	if err := w.Close(); err != nil {
		t.Fatalf("watcher close failed: %q", err)
	}
	diff := pretty.Compare(strconv.FormatInt(orig+1, 10), expvar.Get("log_watcher_error_count").String())
	if len(diff) > 0 {
		t.Errorf("log watcher error count doens't match:\n%s", diff)
	}
}
开发者ID:yanghongkjxy,项目名称:mtail,代码行数:18,代码来源:log_watcher_test.go


示例18: TestCounter

func TestCounter(t *testing.T) {
	var (
		name  = "m"
		value = 123
	)
	expvar.NewCounter(name).With(metrics.Field{Key: "ignored", Value: "field"}).Add(uint64(value))
	if want, have := fmt.Sprint(value), stdexpvar.Get(name).String(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}
开发者ID:cnicolov,项目名称:kit,代码行数:10,代码来源:expvar_test.go


示例19: GetStatement

func GetStatement(key string) (stmt mysql.Stmt, err error) {
	stmt, ok := Statements[key]
	if !ok {
		qry := expvar.Get(key)
		if qry == nil {
			err = errors.New("Invalid query reference")
		}
	}
	return

}
开发者ID:ninnemana,项目名称:goengine,代码行数:11,代码来源:prepared_stmts.go


示例20: TestWatcherErrors

func TestWatcherErrors(t *testing.T) {
	w, err := NewLogWatcher()
	if err != nil {
		t.Fatalf("couldn't create a watcher")
	}
	w.Errors <- errors.New("test error")
	w.Close()
	diff := pretty.Compare(expvar.Get("log_watcher_error_count").String(), "1")
	if len(diff) > 0 {
		t.Errorf("log watcher error count doens't match:\n%s", diff)
	}
}
开发者ID:nulleins0130,项目名称:mtail,代码行数:12,代码来源:log_watcher_test.go



注:本文中的expvar.Get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang expvar.NewInt函数代码示例发布时间:2022-05-24
下一篇:
Golang expvar.Func函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap