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


Golang metric.New函数代码示例

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


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

示例1: TestReadFromCollector

func TestReadFromCollector(t *testing.T) {
	logrus.SetLevel(logrus.ErrorLevel)
	c := make(map[string]interface{})
	c["interval"] = 1
	collector := collector.New("Test")
	collector.SetInterval(1)
	collector.Configure(c)

	var wg sync.WaitGroup
	wg.Add(2)
	collectorStatChannel := make(chan metric.CollectorEmission)
	go func() {
		defer wg.Done()
		collector.Channel() <- metric.New("hello")
		time.Sleep(time.Duration(2) * time.Second)
		m2 := metric.New("world")
		m2.AddDimension("collectorCanonicalName", "Foobar")
		collector.Channel() <- m2
		time.Sleep(time.Duration(2) * time.Second)
		m2.AddDimension("collectorCanonicalName", "Foobar")
		collector.Channel() <- m2
		close(collector.Channel())
	}()
	collectorMetrics := map[string]uint64{}
	go func() {
		defer wg.Done()
		for collectorMetric := range collectorStatChannel {
			collectorMetrics[collectorMetric.Name] = collectorMetric.EmissionCount
		}
	}()
	readFromCollector(collector, []handler.Handler{}, collectorStatChannel)
	wg.Wait()
	assert.Equal(t, uint64(1), collectorMetrics["Test"])
	assert.Equal(t, uint64(2), collectorMetrics["Foobar"])
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:35,代码来源:collectors_test.go

示例2: TestHandlerBufferSize

func TestHandlerBufferSize(t *testing.T) {
	base := BaseHandler{}
	base.log = l.WithField("testing", "basehandler_flush")
	base.interval = 5
	base.maxBufferSize = 100
	base.channel = make(chan metric.Metric)
	base.collectorEndpoints = map[string]CollectorEnd{
		"collector1": CollectorEnd{make(chan metric.Metric), 3},
	}

	emitFunc := func(metrics []metric.Metric) bool {
		assert.Equal(t, 3, len(metrics))
		return true
	}

	go base.run(emitFunc)
	base.CollectorEndpoints()["collector1"].Channel <- metric.New("testMetric")
	base.CollectorEndpoints()["collector1"].Channel <- metric.New("testMetric1")
	base.CollectorEndpoints()["collector1"].Channel <- metric.New("testMetric2")
	time.Sleep(1 * time.Second)
	assert.Equal(t, uint64(3), atomic.LoadUint64(&base.metricsSent))
	assert.Equal(t, uint64(0), atomic.LoadUint64(&base.metricsDropped))

	// This is just to stop goroutines that have been started before
	base.channel <- metric.Metric{}
	base.CollectorEndpoints()["collector1"].Channel <- metric.Metric{}
}
开发者ID:Yelp,项目名称:fullerite,代码行数:27,代码来源:handler_test.go

示例3: TestKairosServerErrorParse

func TestKairosServerErrorParse(t *testing.T) {
	k := getTestKairosHandler(12, 13, 14)

	metrics := make([]metric.Metric, 0, 3)

	metrics = append(metrics, metric.New("Test1"))
	metrics = append(metrics, metric.New("Test2"))
	metrics = append(metrics, metric.New("test3"))

	metrics[0].AddDimension("somedim", "")
	metrics[1].AddDimension("somedim", "working")
	metrics[2].AddDimension("somedime", "")

	series := make([]KairosMetric, 0, len(metrics))
	for i := range metrics {
		series = append(series, k.convertToKairos(metrics[i]))
	}

	expectMetrics := make([]KairosMetric, 0, 2)
	expectMetrics = append(expectMetrics, k.convertToKairos(metrics[0]))
	expectMetrics = append(expectMetrics, k.convertToKairos(metrics[2]))

	expectByt, _ := json.Marshal(expectMetrics)

	errByt := []byte(`{\"errors\":[\"metric[0](name=Test1).tag[somedim].value may not be empty.\",` +
		`\"metric[2](name=Test3).tag[somedim].value may not be empty.\"]}`)

	assert.Equal(t, k.parseServerError(string(errByt), series), string(expectByt))
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:29,代码来源:kairos_test.go

示例4: TestSignalFxSanitation

func TestSignalFxSanitation(t *testing.T) {
	s := getTestSignalfxHandler(12, 12, 12)

	m1 := metric.New(" Test= .me$tric ")
	m1.AddDimension("simple string", "simple string")
	m1.AddDimension("dot.string", "dot.string")
	m1.AddDimension("3.3", "3.3")
	m1.AddDimension("slash/string", "slash/string")
	m1.AddDimension("colon:string", "colon:string")
	m1.AddDimension("equal=string", "equal=string")
	datapoint1 := s.convertToProto(m1)

	m2 := metric.New("Test-_.metric")
	m2.AddDimension("simple_string", "simple_string")
	m2.AddDimension("dot_string", "dot.string")
	m2.AddDimension("3_3", "3.3")
	m2.AddDimension("slash_string", "slash/string")
	m2.AddDimension("colon-string", "colon-string")
	m2.AddDimension("equal-string", "equal-string")
	datapoint2 := s.convertToProto(m2)

	assert.Equal(t, datapoint1.GetMetric(), datapoint2.GetMetric(), "the two metrics should be the same")
	for i := 0; i < len(datapoint1.GetDimensions())-1; i++ {
		for j := i + 1; j < len(datapoint1.GetDimensions()); j++ {
			assert.NotEqual(t, datapoint1.GetDimensions()[i].GetKey(), datapoint1.GetDimensions()[j].GetKey(), "the two dimensions should be different")
		}
	}
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:28,代码来源:signalfx_test.go

示例5: TestCollectorBlacklist

func TestCollectorBlacklist(t *testing.T) {
	logrus.SetLevel(logrus.ErrorLevel)

	c := make(map[string]interface{})
	c["interval"] = 1
	c["metrics_blacklist"] = []string{"m[0-9]+$"}
	col := collector.New("Test")
	col.SetInterval(1)
	col.Configure(c)

	var wg sync.WaitGroup
	wg.Add(2)
	collectorStatChannel := make(chan metric.CollectorEmission)

	go func() {
		defer wg.Done()
		col.Channel() <- metric.New("m1")
		time.Sleep(time.Duration(2) * time.Second)
		col.Channel() <- metric.New("m2")
		time.Sleep(time.Duration(2) * time.Second)
		col.Channel() <- metric.New("metric3")
		close(col.Channel())
	}()
	collectorMetrics := map[string]uint64{}
	go func() {
		defer wg.Done()
		for collectorMetric := range collectorStatChannel {
			collectorMetrics[collectorMetric.Name] = collectorMetric.EmissionCount
		}
	}()
	readFromCollector(col, []handler.Handler{}, collectorStatChannel)
	wg.Wait()

	assert.Equal(t, uint64(1), collectorMetrics["Test"])
}
开发者ID:Yelp,项目名称:fullerite,代码行数:35,代码来源:collectors_test.go

示例6: TestSanitizeMetricDimensionValue

func TestSanitizeMetricDimensionValue(t *testing.T) {
	k := getTestKairosHandler(12, 13, 14)

	m1 := metric.New("Test")
	m1.AddDimension("some=dim", "valu=")
	s1 := k.convertToKairos(m1)

	m2 := metric.New("Test")
	m2.AddDimension("some-dim", "valu-")
	s2 := k.convertToKairos(m2)

	assert.Equal(t, s1, s2, "metric dimension should be sanitazed")
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:13,代码来源:kairos_test.go

示例7: TestSanitizeMetricName

func TestSanitizeMetricName(t *testing.T) {
	k := getTestKairosHandler(12, 13, 14)

	m1 := metric.New("Test==:")
	m1.AddDimension("somedim", "value")
	s1 := k.convertToKairos(m1)

	m2 := metric.New("Test---")
	m2.AddDimension("somedim", "value")
	s2 := k.convertToKairos(m2)

	assert.Equal(t, s1, s2, "metric name should be sanitazed")
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:13,代码来源:kairos_test.go

示例8: TestAddDimensions

func TestAddDimensions(t *testing.T) {
	m1 := metric.New("TestMetric")
	m2 := metric.New("TestMetric")

	dimensions := map[string]string{
		"TestDimension":    "TestValue",
		"Dirty:=Dimension": "Dirty:=Value",
	}
	m1.AddDimension("TestDimension", "TestValue")
	m1.AddDimension("Dirty:=Dimension", "Dirty:=Value")
	m2.AddDimensions(dimensions)

	assert.Equal(t, m1, m2)
}
开发者ID:venkey-ariv,项目名称:fullerite,代码行数:14,代码来源:metric_test.go

示例9: procStatusPoint

func procStatusPoint(name string, value float64, dimensions map[string]string) (m metric.Metric) {
	m = metric.New(name)
	m.Value = value
	m.AddDimension("collector", "ProcStatus")
	m.AddDimensions(dimensions)
	return m
}
开发者ID:jp2007,项目名称:fullerite,代码行数:7,代码来源:procstatus_linux.go

示例10: TestEmissionAndRecord

func TestEmissionAndRecord(t *testing.T) {
	emitCalled := false

	callbackChannel := make(chan emissionTiming)
	emitFunc := func([]metric.Metric) bool {
		emitCalled = true
		return true
	}
	metrics := []metric.Metric{metric.New("example")}

	base := BaseHandler{}
	base.log = l.WithField("testing", "basehandler")
	go base.emitAndTime(metrics, emitFunc, callbackChannel)

	select {
	case timing := <-callbackChannel:
		assert.NotNil(t, timing)
		assert.Equal(t, 1, timing.metricsSent)
		assert.NotNil(t, timing.timestamp)
		assert.NotNil(t, timing.duration)
	case <-time.After(2 * time.Second):
		t.Fatal("Failed to read from the callback channel after 2 seconds")
	}

	assert.True(t, emitCalled)
	callbackChannel = nil
}
开发者ID:sagar8192,项目名称:fullerite,代码行数:27,代码来源:handler_test.go

示例11: TestHandlerRun

func TestHandlerRun(t *testing.T) {
	base := BaseHandler{}
	base.log = l.WithField("testing", "basehandler")
	base.interval = 1
	base.maxBufferSize = 1
	base.channel = make(chan metric.Metric)

	emitCalled := false
	emitFunc := func(metrics []metric.Metric) bool {
		assert.Equal(t, 1, len(metrics))
		emitCalled = true
		return true
	}

	// now we are waiting for some metrics
	go base.run(emitFunc)

	base.channel <- metric.New("testMetric")
	time.Sleep(1 * time.Second)
	assert.True(t, emitCalled)
	assert.Equal(t, 1, base.emissionTimes.Len())
	assert.Equal(t, uint64(1), base.metricsSent)
	assert.Equal(t, uint64(0), base.metricsDropped)
	assert.Equal(t, uint64(1), base.totalEmissions)
	assertEmpty(t, base.channel)
	base.channel = nil
}
开发者ID:sagar8192,项目名称:fullerite,代码行数:27,代码来源:handler_test.go

示例12: TestCollectorPrefix

func TestCollectorPrefix(t *testing.T) {
	logrus.SetLevel(logrus.ErrorLevel)
	c := make(map[string]interface{})
	c["interval"] = 1
	c["prefix"] = "px."
	collector := collector.New("Test")
	collector.SetInterval(1)
	collector.Configure(c)

	collectorChannel := map[string]chan metric.Metric{
		"Test": make(chan metric.Metric),
	}

	testHandler := handler.New("Log")
	testHandler.SetCollectorChannels(collectorChannel)

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		defer wg.Done()
		collector.Channel() <- metric.New("hello")
		close(collector.Channel())
	}()
	go func() {
		defer wg.Done()
		testMetric := <-collectorChannel["Test"]
		assert.Equal(t, "px.hello", testMetric.Name)
	}()
	readFromCollector(collector, []handler.Handler{testHandler})
	wg.Wait()
}
开发者ID:EvanKrall,项目名称:fullerite,代码行数:31,代码来源:collectors_test.go

示例13: TestWorkingGenericHTTP

func TestWorkingGenericHTTP(t *testing.T) {
	// setup the server
	expectedResponse := "This should come back to me"
	server := buildServer(expectedResponse)
	defer server.Close()

	col := buildBaseHTTPCollector(server.URL)
	col.errHandler = func(err error) {
		testLog.Error("Should not have caused an error")
		t.FailNow()
	}

	col.rspHandler = func(rsp *http.Response) []metric.Metric {
		txt, _ := ioutil.ReadAll(rsp.Body)
		rsp.Body.Close()

		assert.Equal(t, expectedResponse, string(txt))
		return []metric.Metric{metric.New("junk")}
	}

	go col.Collect()
	m := <-col.Channel()

	assert.NotNil(t, m, "should have produced a single metric")
	assert.True(t, ensureEmpty(col.Channel()), "There should have only been a single metric")
}
开发者ID:sagar8192,项目名称:fullerite,代码行数:26,代码来源:http_generic_test.go

示例14: reportCollector

func reportCollector(collector collector.Collector) {
	log.Warn(fmt.Sprintf("%s collector took too long to run, reporting incident!", collector.Name()))
	metric := metric.New("fullerite.collection_time_exceeded")
	metric.Value = 1
	metric.AddDimension("interval", fmt.Sprintf("%d", collector.Interval()))
	collector.Channel() <- metric
}
开发者ID:gsalisbury,项目名称:fullerite,代码行数:7,代码来源:collectors.go

示例15: TestSanitizeDimensionNameOverwriteCleanDirty

func TestSanitizeDimensionNameOverwriteCleanDirty(t *testing.T) {
	defaultDimensions := make(map[string]string)
	m := metric.New("TestMetric")
	m.AddDimension("Test-Dimension", "first value")
	m.AddDimension("Test=Dimension", "second value")
	assert := assert.New(t)

	value, ok := m.Dimensions["Test-Dimension"]
	assert.Equal("second value", value, "dimension value does not match")
	assert.True(ok)

	value, ok = m.Dimensions["Test=Dimension"]
	assert.False(ok)

	value, ok = m.GetDimensionValue("Test=Dimension")
	assert.Equal("second value", value, "dimension value does not match")
	assert.True(ok)
	value, ok = m.GetDimensionValue("Test-Dimension")
	assert.Equal("second value", value, "dimension value does not match")
	assert.True(ok)

	dimensions := m.GetDimensions(defaultDimensions)
	value, ok = dimensions["Test-Dimension"]
	assert.Equal("second value", value, "dimension value does not match")
	assert.True(ok)
	value, ok = dimensions["Test=Dimension"]
	assert.False(ok)

	assert.Equal(1, len(dimensions), "only 1 dimension should exist")
}
开发者ID:venkey-ariv,项目名称:fullerite,代码行数:30,代码来源:metric_test.go


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