當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。