当前位置: 首页>>代码示例>>Golang>>正文


Golang testutil.Accumulator类代码示例

本文整理汇总了Golang中github.com/influxdb/telegraf/testutil.Accumulator的典型用法代码示例。如果您正苦于以下问题:Golang Accumulator类的具体用法?Golang Accumulator怎么用?Golang Accumulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Accumulator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestAddEngineStatsPartial

func TestAddEngineStatsPartial(t *testing.T) {
	engine := &Engine{
		ClientConns:   0,
		ClientActive:  0,
		QueriesPerSec: 0,
		ReadsPerSec:   0,
		WritesPerSec:  0,
	}

	var acc testutil.Accumulator

	keys := []string{
		"active_clients",
		"clients",
		"queries_per_sec",
		"read_docs_per_sec",
		"written_docs_per_sec",
	}

	missing_keys := []string{
		"total_queries",
		"total_reads",
		"total_writes",
	}
	engine.AddEngineStats(keys, &acc, tags)

	for _, metric := range missing_keys {
		assert.False(t, acc.HasIntValue(metric))
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:30,代码来源:rethinkdb_data_test.go

示例2: TestGatherClusterStats

func TestGatherClusterStats(t *testing.T) {
	es := NewElasticsearch()
	es.Servers = []string{"http://example.com:9200"}
	es.ClusterHealth = true
	es.client.Transport = newTransportMock(http.StatusOK, clusterResponse)

	var acc testutil.Accumulator
	require.NoError(t, es.Gather(&acc))

	var clusterHealthTests = []struct {
		measurement string
		fields      map[string]interface{}
		tags        map[string]string
	}{
		{
			"cluster_health",
			clusterHealthExpected,
			map[string]string{"name": "elasticsearch_telegraf"},
		},
		{
			"indices",
			v1IndexExpected,
			map[string]string{"index": "v1"},
		},
		{
			"indices",
			v2IndexExpected,
			map[string]string{"index": "v2"},
		},
	}

	for _, exp := range clusterHealthTests {
		assert.NoError(t, acc.ValidateTaggedFields(exp.measurement, exp.fields, exp.tags))
	}
}
开发者ID:rzagabe,项目名称:telegraf,代码行数:35,代码来源:elasticsearch_test.go

示例3: TestAerospikeStatistics

func TestAerospikeStatistics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	a := &Aerospike{
		Servers: []string{testutil.GetLocalHost() + ":3000"},
	}

	var acc testutil.Accumulator

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

	// Only use a few of the metrics
	asMetrics := []string{
		"transactions",
		"stat_write_errs",
		"stat_read_reqs",
		"stat_write_reqs",
	}

	for _, metric := range asMetrics {
		assert.True(t, acc.HasIntValue(metric), metric)
	}

}
开发者ID:rzagabe,项目名称:telegraf,代码行数:27,代码来源:aerospike_test.go

示例4: TestAddNonReplStats

func TestAddNonReplStats(t *testing.T) {
	d := NewMongodbData(
		&StatLine{
			StorageEngine:  "",
			Time:           time.Now(),
			Insert:         0,
			Query:          0,
			Update:         0,
			Delete:         0,
			GetMore:        0,
			Command:        0,
			Flushes:        0,
			Virtual:        0,
			Resident:       0,
			QueuedReaders:  0,
			QueuedWriters:  0,
			ActiveReaders:  0,
			ActiveWriters:  0,
			NetIn:          0,
			NetOut:         0,
			NumConnections: 0,
		},
		tags,
	)
	var acc testutil.Accumulator

	d.AddDefaultStats()
	d.flush(&acc)

	for key, _ := range DefaultStats {
		assert.True(t, acc.HasIntField("mongodb", key))
	}
}
开发者ID:d4devops,项目名称:telegraf,代码行数:33,代码来源:mongodb_data_test.go

示例5: TestAddTableStats

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

	err := server.addTableStats(&acc)
	require.NoError(t, err)

	for _, metric := range TableTracking {
		assert.True(t, acc.HasIntValue(metric))
	}

	keys := []string{
		"cache_bytes_in_use",
		"disk_read_bytes_per_sec",
		"disk_read_bytes_total",
		"disk_written_bytes_per_sec",
		"disk_written_bytes_total",
		"disk_usage_data_bytes",
		"disk_usage_garbage_bytes",
		"disk_usage_metadata_bytes",
		"disk_usage_preallocated_bytes",
	}

	for _, metric := range keys {
		assert.True(t, acc.HasIntValue(metric))
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:26,代码来源:rethinkdb_server_test.go

示例6: testMain

func testMain(t *testing.T, code string, endpoint string, serverType ServerType) {
	// Build the fake snmpwalk for test
	src := makeFakeSNMPSrc(code)
	defer os.Remove(src)
	buildFakeSNMPCmd(src)
	defer os.Remove("./snmpwalk")
	envPathOrigin := os.Getenv("PATH")
	// Refer to the fake snmpwalk
	os.Setenv("PATH", ".")
	defer os.Setenv("PATH", envPathOrigin)

	l := &LeoFS{
		Servers: []string{endpoint},
	}

	var acc testutil.Accumulator
	acc.SetDebug(true)

	err := l.Gather(&acc)
	require.NoError(t, err)

	floatMetrics := KeyMapping[serverType]

	for _, metric := range floatMetrics {
		assert.True(t, acc.HasFloatField("leofs", metric), metric)
	}
}
开发者ID:d4devops,项目名称:telegraf,代码行数:27,代码来源:leofs_test.go

示例7: TestMemcachedGeneratesMetrics

func TestMemcachedGeneratesMetrics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	m := &Memcached{
		Servers: []string{testutil.GetLocalHost()},
	}

	var acc testutil.Accumulator

	err := m.Gather(&acc)
	require.NoError(t, err)

	intMetrics := []string{"get_hits", "get_misses", "evictions",
		"limit_maxbytes", "bytes", "uptime", "curr_items", "total_items",
		"curr_connections", "total_connections", "connection_structures", "cmd_get",
		"cmd_set", "delete_hits", "delete_misses", "incr_hits", "incr_misses",
		"decr_hits", "decr_misses", "cas_hits", "cas_misses", "evictions",
		"bytes_read", "bytes_written", "threads", "conn_yields"}

	for _, metric := range intMetrics {
		assert.True(t, acc.HasIntValue(metric), metric)
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:25,代码来源:memcached_test.go

示例8: TestZookeeperGeneratesMetrics

func TestZookeeperGeneratesMetrics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	z := &Zookeeper{
		Servers: []string{testutil.GetLocalHost()},
	}

	var acc testutil.Accumulator

	err := z.Gather(&acc)
	require.NoError(t, err)

	intMetrics := []string{
		"avg_latency",
		"max_latency",
		"min_latency",
		"packets_received",
		"packets_sent",
		"outstanding_requests",
		"znode_count",
		"watch_count",
		"ephemerals_count",
		"approximate_data_size",
		"open_file_descriptor_count",
		"max_file_descriptor_count",
	}

	for _, metric := range intMetrics {
		assert.True(t, acc.HasIntValue(metric), metric)
	}
}
开发者ID:jrxFive,项目名称:telegraf,代码行数:33,代码来源:zookeeper_test.go

示例9: TestHttpJson200

// Test that the proper values are ignored or collected
func TestHttpJson200(t *testing.T) {
	httpjson := genMockHttpJson(validJSON, 200)

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

	assert.Equal(t, 8, len(acc.Points))

	for _, service := range httpjson.Services {
		for _, srv := range service.Servers {
			require.NoError(t,
				acc.ValidateTaggedValue(
					fmt.Sprintf("%s_parent_child", service.Name),
					3.0,
					map[string]string{"server": srv},
				),
			)
			require.NoError(t,
				acc.ValidateTaggedValue(
					fmt.Sprintf("%s_integer", service.Name),
					4.0,
					map[string]string{"server": srv},
				),
			)
		}
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:29,代码来源:httpjson_test.go

示例10: TestPrometheusGeneratesMetrics

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

	p := &Prometheus{
		Urls: []string{ts.URL},
	}

	var acc testutil.Accumulator

	err := p.Gather(&acc)
	require.NoError(t, err)

	expected := []struct {
		name  string
		value float64
		tags  map[string]string
	}{
		{"go_gc_duration_seconds_count", 7, map[string]string{}},
		{"go_goroutines", 15, map[string]string{}},
	}

	for _, e := range expected {
		assert.NoError(t, acc.ValidateValue(e.name, e.value))
	}
}
开发者ID:jmptrader,项目名称:telegraf,代码行数:28,代码来源:prometheus_test.go

示例11: TestAddEngineStats

func TestAddEngineStats(t *testing.T) {
	engine := &Engine{
		ClientConns:   0,
		ClientActive:  0,
		QueriesPerSec: 0,
		TotalQueries:  0,
		ReadsPerSec:   0,
		TotalReads:    0,
		WritesPerSec:  0,
		TotalWrites:   0,
	}

	var acc testutil.Accumulator

	keys := []string{
		"active_clients",
		"clients",
		"queries_per_sec",
		"total_queries",
		"read_docs_per_sec",
		"total_reads",
		"written_docs_per_sec",
		"total_writes",
	}
	engine.AddEngineStats(keys, &acc, tags)

	for _, metric := range keys {
		assert.True(t, acc.HasIntField("rethinkdb_engine", metric))
	}
}
开发者ID:d4devops,项目名称:telegraf,代码行数:30,代码来源:rethinkdb_data_test.go

示例12: TestPrometheusWritePointEmptyTag

func TestPrometheusWritePointEmptyTag(t *testing.T) {

	p := &prometheus.Prometheus{
		Urls: []string{"http://localhost:9126/metrics"},
	}
	tags := make(map[string]string)
	var points = []*client.Point{
		client.NewPoint(
			"test_point_1",
			tags,
			map[string]interface{}{"value": 0.0}),
		client.NewPoint(
			"test_point_2",
			tags,
			map[string]interface{}{"value": 1.0}),
	}
	require.NoError(t, pTesting.Write(points))

	expected := []struct {
		name  string
		value float64
		tags  map[string]string
	}{
		{"test_point_1", 0.0, tags},
		{"test_point_2", 1.0, tags},
	}

	var acc testutil.Accumulator

	require.NoError(t, p.Gather(&acc))
	for _, e := range expected {
		assert.NoError(t, acc.ValidateValue(e.name, e.value))
	}
}
开发者ID:jp2007,项目名称:telegraf,代码行数:34,代码来源:prometheus_client_test.go

示例13: TestPostgresqlTagsMetricsWithDatabaseName

func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	p := &Postgresql{
		Servers: []*Server{
			{
				Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
					testutil.GetLocalHost()),
				Databases: []string{"postgres"},
			},
		},
	}

	var acc testutil.Accumulator

	err := p.Gather(&acc)
	require.NoError(t, err)

	point, ok := acc.Get("xact_commit")
	require.True(t, ok)

	assert.Equal(t, "postgres", point.Tags["db"])
}
开发者ID:nickscript0,项目名称:telegraf,代码行数:25,代码来源:postgresql_test.go

示例14: TestStateTag

func TestStateTag(t *testing.T) {
	d := NewMongodbData(
		&StatLine{
			StorageEngine: "",
			Time:          time.Now(),
			Insert:        0,
			Query:         0,
			NodeType:      "PRI",
		},
		tags,
	)

	stats := []string{"inserts_per_sec", "queries_per_sec"}

	stateTags := make(map[string]string)
	stateTags["state"] = "PRI"

	var acc testutil.Accumulator

	d.AddDefaultStats(&acc)

	for _, key := range stats {
		err := acc.ValidateTaggedValue(key, int64(0), stateTags)
		require.NoError(t, err)
	}
}
开发者ID:timjwright,项目名称:telegraf,代码行数:26,代码来源:mongodb_data_test.go

示例15: TestPhpFpmGeneratesMetrics_From_Http

func TestPhpFpmGeneratesMetrics_From_Http(t *testing.T) {
	sv := statServer{}
	ts := httptest.NewServer(sv)
	defer ts.Close()

	r := &phpfpm{
		Urls: []string{ts.URL},
	}

	var acc testutil.Accumulator

	err := r.Gather(&acc)
	require.NoError(t, err)

	tags := map[string]string{
		"pool": "www",
	}

	fields := map[string]interface{}{
		"accepted_conn":        int64(3),
		"listen_queue":         int64(1),
		"max_listen_queue":     int64(0),
		"listen_queue_len":     int64(0),
		"idle_processes":       int64(1),
		"active_processes":     int64(1),
		"total_processes":      int64(2),
		"max_active_processes": int64(1),
		"max_children_reached": int64(2),
		"slow_requests":        int64(1),
	}

	acc.AssertContainsTaggedFields(t, "phpfpm", fields, tags)
}
开发者ID:skwong2,项目名称:telegraf,代码行数:33,代码来源:phpfpm_test.go


注:本文中的github.com/influxdb/telegraf/testutil.Accumulator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。