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


Golang Accumulator.AssertContainsFields方法代碼示例

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


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

示例1: TestMesosSlave

func TestMesosSlave(t *testing.T) {
	var acc testutil.Accumulator

	m := Mesos{
		Masters:    []string{},
		Slaves:     []string{slaveTestServer.Listener.Addr().String()},
		SlaveTasks: true,
		Timeout:    10,
	}

	err := m.Gather(&acc)

	if err != nil {
		t.Errorf(err.Error())
	}

	acc.AssertContainsFields(t, "mesos", slaveMetrics)

	jf := jsonparser.JSONFlattener{}
	err = jf.FlattenJSON("", slaveTaskMetrics)

	if err != nil {
		t.Errorf(err.Error())
	}

	acc.AssertContainsFields(t, "mesos-tasks", jf.Fields)
}
開發者ID:mkuzmin,項目名稱:telegraf,代碼行數:27,代碼來源:mesos_test.go

示例2: TestPartialVmStatProcFile

func TestPartialVmStatProcFile(t *testing.T) {
	tmpfile := makeFakeStatFile([]byte(vmStatFile_Partial))
	defer os.Remove(tmpfile)

	k := KernelVmstat{
		statFile: tmpfile,
	}

	acc := testutil.Accumulator{}
	err := k.Gather(&acc)
	assert.NoError(t, err)

	fields := map[string]interface{}{
		"unevictable_pgs_culled":     int64(1531),
		"unevictable_pgs_scanned":    int64(0),
		"unevictable_pgs_rescued":    int64(5426),
		"unevictable_pgs_mlocked":    int64(6988),
		"unevictable_pgs_munlocked":  int64(6988),
		"unevictable_pgs_cleared":    int64(0),
		"unevictable_pgs_stranded":   int64(0),
		"unevictable_pgs_mlockfreed": int64(0),
		"thp_fault_alloc":            int64(346219),
		"thp_fault_fallback":         int64(895453),
		"thp_collapse_alloc":         int64(24857),
		"thp_collapse_alloc_failed":  int64(102214),
		"thp_split":                  int64(9817),
	}
	acc.AssertContainsFields(t, "kernel_vmstat", fields)
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:29,代碼來源:kernel_vmstat_test.go

示例3: TestMesosSlave

func TestMesosSlave(t *testing.T) {
	var acc testutil.Accumulator

	m := Mesos{
		Masters: []string{},
		Slaves:  []string{slaveTestServer.Listener.Addr().String()},
		// SlaveTasks: true,
		Timeout: 10,
	}

	err := m.Gather(&acc)

	if err != nil {
		t.Errorf(err.Error())
	}

	acc.AssertContainsFields(t, "mesos", slaveMetrics)

	// expectedFields := make(map[string]interface{}, len(slaveTaskMetrics["statistics"].(map[string]interface{}))+1)
	// for k, v := range slaveTaskMetrics["statistics"].(map[string]interface{}) {
	// 	expectedFields[k] = v
	// }
	// expectedFields["executor_id"] = slaveTaskMetrics["executor_id"]

	// acc.AssertContainsTaggedFields(
	// 	t,
	// 	"mesos_tasks",
	// 	expectedFields,
	// 	map[string]string{"server": "127.0.0.1", "framework_id": slaveTaskMetrics["framework_id"].(string)})
}
開發者ID:Wikia,項目名稱:telegraf,代碼行數:30,代碼來源:mesos_test.go

示例4: 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

示例5: TestExecCommandWithoutGlobAndPath

func TestExecCommandWithoutGlobAndPath(t *testing.T) {
	parser, _ := parsers.NewValueParser("metric", "string", nil)
	e := NewExec()
	e.Commands = []string{"echo metric_value"}
	e.SetParser(parser)

	var acc testutil.Accumulator
	err := e.Gather(&acc)
	require.NoError(t, err)

	fields := map[string]interface{}{
		"value": "metric_value",
	}
	acc.AssertContainsFields(t, "metric", fields)
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:15,代碼來源:exec_test.go

示例6: TestRunParserAndGather

// Test that the parser parses kafka messages into points
func TestRunParserAndGather(t *testing.T) {
	k, in := NewTestKafka()
	defer close(k.done)

	go k.parser()
	in <- saramaMsg(testMsg)
	time.Sleep(time.Millisecond)

	acc := testutil.Accumulator{}
	k.Gather(&acc)

	assert.Equal(t, len(acc.Points), 1)
	acc.AssertContainsFields(t, "cpu_load_short",
		map[string]interface{}{"value": float64(23422)})
}
開發者ID:bahadrix,項目名稱:telegraf,代碼行數:16,代碼來源:kafka_consumer_test.go

示例7: TestMesosMaster

func TestMesosMaster(t *testing.T) {
	var acc testutil.Accumulator

	m := Mesos{
		Masters: []string{masterTestServer.Listener.Addr().String()},
		Timeout: 10,
	}

	err := m.Gather(&acc)

	if err != nil {
		t.Errorf(err.Error())
	}

	acc.AssertContainsFields(t, "mesos", masterMetrics)
}
開發者ID:mkuzmin,項目名稱:telegraf,代碼行數:16,代碼來源:mesos_test.go

示例8: TestRunParserAndGather

// Test that the parser parses line format messages into metrics
func TestRunParserAndGather(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)

	n.Gather(&acc)

	acc.AssertContainsFields(t, "cpu_load_short",
		map[string]interface{}{"value": float64(23422)})
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:17,代碼來源:nats_consumer_test.go

示例9: TestRunParserAndGatherGraphite

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

	n.parser, _ = parsers.NewGraphiteParser("_", []string{}, nil)
	go n.receiver()
	in <- mqttMsg(testMsgGraphite)
	time.Sleep(time.Millisecond * 25)

	n.Gather(&acc)

	acc.AssertContainsFields(t, "cpu_load_short_graphite",
		map[string]interface{}{"value": float64(23422)})
}
開發者ID:NathanielMichael,項目名稱:telegraf,代碼行數:17,代碼來源:mqtt_consumer_test.go

示例10: TestRunParserAndGatherGraphite

// Test that the parser parses kafka messages into points
func TestRunParserAndGatherGraphite(t *testing.T) {
	k, in := NewTestKafka()
	defer close(k.done)

	k.parser, _ = parsers.NewGraphiteParser("_", []string{}, nil)
	go k.receiver()
	in <- saramaMsg(testMsgGraphite)
	time.Sleep(time.Millisecond)

	acc := testutil.Accumulator{}
	k.Gather(&acc)

	assert.Equal(t, len(acc.Metrics), 1)
	acc.AssertContainsFields(t, "cpu_load_short_graphite",
		map[string]interface{}{"value": float64(23422)})
}
開發者ID:bwolf,項目名稱:telegraf,代碼行數:17,代碼來源:kafka_consumer_test.go

示例11: TestRunParserAndGather

// Test that the parser parses kafka messages into points
func TestRunParserAndGather(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(testMsg)
	time.Sleep(time.Millisecond * 5)

	k.Gather(&acc)

	assert.Equal(t, acc.NFields(), 1)
	acc.AssertContainsFields(t, "cpu_load_short",
		map[string]interface{}{"value": float64(23422)})
}
開發者ID:li-ang,項目名稱:telegraf,代碼行數:18,代碼來源:kafka_consumer_test.go

示例12: TestRunParserAndGather

// Test that the parser parses line format messages into metrics
func TestRunParserAndGather(t *testing.T) {
	n, in := newTestNatsConsumer()
	defer close(n.done)

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

	acc := testutil.Accumulator{}
	n.Gather(&acc)

	if a := len(acc.Metrics); a != 1 {
		t.Errorf("got %v, expected %v", a, 1)
	}
	acc.AssertContainsFields(t, "cpu_load_short",
		map[string]interface{}{"value": float64(23422)})
}
開發者ID:noise,項目名稱:telegraf,代碼行數:19,代碼來源:nats_consumer_test.go

示例13: TestHTTPApache

func TestHTTPApache(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		fmt.Fprintln(w, apacheStatus)
	}))
	defer ts.Close()

	a := Apache{
		// Fetch it 2 times to catch possible data races.
		Urls: []string{ts.URL, ts.URL},
	}

	var acc testutil.Accumulator
	err := a.Gather(&acc)
	require.NoError(t, err)

	fields := map[string]interface{}{
		"TotalAccesses":        float64(1.29811861e+08),
		"TotalkBytes":          float64(5.213701865e+09),
		"CPULoad":              float64(6.51929),
		"Uptime":               float64(941553),
		"ReqPerSec":            float64(137.87),
		"BytesPerSec":          float64(5.67024e+06),
		"BytesPerReq":          float64(41127.4),
		"BusyWorkers":          float64(270),
		"IdleWorkers":          float64(630),
		"ConnsTotal":           float64(1451),
		"ConnsAsyncWriting":    float64(32),
		"ConnsAsyncKeepAlive":  float64(945),
		"ConnsAsyncClosing":    float64(205),
		"scboard_waiting":      float64(630),
		"scboard_starting":     float64(0),
		"scboard_reading":      float64(157),
		"scboard_sending":      float64(113),
		"scboard_keepalive":    float64(0),
		"scboard_dnslookup":    float64(0),
		"scboard_closing":      float64(0),
		"scboard_logging":      float64(0),
		"scboard_finishing":    float64(0),
		"scboard_idle_cleanup": float64(0),
		"scboard_open":         float64(2850),
	}
	acc.AssertContainsFields(t, "apache", fields)
}
開發者ID:jeichorn,項目名稱:telegraf,代碼行數:44,代碼來源:apache_test.go

