本文整理匯總了Golang中github.com/elastic/beats/metricbeat/mb/testing.NewEventFetcher函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewEventFetcher函數的具體用法?Golang NewEventFetcher怎麽用?Golang NewEventFetcher使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewEventFetcher函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestPasswords
func TestPasswords(t *testing.T) {
// Add password and ensure it gets reset
defer resetPassword(redisHost, password, "")
err := addPassword(redisHost, password)
if err != nil {
t.Fatal("adding password", err)
}
// Test Fetch metrics with missing password
f := mbtest.NewEventFetcher(t, getConfig(""))
_, err = f.Fetch()
if assert.Error(t, err, "missing password") {
assert.Contains(t, err, "NOAUTH Authentication required.")
}
// Config redis and metricset with an invalid password
f = mbtest.NewEventFetcher(t, getConfig("blah"))
_, err = f.Fetch()
if assert.Error(t, err, "invalid password") {
assert.Contains(t, err, "ERR invalid password")
}
// Config redis and metricset with a valid password
f = mbtest.NewEventFetcher(t, getConfig(password))
_, err = f.Fetch()
assert.NoError(t, err, "valid password")
}
示例2: TestFetchTimeout
// TestFetchTimeout verifies that the HTTP request times out and an error is
// returned.
func TestFetchTimeout(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Header().Set("Content-Type", "text/plain; charset=ISO-8859-1")
w.Write([]byte(response))
time.Sleep(100 * time.Millisecond)
}))
defer server.Close()
config := map[string]interface{}{
"module": "apache",
"metricsets": []string{"status"},
"hosts": []string{server.URL},
"timeout": "50ms",
}
f := mbtest.NewEventFetcher(t, config)
start := time.Now()
_, err := f.Fetch()
elapsed := time.Since(start)
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "request canceled (Client.Timeout exceeded")
}
// Elapsed should be ~50ms, sometimes it can be up to 1s
assert.True(t, elapsed < 5*time.Second, "elapsed time: %s", elapsed.String())
}
示例3: TestFetch
func TestFetch(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
assert.Contains(t, event, "checkpoints")
assert.Contains(t, event, "buffers")
assert.Contains(t, event, "stats_reset")
checkpoints := event["checkpoints"].(common.MapStr)
assert.Contains(t, checkpoints, "scheduled")
assert.Contains(t, checkpoints, "requested")
assert.Contains(t, checkpoints, "times")
buffers := event["buffers"].(common.MapStr)
assert.Contains(t, buffers, "checkpoints")
assert.Contains(t, buffers, "clean")
assert.Contains(t, buffers, "clean_full")
assert.Contains(t, buffers, "backend")
assert.Contains(t, buffers, "backend_fsync")
assert.Contains(t, buffers, "allocated")
}
示例4: TestData
func TestData(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
err := mbtest.WriteEvent(f, t)
if err != nil {
t.Fatal("write", err)
}
}
示例5: TestData
func TestData(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
// Do a first fetch to have percentages
f.Fetch()
time.Sleep(1 * time.Second)
err := mbtest.WriteEvent(f, t)
if err != nil {
t.Fatal("write", err)
}
}
示例6: TestFetch
func TestFetch(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
// Check event fields
openFiles := event["harvesters"].(common.MapStr)["files"].(common.MapStr)["open"].(int64)
assert.True(t, openFiles >= 0)
}
示例7: TestFetch
func TestFetch(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig(""))
event, err := f.Fetch()
if err != nil {
t.Fatal("fetch", err)
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
// Check fields
assert.Equal(t, 8, len(event))
server := event["server"].(common.MapStr)
assert.Equal(t, "standalone", server["mode"])
}
示例8: TestFetch
func TestFetch(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
// Check number of fields.
if len(event) < 11 {
t.Fatal("Too few top-level elements in the event")
}
}
示例9: TestKeyspace
func TestKeyspace(t *testing.T) {
// Write to DB to enable Keyspace stats
err := writeToRedis(redisHost)
if err != nil {
t.Fatal("write to host", err)
}
// Fetch metrics
f := mbtest.NewEventFetcher(t, getConfig(""))
event, err := f.Fetch()
if err != nil {
t.Fatal("fetch", err)
}
keyspace := event["keyspace"].(map[string]common.MapStr)
keyCount := keyspace["db0"]["keys"].(int)
assert.True(t, (keyCount > 0))
}
示例10: TestFetch
func TestFetch(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
// Check event fields
current := event["connections"].(common.MapStr)["current"].(int64)
assert.True(t, current >= 0)
available := event["connections"].(common.MapStr)["available"].(int64)
assert.True(t, available > 0)
commits := event["journaling"].(common.MapStr)["commits"].(int64)
assert.True(t, commits >= 0)
}
示例11: TestFetch
func TestFetch(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
// Check event fields
connections := event["connections"].(int64)
open := event["open"].(common.MapStr)
openTables := open["tables"].(int64)
openFiles := open["files"].(int64)
openStreams := open["streams"].(int64)
assert.True(t, connections > 0)
assert.True(t, openTables > 0)
assert.True(t, openFiles >= 0)
assert.True(t, openStreams == 0)
}
示例12: TestMultipleFetches
// TestMultipleFetches verifies that the server connection is reused when HTTP
// keep-alive is supported by the server.
func TestMultipleFetches(t *testing.T) {
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Header().Set("Content-Type", "text/plain; charset=ISO-8859-1")
w.Write([]byte(response))
}))
connLock := sync.Mutex{}
conns := map[string]struct{}{}
server.Config.ConnState = func(conn net.Conn, state http.ConnState) {
connLock.Lock()
conns[conn.RemoteAddr().String()] = struct{}{}
connLock.Unlock()
}
server.Start()
defer server.Close()
config := map[string]interface{}{
"module": "apache",
"metricsets": []string{"status"},
"hosts": []string{server.URL},
}
f := mbtest.NewEventFetcher(t, config)
for i := 0; i < 20; i++ {
_, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
}
connLock.Lock()
assert.Len(t, conns, 1,
"only a single connection should exist because of keep-alives")
connLock.Unlock()
}
示例13: TestFetchRaw
func TestFetchRaw(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig(true))
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
// Check event fields
cachedThreads := event["threads"].(common.MapStr)["cached"].(int64)
assert.True(t, cachedThreads >= 0)
rawData := event["raw"].(common.MapStr)
// Make sure field was removed from raw fields as in schema
_, exists := rawData["Threads_cached"]
assert.False(t, exists)
// Check a raw field if it is available
_, exists = rawData["Slow_launch_threads"]
assert.True(t, exists)
}
示例14: TestFetch
func TestFetch(t *testing.T) {
f := mbtest.NewEventFetcher(t, getConfig())
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)
// Check values
version := event["zk_version"].(string)
avgLatency := event["zk_avg_latency"].(int)
maxLatency := event["zk_max_latency"].(int)
numAliveConnections := event["zk_num_alive_connections"].(int)
assert.Equal(t, version, "3.4.8--1, built on 02/06/2016 03:18 GMT")
assert.True(t, avgLatency >= 0)
assert.True(t, maxLatency >= 0)
assert.True(t, numAliveConnections > 0)
// Check fields
assert.Equal(t, 18, len(event))
}
示例15: TestFetchEventContents
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{"cluster"},
"hosts": []string{server.URL},
}
f := mbtest.NewEventFetcher(t, config)
event, err := f.Fetch()
if !assert.NoError(t, err) {
t.FailNow()
}
t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event.StringToPrint())
hdd := event["hdd"].(common.MapStr)
hdd_free := hdd["free"].(common.MapStr)
assert.EqualValues(t, 46902679716, hdd_free["bytes"])
hdd_total := hdd["total"].(common.MapStr)
assert.EqualValues(t, 63381999616, hdd_total["bytes"])
hdd_used := hdd["used"].(common.MapStr)
hdd_used_value := hdd_used["value"].(common.MapStr)
assert.EqualValues(t, 16479319900, hdd_used_value["bytes"])
hdd_used_by_data := hdd_used["by_data"].(common.MapStr)
assert.EqualValues(t, 16369010, hdd_used_by_data["bytes"])
hdd_quota := hdd["quota"].(common.MapStr)
hdd_quota_total := hdd_quota["total"].(common.MapStr)
assert.EqualValues(t, 63381999616, hdd_quota_total["bytes"])
assert.EqualValues(t, 10, event["max_bucket_count"])
quota := event["quota"].(common.MapStr)
quota_index_memory := quota["index_memory"].(common.MapStr)
assert.EqualValues(t, 300, quota_index_memory["mb"])
quota_memory := quota["memory"].(common.MapStr)
assert.EqualValues(t, 300, quota_memory["mb"])
ram := event["ram"].(common.MapStr)
ram_quota := ram["quota"].(common.MapStr)
ram_quota_total := ram_quota["total"].(common.MapStr)
ram_quota_total_value := ram_quota_total["value"].(common.MapStr)
assert.EqualValues(t, 314572800, ram_quota_total_value["bytes"])
ram_quota_total_per_node := ram_quota_total["per_node"].(common.MapStr)
assert.EqualValues(t, 314572800, ram_quota_total_per_node["bytes"])
ram_quota_used := ram_quota["used"].(common.MapStr)
ram_quota_used_value := ram_quota_used["value"].(common.MapStr)
assert.EqualValues(t, 104857600, ram_quota_used_value["bytes"])
ram_quota_used_per_node := ram_quota_used["per_node"].(common.MapStr)
assert.EqualValues(t, 104857600, ram_quota_used_per_node["bytes"])
ram_total := ram["total"].(common.MapStr)
assert.EqualValues(t, 8359174144, ram_total["bytes"])
ram_used := ram["used"].(common.MapStr)
ram_used_value := ram_used["value"].(common.MapStr)
assert.EqualValues(t, 8004751360, ram_used_value["bytes"])
ram_used_by_data := ram_used["by_data"].(common.MapStr)
assert.EqualValues(t, 53962016, ram_used_by_data["bytes"])
}