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


Golang Accumulator.NFields方法代碼示例

本文整理匯總了Golang中github.com/influxdata/telegraf/testutil.Accumulator.NFields方法的典型用法代碼示例。如果您正苦於以下問題:Golang Accumulator.NFields方法的具體用法?Golang Accumulator.NFields怎麽用?Golang Accumulator.NFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/influxdata/telegraf/testutil.Accumulator的用法示例。


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

示例1: TestExec

func TestExec(t *testing.T) {
	parser, _ := parsers.NewJSONParser("exec", []string{}, nil)
	e := &Exec{
		runner:   newRunnerMock([]byte(validJson), nil),
		Commands: []string{"testcommand arg1"},
		parser:   parser,
	}

	var acc testutil.Accumulator
	err := e.Gather(&acc)
	require.NoError(t, err)
	assert.Equal(t, acc.NFields(), 8, "non-numeric measurements should be ignored")

	fields := map[string]interface{}{
		"num_processes": float64(82),
		"cpu_used":      float64(8234),
		"cpu_free":      float64(32),
		"percent":       float64(0.81),
		"users_0":       float64(0),
		"users_1":       float64(1),
		"users_2":       float64(2),
		"users_3":       float64(3),
	}
	acc.AssertContainsFields(t, "exec", fields)
}
開發者ID:miketonks,項目名稱:telegraf,代碼行數:25,代碼來源:exec_test.go

示例2: TestRunParser

func TestRunParser(t *testing.T) {
	var testmsg = []byte(testMsg)

	listener, in := newTestTcpListener()
	acc := testutil.Accumulator{}
	listener.acc = &acc
	defer close(listener.done)

	listener.parser, _ = parsers.NewInfluxParser()
	listener.wg.Add(1)
	go listener.tcpParser()

	in <- testmsg
	time.Sleep(time.Millisecond * 25)
	listener.Gather(&acc)

	if a := acc.NFields(); a != 1 {
		t.Errorf("got %v, expected %v", a, 1)
	}

	acc.AssertContainsTaggedFields(t, "cpu_load_short",
		map[string]interface{}{"value": float64(12)},
		map[string]string{"host": "server01"},
	)
}
開發者ID:cwegener,項目名稱:telegraf,代碼行數:25,代碼來源:tcp_listener_test.go

示例3: TestRunParser

