本文整理汇总了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()
}
}
示例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(),
)
}
示例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(),
)
}
示例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:
}
}
示例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)
}
示例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))
}
}
}
示例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")
}
}
示例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
}
}
示例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")
}
}
示例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(),
)
}
示例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)
}
示例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)
}
示例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")
}
}
示例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})
}
示例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)
//.........这里部分代码省略.........