当前位置: 首页>>代码示例>>Golang>>正文


Golang expvar.Get函数代码示例

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


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


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