func TestRunParser(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	var testmsg = []byte("cpu_load_short,host=server01 value=12.0 1422568543702900257")

	listener, in := newTestUdpListener()
	acc := testutil.Accumulator{}
	listener.acc = &acc
	defer close(listener.done)

	listener.parser, _ = parsers.NewInfluxParser()
	listener.wg.Add(1)
	go listener.udpParser()

	in <- testmsg
	time.Sleep(time.Millisecond * 25)
	listener.Gather(&acc)

	if a := acc.NFields(); a != 1 {
		t.Errorf("got %v, expected %v", a, 1)
	}

	acc.AssertContainsTaggedFields(t, "cpu_load_short",
		map[string]interface{}{"value": float64(12)},
		map[string]string{"host": "server01"},
	)
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:26,代碼來源:udp_listener_test.go

示例4: TestHttpJsonBadJson

// Test response to malformed JSON
func TestHttpJsonBadJson(t *testing.T) {
	graylog := genMockGrayLog(invalidJSON, 200)

	var acc testutil.Accumulator
	err := graylog[0].Gather(&acc)

	assert.NotNil(t, err)
	assert.Equal(t, 0, acc.NFields())
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:10,代碼來源:graylog_test.go

示例5: TestHttpJsonBadJson

// Test response to malformed JSON
func TestHttpJsonBadJson(t *testing.T) {
	httpjson := genMockHttpJson(invalidJSON, 200)

	var acc testutil.Accumulator
	err := httpjson[0].Gather(&acc)

	assert.NotNil(t, err)
	assert.Equal(t, 0, acc.NFields())
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:10,代碼來源:httpjson_test.go

示例6: TestHttpJsonEmptyResponse

// Test response to empty string as response objectgT
func TestHttpJsonEmptyResponse(t *testing.T) {
	httpjson := genMockHttpJson(empty, 200)

	var acc testutil.Accumulator
	err := httpjson[0].Gather(&acc)

	assert.NotNil(t, err)
	assert.Equal(t, 0, acc.NFields())
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:10,代碼來源:httpjson_test.go

示例7: TestHttpJsonEmptyResponse

// Test response to empty string as response objectgT
func TestHttpJsonEmptyResponse(t *testing.T) {
	graylog := genMockGrayLog(empty, 200)

	var acc testutil.Accumulator
	err := graylog[0].Gather(&acc)

	assert.NotNil(t, err)
	assert.Equal(t, 0, acc.NFields())
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:10,代碼來源:graylog_test.go

示例8: TestHttpJsonBadMethod

// Test response to HTTP 405
func TestHttpJsonBadMethod(t *testing.T) {
	httpjson := genMockHttpJson(validJSON, 200)
	httpjson[0].Method = "NOT_A_REAL_METHOD"

	var acc testutil.Accumulator
	err := httpjson[0].Gather(&acc)

	assert.NotNil(t, err)
	assert.Equal(t, 0, acc.NFields())
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:11,代碼來源:httpjson_test.go

示例9: TestExecMalformed

func TestExecMalformed(t *testing.T) {
	e := &Exec{
		runner:  newRunnerMock([]byte(malformedJson), nil),
		Command: "badcommand arg1",
	}

	var acc testutil.Accumulator
	err := e.Gather(&acc)
	require.Error(t, err)
	assert.Equal(t, acc.NFields(), 0, "No new points should have been added")
}
開發者ID:zooplus,項目名稱:telegraf,代碼行數:11,代碼來源:exec_test.go

示例10: TestCommandError

func TestCommandError(t *testing.T) {
	e := &Exec{
		runner:  newRunnerMock(nil, fmt.Errorf("exit status code 1")),
		Command: "badcommand",
	}

	var acc testutil.Accumulator
	err := e.Gather(&acc)
	require.Error(t, err)
	assert.Equal(t, acc.NFields(), 0, "No new points should have been added")
}
開發者ID:zooplus,項目名稱:telegraf,代碼行數:11,代碼來源:exec_test.go

示例11: TestRunParserInvalidMsg

// Test that the parser ignores invalid messages
func TestRunParserInvalidMsg(t *testing.T) {
	k, in := newTestKafka()
	acc := testutil.Accumulator{}
	k.acc = &acc
	defer close(k.done)

	k.parser, _ = parsers.NewInfluxParser()
	go k.receiver()
	in <- saramaMsg(invalidMsg)
	time.Sleep(time.Millisecond * 5)

	assert.Equal(t, acc.NFields(), 0)
}
開發者ID:li-ang,項目名稱:telegraf,代碼行數:14,代碼來源:kafka_consumer_test.go

示例12: TestExecMalformed

func TestExecMalformed(t *testing.T) {
	parser, _ := parsers.NewJSONParser("exec", []string{}, nil)
	e := &Exec{
		runner:   newRunnerMock([]byte(malformedJson), nil),
		Commands: []string{"badcommand arg1"},
		parser:   parser,
	}

	var acc testutil.Accumulator
	err := e.Gather(&acc)
	require.Error(t, err)
	assert.Equal(t, acc.NFields(), 0, "No new points should have been added")
}
開發者ID:miketonks,項目名稱:telegraf,代碼行數:13,代碼來源:exec_test.go

示例13: TestCommandError

func TestCommandError(t *testing.T) {
	parser, _ := parsers.NewJSONParser("exec", []string{}, nil)
	e := &Exec{
		runner:   newRunnerMock(nil, fmt.Errorf("exit status code 1")),
		Commands: []string{"badcommand"},
		parser:   parser,
	}

	var acc testutil.Accumulator
	err := e.Gather(&acc)
	require.Error(t, err)
	assert.Equal(t, acc.NFields(), 0, "No new points should have been added")
}
開發者ID:miketonks,項目名稱:telegraf,代碼行數:13,代碼來源:exec_test.go

示例14: TestRunParser

// Test that the parser parses NATS messages into metrics
func TestRunParser(t *testing.T) {
	n, in := newTestNatsConsumer()
	acc := testutil.Accumulator{}
	n.acc = &acc
	defer close(n.done)

	n.parser, _ = parsers.NewInfluxParser()
	go n.receiver()
	in <- natsMsg(testMsg)
	time.Sleep(time.Millisecond * 25)

	if acc.NFields() != 1 {
		t.Errorf("got %v, expected %v", acc.NFields(), 1)
	}
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:16,代碼來源:nats_consumer_test.go

示例15: TestRunParserInvalidMsg

// Test that the parser ignores invalid messages
func TestRunParserInvalidMsg(t *testing.T) {
	n, in := newTestMQTTConsumer()
	acc := testutil.Accumulator{}
	n.acc = &acc
	defer close(n.done)

	n.parser, _ = parsers.NewInfluxParser()
	go n.receiver()
	in <- mqttMsg(invalidMsg)
	time.Sleep(time.Millisecond * 25)

	if a := acc.NFields(); a != 0 {
		t.Errorf("got %v, expected %v", a, 0)
	}
}
開發者ID:NathanielMichael,項目名稱:telegraf,代碼行數:16,代碼來源:mqtt_consumer_test.go


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