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


Golang Accumulator.AssertContainsTaggedFields方法代码示例

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


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

示例1: TestHaproxyGeneratesMetricsWithoutAuthentication

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

	r := &haproxy{
		Servers: []string{ts.URL},
	}

	var acc testutil.Accumulator

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

	tags := map[string]string{
		"proxy":  "be_app",
		"server": ts.Listener.Addr().String(),
		"sv":     "host0",
	}

	fields := map[string]interface{}{
		"active_servers":    uint64(1),
		"backup_servers":    uint64(0),
		"bin":               uint64(510913516),
		"bout":              uint64(2193856571),
		"check_duration":    uint64(10),
		"cli_abort":         uint64(73),
		"ctime":             uint64(2),
		"downtime":          uint64(0),
		"dresp":             uint64(0),
		"econ":              uint64(0),
		"eresp":             uint64(1),
		"http_response.1xx": uint64(0),
		"http_response.2xx": uint64(119534),
		"http_response.3xx": uint64(48051),
		"http_response.4xx": uint64(2345),
		"http_response.5xx": uint64(1056),
		"lbtot":             uint64(171013),
		"qcur":              uint64(0),
		"qmax":              uint64(0),
		"qtime":             uint64(0),
		"rate":              uint64(3),
		"rate_max":          uint64(12),
		"rtime":             uint64(312),
		"scur":              uint64(1),
		"smax":              uint64(32),
		"srv_abort":         uint64(1),
		"stot":              uint64(171014),
		"ttime":             uint64(2341),
		"wredis":            uint64(0),
		"wretr":             uint64(1),
	}
	acc.AssertContainsTaggedFields(t, "haproxy", fields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:55,代码来源:haproxy_test.go

示例2: TestNginxGeneratesMetrics

func TestNginxGeneratesMetrics(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		var rsp string

		if r.URL.Path == "/stub_status" {
			rsp = sampleResponse
		} else {
			panic("Cannot handle request")
		}

		fmt.Fprintln(w, rsp)
	}))
	defer ts.Close()

	n := &Nginx{
		Urls: []string{fmt.Sprintf("%s/stub_status", ts.URL)},
	}

	var acc testutil.Accumulator

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

	fields := map[string]interface{}{
		"active":   uint64(585),
		"accepts":  uint64(85340),
		"handled":  uint64(85340),
		"requests": uint64(35085),
		"reading":  uint64(4),
		"writing":  uint64(135),
		"waiting":  uint64(446),
	}
	addr, err := url.Parse(ts.URL)
	if err != nil {
		panic(err)
	}

	host, port, err := net.SplitHostPort(addr.Host)
	if err != nil {
		host = addr.Host
		if addr.Scheme == "http" {
			port = "80"
		} else if addr.Scheme == "https" {
			port = "443"
		} else {
			port = ""
		}
	}

	tags := map[string]string{"server": host, "port": port}
	acc.AssertContainsTaggedFields(t, "nginx", fields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:52,代码来源:nginx_test.go

示例3: TestRedis_ParseMetrics

func TestRedis_ParseMetrics(t *testing.T) {
	var acc testutil.Accumulator
	tags := map[string]string{"host": "redis.net"}
	rdr := bufio.NewReader(strings.NewReader(testOutput))

	err := gatherInfoOutput(rdr, &acc, tags)
	require.NoError(t, err)

	fields := map[string]interface{}{
		"uptime":                      uint64(238),
		"clients":                     uint64(1),
		"used_memory":                 uint64(1003936),
		"used_memory_rss":             uint64(811008),
		"used_memory_peak":            uint64(1003936),
		"used_memory_lua":             uint64(33792),
		"rdb_changes_since_last_save": uint64(0),
		"total_connections_received":  uint64(2),
		"total_commands_processed":    uint64(1),
		"instantaneous_ops_per_sec":   uint64(0),
		"sync_full":                   uint64(0),
		"sync_partial_ok":             uint64(0),
		"sync_partial_err":            uint64(0),
		"expired_keys":                uint64(0),
		"evicted_keys":                uint64(0),
		"keyspace_hits":               uint64(1),
		"keyspace_misses":             uint64(1),
		"pubsub_channels":             uint64(0),
		"pubsub_patterns":             uint64(0),
		"latest_fork_usec":            uint64(0),
		"connected_slaves":            uint64(0),
		"master_repl_offset":          uint64(0),
		"repl_backlog_active":         uint64(0),
		"repl_backlog_size":           uint64(1048576),
		"repl_backlog_histlen":        uint64(0),
		"mem_fragmentation_ratio":     float64(0.81),
		"instantaneous_input_kbps":    float64(876.16),
		"instantaneous_output_kbps":   float64(3010.23),
		"used_cpu_sys":                float64(0.14),
		"used_cpu_user":               float64(0.05),
		"used_cpu_sys_children":       float64(0.00),
		"used_cpu_user_children":      float64(0.00),
		"keyspace_hitrate":            float64(0.50),
	}
	keyspaceFields := map[string]interface{}{
		"avg_ttl": uint64(0),
		"expires": uint64(0),
		"keys":    uint64(2),
	}
	acc.AssertContainsTaggedFields(t, "redis", fields, tags)
	acc.AssertContainsTaggedFields(t, "redis_keyspace", keyspaceFields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:51,代码来源:redis_test.go

示例4: TestHttpJson200

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

	for _, service := range httpjson {
		var acc testutil.Accumulator
		err := service.Gather(&acc)
		require.NoError(t, err)
		assert.Equal(t, 4, acc.NFields())
		for _, srv := range service.Servers {
			tags := map[string]string{"server": srv}
			mname := "httpjson_" + service.Name
			acc.AssertContainsTaggedFields(t, mname, expectedFields, tags)
		}
	}
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:16,代码来源:httpjson_test.go

示例5: TestLossyPingGather

// Test that Gather works on a ping with lossy packets
func TestLossyPingGather(t *testing.T) {
	var acc testutil.Accumulator
	p := Ping{
		Urls:     []string{"www.google.com"},
		pingHost: mockLossyHostPinger,
	}

	p.Gather(&acc)
	tags := map[string]string{"url": "www.google.com"}
	fields := map[string]interface{}{
		"packets_transmitted": 5,
		"packets_received":    3,
		"percent_packet_loss": 40.0,
		"average_response_ms": 44.033,
	}
	acc.AssertContainsTaggedFields(t, "ping", fields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:18,代码来源:ping_test.go

示例6: TestBadPingGather

// Test that Gather works on a ping with no transmitted packets, even though the
// command returns an error
func TestBadPingGather(t *testing.T) {
	var acc testutil.Accumulator
	p := Ping{
		Urls:     []string{"www.amazon.com"},
		pingHost: mockErrorHostPinger,
	}

	p.Gather(&acc)
	tags := map[string]string{"url": "www.amazon.com"}
	fields := map[string]interface{}{
		"packets_transmitted": 2,
		"packets_received":    0,
		"percent_packet_loss": 100.0,
		"average_response_ms": 0.0,
	}
	acc.AssertContainsTaggedFields(t, "ping", fields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:19,代码来源:ping_test.go

示例7: TestStateTag

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

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

	var acc testutil.Accumulator

	d.AddDefaultStats()
	d.flush(&acc)
	fields := map[string]interface{}{
		"active_reads":          int64(0),
		"active_writes":         int64(0),
		"commands_per_sec":      int64(0),
		"deletes_per_sec":       int64(0),
		"flushes_per_sec":       int64(0),
		"getmores_per_sec":      int64(0),
		"inserts_per_sec":       int64(0),
		"member_status":         "PRI",
		"net_in_bytes":          int64(0),
		"net_out_bytes":         int64(0),
		"open_connections":      int64(0),
		"queries_per_sec":       int64(0),
		"queued_reads":          int64(0),
		"queued_writes":         int64(0),
		"repl_commands_per_sec": int64(0),
		"repl_deletes_per_sec":  int64(0),
		"repl_getmores_per_sec": int64(0),
		"repl_inserts_per_sec":  int64(0),
		"repl_queries_per_sec":  int64(0),
		"repl_updates_per_sec":  int64(0),
		"resident_megabytes":    int64(0),
		"updates_per_sec":       int64(0),
		"vsize_megabytes":       int64(0),
	}
	acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:46,代码来源:mongodb_data_test.go

示例8: TestHttpJson200Tags

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

	for _, service := range httpjson {
		if service.Name == "other_webapp" {
			var acc testutil.Accumulator
			err := service.Gather(&acc)
			require.NoError(t, err)
			assert.Equal(t, 2, acc.NFields())
			for _, srv := range service.Servers {
				tags := map[string]string{"server": srv, "role": "master", "build": "123"}
				fields := map[string]interface{}{"value": float64(15)}
				mname := "httpjson_" + service.Name
				acc.AssertContainsTaggedFields(t, mname, fields, tags)
			}
		}
	}
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:19,代码来源:httpjson_test.go

示例9: TestReadAerospikeStatsNamespace

func TestReadAerospikeStatsNamespace(t *testing.T) {
	var acc testutil.Accumulator
	stats := map[string]string{
		"stat_write_errs": "12345",
		"stat_read_reqs":  "12345",
	}
	readAerospikeStats(stats, &acc, "host1", "test")

	fields := map[string]interface{}{
		"stat_write_errs": int64(12345),
		"stat_read_reqs":  int64(12345),
	}
	tags := map[string]string{
		"aerospike_host": "host1",
		"namespace":      "test",
	}
	acc.AssertContainsTaggedFields(t, "aerospike", fields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:18,代码来源:aerospike_test.go

示例10: TestGather

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

	pa := PuppetAgent{
		Location: "last_run_summary.yaml",
	}
	pa.Gather(&acc)

	tags := map[string]string{"location": "last_run_summary.yaml"}
	fields := map[string]interface{}{
		"events_failure":            int64(0),
		"events_total":              int64(0),
		"events_success":            int64(0),
		"resources_failed":          int64(0),
		"resources_scheduled":       int64(0),
		"resources_changed":         int64(0),
		"resources_skipped":         int64(0),
		"resources_total":           int64(109),
		"resources_failedtorestart": int64(0),
		"resources_restarted":       int64(0),
		"resources_outofsync":       int64(0),
		"changes_total":             int64(0),
		"time_lastrun":              int64(1444936531),
		"version_config":            int64(1444936521),
		"time_user":                 float64(0.004331),
		"time_schedule":             float64(0.001123),
		"time_filebucket":           float64(0.000353),
		"time_file":                 float64(0.441472),
		"time_exec":                 float64(0.508123),
		"time_anchor":               float64(0.000555),
		"time_sshauthorizedkey":     float64(0.000764),
		"time_service":              float64(1.807795),
		"time_package":              float64(1.325788),
		"time_total":                float64(8.85354707064819),
		"time_configretrieval":      float64(4.75567007064819),
		"time_cron":                 float64(0.000584),
		"version_puppet":            "3.7.5",
	}

	acc.AssertContainsTaggedFields(t, "puppetagent", fields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:41,代码来源:puppetagent_test.go

示例11: TestHttpJsonMultiValue

// Test that the proper values are ignored or collected
func TestHttpJsonMultiValue(t *testing.T) {
	jolokia := genJolokiaClientStub(validMultiValueJSON, 200, Servers, []Metric{HeapMetric})

	var acc testutil.Accumulator
	err := jolokia.Gather(&acc)

	assert.Nil(t, err)
	assert.Equal(t, 1, len(acc.Points))

	fields := map[string]interface{}{
		"heap_memory_usage_init":      67108864.0,
		"heap_memory_usage_committed": 456130560.0,
		"heap_memory_usage_max":       477626368.0,
		"heap_memory_usage_used":      203288528.0,
	}
	tags := map[string]string{
		"host":   "127.0.0.1",
		"port":   "8080",
		"server": "as1",
	}
	acc.AssertContainsTaggedFields(t, "jolokia", fields, tags)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:23,代码来源:jolokia_test.go

示例12: TestZfsPoolMetrics

func TestZfsPoolMetrics(t *testing.T) {
	err := os.MkdirAll(testKstatPath, 0755)
	require.NoError(t, err)

	err = os.MkdirAll(testKstatPath+"/HOME", 0755)
	require.NoError(t, err)

	err = ioutil.WriteFile(testKstatPath+"/HOME/io", []byte(pool_ioContents), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testKstatPath+"/arcstats", []byte(arcstatsContents), 0644)
	require.NoError(t, err)

	poolMetrics := getPoolMetrics()

	var acc testutil.Accumulator

	z := &Zfs{KstatPath: testKstatPath, KstatMetrics: []string{"arcstats"}}
	err = z.Gather(&acc)
	require.NoError(t, err)

	require.False(t, acc.HasMeasurement("zfs_pool"))
	acc.Points = nil

	z = &Zfs{KstatPath: testKstatPath, KstatMetrics: []string{"arcstats"}, PoolMetrics: true}
	err = z.Gather(&acc)
	require.NoError(t, err)

	//one pool, all metrics
	tags := map[string]string{
		"pool": "HOME",
	}

	acc.AssertContainsTaggedFields(t, "zfs_pool", poolMetrics, tags)

	err = os.RemoveAll(os.TempDir() + "/telegraf")
	require.NoError(t, err)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:38,代码来源:zfs_test.go

示例13: TestPhpFpmGeneratesMetrics

func TestPhpFpmGeneratesMetrics(t *testing.T) {
	//We create a fake server to return test data
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, outputSample)
	}))
	defer ts.Close()

	//Now we tested again above server, with our authentication data
	r := &phpfpm{
		Urls: []string{ts.URL},
	}

	var acc testutil.Accumulator

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

	tags := map[string]string{
		"url":  ts.Listener.Addr().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:ronaldslc,项目名称:telegraf,代码行数:37,代码来源:phpfpm_test.go

示例14: 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))

	acc.AssertContainsTaggedFields(t, "elasticsearch_cluster_health",
		clusterHealthExpected,
		map[string]string{"name": "elasticsearch_telegraf"})

	acc.AssertContainsTaggedFields(t, "elasticsearch_indices",
		v1IndexExpected,
		map[string]string{"index": "v1"})

	acc.AssertContainsTaggedFields(t, "elasticsearch_indices",
		v2IndexExpected,
		map[string]string{"index": "v2"})
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:21,代码来源:elasticsearch_test.go

示例15: TestBcacheGeneratesMetrics

func TestBcacheGeneratesMetrics(t *testing.T) {
	err := os.MkdirAll(testBcacheUuidPath, 0755)
	require.NoError(t, err)

	err = os.MkdirAll(testBcacheDevPath, 0755)
	require.NoError(t, err)

	err = os.MkdirAll(testBcacheBackingDevPath+"/bcache", 0755)
	require.NoError(t, err)

	err = os.Symlink(testBcacheBackingDevPath+"/bcache", testBcacheUuidPath+"/bdev0")
	require.NoError(t, err)

	err = os.Symlink(testBcacheDevPath, testBcacheUuidPath+"/bdev0/dev")
	require.NoError(t, err)

	err = os.MkdirAll(testBcacheUuidPath+"/bdev0/stats_total", 0755)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/dirty_data",
		[]byte(dirty_data), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/bypassed",
		[]byte(bypassed), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_bypass_hits",
		[]byte(cache_bypass_hits), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_bypass_misses",
		[]byte(cache_bypass_misses), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_hit_ratio",
		[]byte(cache_hit_ratio), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_hits",
		[]byte(cache_hits), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_miss_collisions",
		[]byte(cache_miss_collisions), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_misses",
		[]byte(cache_misses), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(testBcacheUuidPath+"/bdev0/stats_total/cache_readaheads",
		[]byte(cache_readaheads), 0644)
	require.NoError(t, err)

	fields := map[string]interface{}{
		"dirty_data":            uint64(1610612736),
		"bypassed":              uint64(5167704440832),
		"cache_bypass_hits":     uint64(146155333),
		"cache_bypass_misses":   uint64(0),
		"cache_hit_ratio":       uint64(90),
		"cache_hits":            uint64(511469583),
		"cache_miss_collisions": uint64(157567),
		"cache_misses":          uint64(50616331),
		"cache_readaheads":      uint64(2),
	}

	tags := map[string]string{
		"backing_dev": "md10",
		"bcache_dev":  "bcache0",
	}

	var acc testutil.Accumulator

	// all devs
	b := &Bcache{BcachePath: testBcachePath}

	err = b.Gather(&acc)
	require.NoError(t, err)
	acc.AssertContainsTaggedFields(t, "bcache", fields, tags)

	// one exist dev
	b = &Bcache{BcachePath: testBcachePath, BcacheDevs: []string{"bcache0"}}

	err = b.Gather(&acc)
	require.NoError(t, err)
	acc.AssertContainsTaggedFields(t, "bcache", fields, tags)

	err = os.RemoveAll(os.TempDir() + "/telegraf")
	require.NoError(t, err)
}
开发者ID:ronaldslc,项目名称:telegraf,代码行数:91,代码来源:bcache_test.go


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