當前位置: 首頁>>代碼示例>>Golang>>正文


Golang points.OnePoint函數代碼示例

本文整理匯總了Golang中github.com/lomik/go-carbon/points.OnePoint函數的典型用法代碼示例。如果您正苦於以下問題:Golang OnePoint函數的具體用法?Golang OnePoint怎麽用?Golang OnePoint使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了OnePoint函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestCache

func TestCache(t *testing.T) {

	c := New()

	c.Add(points.OnePoint("hello.world", 42, 10))

	if c.Size() != 1 {
		t.FailNow()
	}

	c.Add(points.OnePoint("hello.world", 15, 12))

	if c.Size() != 2 {
		t.FailNow()
	}

	values := c.Pop()

	if values.Metric != "hello.world" {
		t.FailNow()
	}

	if len(values.Data) != 2 {
		t.FailNow()
	}

	if c.Size() != 0 {
		t.FailNow()
	}
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:30,代碼來源:cache_test.go

示例2: Stat

// Stat sends internal statistics to cache
func (p *Whisper) Stat(metric string, value float64) {
	p.in <- points.OnePoint(
		fmt.Sprintf("%spersister.%s", p.graphPrefix, metric),
		value,
		time.Now().Unix(),
	)
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:8,代碼來源:whisper.go

示例3: Stat

// Stat sends internal statistics to cache
func (rcv *UDP) Stat(metric string, value float64) {
	rcv.out <- points.OnePoint(
		fmt.Sprintf("%s%s", rcv.graphPrefix, metric),
		value,
		time.Now().Unix(),
	)
}
開發者ID:szibis,項目名稱:go-carbon,代碼行數:8,代碼來源:udp.go

示例4: TestStopConnectedTCP

func TestStopConnectedTCP(t *testing.T) {
	test := newTCPTestCase(t, false)
	defer test.Finish()

	ch := test.rcvChan
	test.Send("hello.world 42.15 1422698155\n")
	time.Sleep(10 * time.Millisecond)

	select {
	case msg := <-ch:
		test.Eq(msg, points.OnePoint("hello.world", 42.15, 1422698155))
	default:
		t.Fatalf("Message #0 not received")
	}

	test.receiver.Stop()
	test.receiver = nil
	time.Sleep(10 * time.Millisecond)

	test.Send("metric.name -72.11 1422698155\n")
	time.Sleep(10 * time.Millisecond)

	select {
	case <-ch:
		t.Fatalf("Message #0 received")
	default:
	}
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:28,代碼來源:stop_test.go

示例5: TestThrottleChan

func TestThrottleChan(t *testing.T) {
	perSecond := 100
	timestamp := time.Now().Unix()

	chIn := make(chan *points.Points)
	chOut := throttleChan(chIn, perSecond, nil)
	wait := time.After(time.Second)

	bw := 0

LOOP:
	for {
		select {
		case <-wait:
			break LOOP
		default:
		}
		chIn <- points.OnePoint("metric", 1, timestamp)
		<-chOut
		bw++
	}
	close(chIn)

	max := float64(perSecond) * 1.05
	min := float64(perSecond) * 0.95

	assert.True(t, float64(bw) >= min)
	assert.True(t, float64(bw) <= max)
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:29,代碼來源:throttle_test.go

示例6: TestCacheCheckpoint

func TestCacheCheckpoint(t *testing.T) {
	cache := New()
	cache.Start()
	cache.SetOutputChanSize(0)

	defer cache.Stop()

	startTime := time.Now().Unix() - 60*60

	sizes := []int{1, 15, 42, 56, 22, 90, 1}

	for index, value := range sizes {
		metricName := fmt.Sprintf("metric%d", index)

		for i := value; i > 0; i-- {
			cache.In() <- points.OnePoint(metricName, float64(i), startTime+int64(i))
		}

	}

	time.Sleep(100 * time.Millisecond)
	cache.doCheckpoint()

	d := <-cache.Out()
	if d.Metric != "metric0" {
		t.Fatal("wrong metric received")
	}

	systemMetrics := []string{
		"carbon.cache.inputLenAfterCheckpoint",
		"carbon.cache.inputLenBeforeCheckpoint",
		"carbon.cache.checkpointTime",
		"carbon.cache.overflow",
		"carbon.cache.queries",
		"carbon.cache.metrics",
		"carbon.cache.size",
	}

	for _, metricName := range systemMetrics {
		d = <-cache.Out()
		if d.Metric != metricName {
			t.Fatalf("%#v != %#v", d.Metric, metricName)
		}
	}

	result := sizes[1:]
	sort.Sort(sort.Reverse(sort.IntSlice(result)))

	for _, size := range result {
		d = <-cache.Out()
		if len(d.Data) != size {
			t.Fatalf("wrong metric received. Waiting metric with %d points, received with %d", size, len(d.Data))
		}
	}
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:55,代碼來源:cache_test.go

示例7: TestUDP2

func TestUDP2(t *testing.T) {
	test := newUDPTestCase(t)
	defer test.Finish()

	test.Send("hello.world 42.15 1422698155\nmetric.name -72.11 1422698155\n")

	select {
	case msg := <-test.rcvChan:
		test.Eq(msg, points.OnePoint("hello.world", 42.15, 1422698155))
	default:
		t.Fatalf("Message #0 not received")
	}

	select {
	case msg := <-test.rcvChan:
		test.Eq(msg, points.OnePoint("metric.name", -72.11, 1422698155))
	default:
		t.Fatalf("Message #1 not received")
	}
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:20,代碼來源:udp_test.go

示例8: randomPoints

func randomPoints(num int, out chan *points.Points) {
	var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
	var i int
	for i = 0; i < num; i++ {
		b := make([]rune, 32)
		for i := range b {
			b[i] = letters[rand.Intn(len(letters))]
		}
		metric := string(b)
		p := points.OnePoint(metric, rand.Float64(), rand.Int63())
		out <- p
	}
}
開發者ID:Gibheer,項目名稱:go-carbon,代碼行數:13,代碼來源:whisper_test.go

示例9: TestTCP2

func TestTCP2(t *testing.T) {
	test := newTCPTestCase(t, false)
	defer test.Finish()

	test.Send("hello.world 42.15 1422698155\nmetric.name -72.11 1422698155\n")

	time.Sleep(10 * time.Millisecond)

	select {
	case msg := <-test.rcvChan:
		test.Eq(msg, points.OnePoint("hello.world", 42.15, 1422698155))
	default:
		t.Fatalf("Message #0 not received")
	}

	select {
	case msg := <-test.rcvChan:
		test.Eq(msg, points.OnePoint("metric.name", -72.11, 1422698155))
	default:
		t.Fatalf("Message #1 not received")
	}
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:22,代碼來源:tcp_test.go

示例10: Stat

// Stat sends internal statistics to cache
func (rcv *TCP) Stat(metric string, value float64) {
	var protocolPrefix string

	if rcv.isPickle {
		protocolPrefix = "pickle"
	} else {
		protocolPrefix = "tcp"
	}

	rcv.out <- points.OnePoint(
		fmt.Sprintf("%s%s.%s", rcv.graphPrefix, protocolPrefix, metric),
		value,
		time.Now().Unix(),
	)
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:16,代碼來源:tcp.go

示例11: TestStat

func TestStat(t *testing.T) {
	fixture := Whisper{
		graphPrefix: "bing.bang.",
	}
	fixture.in = make(chan *points.Points)
	go func() {
		output := <-fixture.in
		expected := points.OnePoint(
			"bing.bang.persister.foo.bar",
			1.5,
			time.Now().Unix(),
		)
		assert.Equal(t, output, expected)
	}()
	fixture.Stat("foo.bar", 1.5)

}
開發者ID:Gibheer,項目名稱:go-carbon,代碼行數:17,代碼來源:whisper_test.go

示例12: TestStat

func TestStat(t *testing.T) {
	mock := clock.NewMock()
	app.Clock = mock
	fixture := Whisper{
		graphPrefix: "bing.bang.",
	}
	fixture.in = make(chan *points.Points)
	go func() {
		output := <-fixture.in
		expected := points.OnePoint(
			"bing.bang.persister.foo.bar",
			1.5,
			0,
		)
		assert.Equal(t, output, expected)
	}()
	fixture.Stat("foo.bar", 1.5)

}
開發者ID:EyckWigo,項目名稱:go-carbon,代碼行數:19,代碼來源:whisper_test.go

示例13: TestPickle

func TestPickle(t *testing.T) {
	// > python
	// >>> import pickle, struct
	// >>> listOfMetricTuples = [("hello.world", (1452200952, 42))]
	// >>> payload = pickle.dumps(listOfMetricTuples, protocol=2)
	// >>> header = struct.pack("!L", len(payload))
	// >>> message = header + payload
	// >>> print repr(message)
	// '\x00\x00\x00#\x80\x02]q\x00U\x0bhello.worldq\x01J\xf8\xd3\x8eVK*\x86q\x02\x86q\x03a.'

	test := newTCPTestCase(t, true)
	defer test.Finish()

	test.Send("\x00\x00\x00#\x80\x02]q\x00U\x0bhello.worldq\x01J\xf8\xd3\x8eVK*\x86q\x02\x86q\x03a.")

	time.Sleep(10 * time.Millisecond)

	select {
	case msg := <-test.rcvChan:
		test.Eq(msg, points.OnePoint("hello.world", 42, 1452200952))
	default:
		t.Fatalf("Message #0 not received")
	}
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:24,代碼來源:pickle_test.go

示例14: stat

// stat send internal statistics of cache
func (c *Cache) stat(metric string, value float64) {
	key := fmt.Sprintf("%scache.%s", c.graphPrefix, metric)
	c.Add(points.OnePoint(key, value, time.Now().Unix()))
	c.queue = append(c.queue, &queueItem{key, 1})
}
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:6,代碼來源:cache.go

示例15: TestCarbonlink

func TestCarbonlink(t *testing.T) {
	assert := assert.New(t)

	cache := New()
	cache.Start()
	cache.SetOutputChanSize(0)

	msg1 := points.OnePoint(
		"carbon.agents.carbon_agent_server.cache.size",
		42.17,
		1422797285,
	)

	msg2 := points.OnePoint(
		"carbon.agents.carbon_agent_server.param.size",
		-42.14,
		1422797267,
	)

	msg3 := points.OnePoint(
		"carbon.agents.carbon_agent_server.param.size",
		15,
		1422795966,
	)

	cache.In() <- msg1
	cache.In() <- msg2
	cache.In() <- msg3

	defer cache.Stop()

	time.Sleep(50 * time.Millisecond)

	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
	assert.NoError(err)

	carbonlink := NewCarbonlinkListener(cache.Query())
	defer carbonlink.Stop()

	assert.NoError(carbonlink.Listen(addr))

	conn, err := net.Dial("tcp", carbonlink.Addr().String())
	assert.NoError(err)

	conn.SetDeadline(time.Now().Add(time.Second))
	defer conn.Close()

	var replyLength int32
	var data []byte

	/* MESSAGE 1 */

	_, err = conn.Write([]byte(sampleCacheQuery))
	assert.NoError(err)

	err = binary.Read(conn, binary.BigEndian, &replyLength)
	assert.NoError(err)

	data = make([]byte, replyLength)

	err = binary.Read(conn, binary.BigEndian, data)
	assert.NoError(err)

	// {u'datapoints': [(1422797285, 42.17)]}
	assert.Equal("\x80\x02}(X\n\x00\x00\x00datapoints](J\xe5)\[email protected]\x15\xc2\x8f\\(\xf6\x86eu.", string(data))

	/* MESSAGE 2 */
	_, err = conn.Write([]byte(sampleCacheQuery2))
	assert.NoError(err)

	err = binary.Read(conn, binary.BigEndian, &replyLength)
	assert.NoError(err)

	data = make([]byte, replyLength)

	err = binary.Read(conn, binary.BigEndian, data)
	assert.NoError(err)

	// {u'datapoints': [(1422797267, -42.14), (1422795966, 15.0)]}
	assert.Equal("\x80\x02}(X\n\x00\x00\x00datapoints](J\xd3)\xceTG\xc0E\x11\xeb\x85\x1e\xb8R\x86J\xbe$\[email protected]\x00\x00\x00\x00\x00\x00\x86eu.",
		string(data))

	/* MESSAGE 3 */
	/* Remove carbon.agents.carbon_agent_server.param.size from cache and request again */

	for {
		c := <-cache.Out()
		if c.Metric == "carbon.agents.carbon_agent_server.param.size" {
			break
		}
	}

	_, err = conn.Write([]byte(sampleCacheQuery2))
	assert.NoError(err)

	err = binary.Read(conn, binary.BigEndian, &replyLength)
	assert.NoError(err)

	data = make([]byte, replyLength)

//.........這裏部分代碼省略.........
開發者ID:xyntrix,項目名稱:go-carbon,代碼行數:101,代碼來源:carbonlink_test.go


注:本文中的github.com/lomik/go-carbon/points.OnePoint函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。