示例14: TestRunParserAndGatherJSON

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

	n.parser, _ = parsers.NewJSONParser("nats_json_test", []string{}, nil)
	go n.receiver()
	in <- mqttMsg(testMsgJSON)
	time.Sleep(time.Millisecond * 25)

	n.Gather(&acc)

	acc.AssertContainsFields(t, "nats_json_test",
		map[string]interface{}{
			"a":   float64(5),
			"b_c": float64(6),
		})
}
開發者ID:NathanielMichael,項目名稱:telegraf,代碼行數:20,代碼來源:mqtt_consumer_test.go

示例15: TestRunParserAndGatherJSON

// Test that the parser parses kafka messages into points
func TestRunParserAndGatherJSON(t *testing.T) {
	k, in := NewTestKafka()
	defer close(k.done)

	k.parser, _ = parsers.NewJSONParser("kafka_json_test", []string{}, nil)
	go k.receiver()
	in <- saramaMsg(testMsgJSON)
	time.Sleep(time.Millisecond)

	acc := testutil.Accumulator{}
	k.Gather(&acc)

	assert.Equal(t, len(acc.Metrics), 1)
	acc.AssertContainsFields(t, "kafka_json_test",
		map[string]interface{}{
			"a":   float64(5),
			"b_c": float64(6),
		})
}
開發者ID:bwolf,項目名稱:telegraf,代碼行數:20,代碼來源:kafka_consumer_test.go


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