Example #1
0
func TestData(t *testing.T) {
	f := mbtest.NewEventsFetcher(t, getConfig())
	err := mbtest.WriteEvents(f, t)
	if err != nil {
		t.Fatal("write", err)
	}
}
func TestFetch(t *testing.T) {
	f := mbtest.NewEventsFetcher(t, getConfig())
	events, err := f.Fetch()
	if !assert.NoError(t, err) {
		t.FailNow()
	}

	assert.True(t, len(events) > 0)
	event := events[0]

	t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)

	// Check event fields
	db_oid := event["oid"].(int64)
	assert.True(t, db_oid > 0)
	assert.Contains(t, event, "name")
	_, ok := event["name"].(string)
	assert.True(t, ok)

	rows := event["rows"].(common.MapStr)
	assert.Contains(t, rows, "returned")
	assert.Contains(t, rows, "fetched")
	assert.Contains(t, rows, "inserted")
	assert.Contains(t, rows, "updated")
	assert.Contains(t, rows, "deleted")

}
func TestFetch(t *testing.T) {
	f := mbtest.NewEventsFetcher(t, getConfig())
	events, err := f.Fetch()
	if !assert.NoError(t, err) {
		t.FailNow()
	}

	assert.True(t, len(events) > 0)
	event := events[0]

	t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)

	// Check event fields
	assert.Contains(t, event, "database")
	db_oid := event["database"].(common.MapStr)["oid"].(int64)
	assert.True(t, db_oid > 0)

	assert.Contains(t, event, "pid")
	assert.True(t, event["pid"].(int64) > 0)

	assert.Contains(t, event, "user")
	assert.Contains(t, event["user"].(common.MapStr), "name")
	assert.Contains(t, event["user"].(common.MapStr), "id")

}
Example #4
0
func TestFetch(t *testing.T) {

	// Insert at least one event to make sure db exists
	c, err := rd.Dial("tcp", host)
	if err != nil {
		t.Fatal("connect", err)
	}
	defer c.Close()
	_, err = c.Do("SET", "foo", "bar")

	// Fetch data
	f := mbtest.NewEventsFetcher(t, getConfig())
	events, err := f.Fetch()
	if err != nil {
		t.Fatal("fetch", err)
	}

	t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), events)

	// Make sure at least 1 db keyspace exists
	assert.True(t, len(events) > 0)

	keyspace := events[0]

	assert.True(t, keyspace["avg_ttl"].(int64) >= 0)
	assert.True(t, keyspace["expires"].(int64) >= 0)
	assert.True(t, keyspace["keys"].(int64) >= 0)
	assert.True(t, strings.Contains(keyspace["id"].(string), "db"))
}
func TestData(t *testing.T) {
	generateKafkaData(t, "metricbeat-generate-data")

	f := mbtest.NewEventsFetcher(t, getConfig())
	err := mbtest.WriteEvents(f, t)
	if err != nil {
		t.Fatal("write", err)
	}
}
Example #6
0
func TestData(t *testing.T) {
	f := mbtest.NewEventsFetcher(t, getConfig())

	// Fetch once in advance to have percentage values
	f.Fetch()
	time.Sleep(1 * time.Second)

	err := mbtest.WriteEvents(f, t)
	if err != nil {
		t.Fatal("write", err)
	}
}
Example #7
0
func TestData(t *testing.T) {
	f := mbtest.NewEventsFetcher(t, getConfig())

	// Do a first fetch to have precentages
	f.Fetch()
	time.Sleep(1 * time.Second)

	err := mbtest.WriteEvents(f, t)
	if err != nil {
		t.Fatal("write", err)
	}
}
Example #8
0
func TestFetchEventContents(t *testing.T) {
	absPath, err := filepath.Abs("./testdata/")
	// response is a raw response from a couchbase
	response, err := ioutil.ReadFile(absPath + "/sample_response.json")
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
		w.Header().Set("Content-Type", "appication/json;")
		w.Write([]byte(response))
	}))
	defer server.Close()

	config := map[string]interface{}{
		"module":     "couchbase",
		"metricsets": []string{"bucket"},
		"hosts":      []string{server.URL},
	}

	f := mbtest.NewEventsFetcher(t, config)
	events, err := f.Fetch()
	event := events[0]
	if !assert.NoError(t, err) {
		t.FailNow()
	}

	t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event.StringToPrint())

	assert.EqualValues(t, "membase", event["type"])
	assert.EqualValues(t, "beer-sample", event["name"])

	data := event["data"].(common.MapStr)
	data_used := data["used"].(common.MapStr)
	assert.EqualValues(t, 12597731, data_used["bytes"])

	disk := event["disk"].(common.MapStr)
	assert.EqualValues(t, 0, disk["fetches"])

	disk_used := disk["used"].(common.MapStr)
	assert.EqualValues(t, 16369008, disk_used["bytes"])

	memory := event["memory"].(common.MapStr)
	memory_used := memory["used"].(common.MapStr)
	assert.EqualValues(t, 53962160, memory_used["bytes"])

	quota := event["quota"].(common.MapStr)
	quota_ram := quota["ram"].(common.MapStr)
	assert.EqualValues(t, 104857600, quota_ram["bytes"])

	quota_use := quota["use"].(common.MapStr)
	assert.EqualValues(t, 51.46232604980469, quota_use["pct"])

	assert.EqualValues(t, 7303, event["item_count"])
	assert.EqualValues(t, 0, event["ops_per_sec"])
}
func TestTopic(t *testing.T) {
	id := strconv.Itoa(rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int())
	testTopic := fmt.Sprintf("test-metricbeat-%s", id)

	// Create initial topic
	generateKafkaData(t, testTopic)

	f := mbtest.NewEventsFetcher(t, getConfig())
	dataBefore, err := f.Fetch()
	if err != nil {
		t.Fatal("write", err)
	}

	var n int64 = 10
	var i int64 = 0
	// Create n messages
	for ; i < n; i++ {
		generateKafkaData(t, testTopic)
	}

	dataAfter, err := f.Fetch()
	if err != nil {
		t.Fatal("write", err)
	}

	// Checks that no new topics / partitions were added
	assert.True(t, len(dataBefore) == len(dataAfter))

	var offsetBefore int64 = 0
	var offsetAfter int64 = 0

	// Its possible that other topics exists -> select the right data
	for _, data := range dataBefore {
		if data["topic"].(common.MapStr)["name"] == testTopic {
			offsetBefore = data["offset"].(common.MapStr)["newest"].(int64)
		}
	}

	for _, data := range dataAfter {
		if data["topic"].(common.MapStr)["name"] == testTopic {
			offsetAfter = data["offset"].(common.MapStr)["newest"].(int64)
		}
	}

	// Compares offset before and after
	if offsetBefore+n != offsetAfter {
		t.Errorf("Offset before: %v", offsetBefore)
		t.Errorf("Offset after: %v", offsetAfter)
	}
	assert.True(t, offsetBefore+n == offsetAfter)
}
func TestFetch(t *testing.T) {

	addEntry(t)

	// Fetch data
	f := mbtest.NewEventsFetcher(t, getConfig())
	events, err := f.Fetch()
	if err != nil {
		t.Fatal("fetch", err)
	}

	t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), events)

	// Make sure at least 1 db keyspace exists
	assert.True(t, len(events) > 0)

	keyspace := events[0]

	assert.True(t, keyspace["avg_ttl"].(int64) >= 0)
	assert.True(t, keyspace["expires"].(int64) >= 0)
	assert.True(t, keyspace["keys"].(int64) >= 0)
	assert.True(t, strings.Contains(keyspace["id"].(string), "db"))
}
Example #11
0
func TestFetchEventContents(t *testing.T) {
	absPath, err := filepath.Abs("./testdata/")
	// response is a raw response from a couchbase
	response, err := ioutil.ReadFile(absPath + "/sample_response.json")
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
		w.Header().Set("Content-Type", "appication/json;")
		w.Write([]byte(response))
	}))
	defer server.Close()

	config := map[string]interface{}{
		"module":     "couchbase",
		"metricsets": []string{"node"},
		"hosts":      []string{server.URL},
	}

	f := mbtest.NewEventsFetcher(t, config)
	events, err := f.Fetch()
	event := events[0]
	if !assert.NoError(t, err) {
		t.FailNow()
	}

	t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event.StringToPrint())

	assert.EqualValues(t, 0, event["cmd_get"])

	couch := event["couch"].(common.MapStr)

	couch_docs := couch["docs"].(common.MapStr)
	couch_docs_actual_disk_size := couch_docs["actual_disk_size"].(common.MapStr)
	assert.EqualValues(t, 13563791, couch_docs_actual_disk_size["bytes"])

	couch_docs_data_size := couch_docs["data_size"].(common.MapStr)
	assert.EqualValues(t, 9792512, couch_docs_data_size["bytes"])

	couch_spacial := couch["spacial"].(common.MapStr)
	couch_spacial_data_size := couch_spacial["data_size"].(common.MapStr)
	assert.EqualValues(t, 0, couch_spacial_data_size["bytes"])

	couch_spacial_disk_size := couch_spacial["disk_size"].(common.MapStr)
	assert.EqualValues(t, 0, couch_spacial_disk_size["bytes"])

	couch_views := couch["views"].(common.MapStr)
	couch_views_actual_disk_size := couch_views["actual_disk_size"].(common.MapStr)
	assert.EqualValues(t, 2805219, couch_views_actual_disk_size["bytes"])

	couch_views_data_size := couch_views["data_size"].(common.MapStr)
	assert.EqualValues(t, 2805219, couch_views_data_size["bytes"])

	event_cpu_utilization_rate := event["cpu_utilization_rate"].(common.MapStr)
	assert.EqualValues(t, 29.64705882352941, event_cpu_utilization_rate["pct"])

	current_items := event["current_items"].(common.MapStr)
	assert.EqualValues(t, 7303, current_items["value"])
	assert.EqualValues(t, 7303, current_items["total"])

	assert.EqualValues(t, 0, event["ep_bg_fetched"])
	assert.EqualValues(t, 0, event["get_hits"])
	assert.Equal(t, "172.17.0.2:8091", event["hostname"])

	mcd_memory := event["mcd_memory"].(common.MapStr)
	mcd_memory_reserved := mcd_memory["reserved"].(common.MapStr)
	assert.EqualValues(t, 6377, mcd_memory_reserved["bytes"])

	mcd_memory_allocated := mcd_memory["allocated"].(common.MapStr)
	assert.EqualValues(t, 6377, mcd_memory_allocated["bytes"])

	memory := event["memory"].(common.MapStr)
	memory_total := memory["total"].(common.MapStr)
	assert.EqualValues(t, 8359174144, memory_total["bytes"])

	memory_free := memory["free"].(common.MapStr)
	assert.EqualValues(t, 4678324224, memory_free["bytes"])

	memory_used := memory["used"].(common.MapStr)
	assert.EqualValues(t, 53962016, memory_used["bytes"])

	assert.EqualValues(t, 0, event["ops"])

	swap := event["swap"].(common.MapStr)
	swap_total := swap["total"].(common.MapStr)
	assert.EqualValues(t, 4189057024, swap_total["bytes"])

	swap_used := swap["used"].(common.MapStr)
	assert.EqualValues(t, 135168, swap_used["bytes"])

	event_uptime := event["uptime"].(common.MapStr)
	assert.EqualValues(t, 7260, event_uptime["sec"])

	assert.EqualValues(t, 0, event["vb_replica_curr_items"])
}