• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang testutil.Accumulator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestExec

func TestExec(t *testing.T) {
	runner := newRunnerMock([]byte(validJson), nil)
	command := Command{Command: "testcommand arg1", Name: "mycollector"}
	e := &Exec{runner: runner, Commands: []*Command{&command}}

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

	checkFloat := []struct {
		name  string
		value float64
	}{
		{"mycollector_num_processes", 82},
		{"mycollector_cpu_used", 8234},
		{"mycollector_cpu_free", 32},
		{"mycollector_percent", 0.81},
	}

	for _, c := range checkFloat {
		assert.True(t, acc.CheckValue(c.name, c.value))
	}

	assert.Equal(t, len(acc.Points), 4, "non-numeric measurements should be ignored")
}
开发者ID:toorop,项目名称:telegraf,代码行数:25,代码来源:exec_test.go


示例2: 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:toorop,项目名称:telegraf,代码行数:26,代码来源:rethinkdb_server_test.go


示例3: 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:toorop,项目名称:telegraf,代码行数:29,代码来源:httpjson_test.go


示例4: 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:toorop,项目名称:telegraf,代码行数:25,代码来源:postgresql_test.go


示例5: 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:toorop,项目名称:telegraf,代码行数:28,代码来源:prometheus_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

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

	floatMetrics := KeyMapping[serverType]

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


示例7: 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:toorop,项目名称:telegraf,代码行数:30,代码来源:rethinkdb_data_test.go


示例8: TestAddMemberStats

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

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

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


示例9: TestMysqlGeneratesMetrics

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

	m := &Mysql{
		Servers: []string{fmt.Sprintf("[email protected](%s:3306)/", testutil.GetLocalHost())},
	}

	var acc testutil.Accumulator

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

	prefixes := []struct {
		prefix string
		count  int
	}{
		{"commands", 141},
		{"handler", 18},
		{"bytes", 2},
		{"innodb", 51},
		{"threads", 4},
		{"aborted", 2},
		{"created", 3},
		{"key", 7},
		{"open", 7},
		{"opened", 3},
		{"qcache", 8},
		{"table", 5},
	}

	intMetrics := []string{
		"queries",
		"slow_queries",
	}

	for _, prefix := range prefixes {
		var count int

		for _, p := range acc.Points {
			if strings.HasPrefix(p.Measurement, prefix.prefix) {
				count++
			}
		}

		assert.Equal(t, prefix.count, count)
	}

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


示例10: TestPostgresqlGeneratesMetrics

func TestPostgresqlGeneratesMetrics(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)

	intMetrics := []string{
		"xact_commit",
		"xact_rollback",
		"blks_read",
		"blks_hit",
		"tup_returned",
		"tup_fetched",
		"tup_inserted",
		"tup_updated",
		"tup_deleted",
		"conflicts",
		"temp_files",
		"temp_bytes",
		"deadlocks",
	}

	floatMetrics := []string{
		"blk_read_time",
		"blk_write_time",
	}

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

	for _, metric := range floatMetrics {
		assert.True(t, acc.HasFloatValue(metric))
	}
}
开发者ID:toorop,项目名称:telegraf,代码行数:49,代码来源:postgresql_test.go


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

	metrics := []struct {
		name  string
		value uint64
	}{
		{"active", 585},
		{"accepts", 85340},
		{"handled", 85340},
		{"requests", 35085},
		{"reading", 4},
		{"writing", 135},
		{"waiting", 446},
	}
	addr, err := url.Parse(ts.URL)
	if err != nil {
		panic(err)
	}
	host, _, _ := net.SplitHostPort(addr.Host)
	tags := map[string]string{"server": host}

	for _, m := range metrics {
		assert.NoError(t, acc.ValidateTaggedValue(m.name, m.value, tags))
	}
}
开发者ID:toorop,项目名称:telegraf,代码行数:46,代码来源:nginx_test.go


示例12: 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"}
	assert.NoError(t, acc.ValidateTaggedValue("packets_transmitted", 2, tags))
	assert.NoError(t, acc.ValidateTaggedValue("packets_received", 0, tags))
	assert.NoError(t, acc.ValidateTaggedValue("percent_packet_loss", 100.0, tags))
	assert.NoError(t, acc.ValidateTaggedValue("average_response_ms", 0.0, tags))
}
开发者ID:toorop,项目名称:telegraf,代码行数:16,代码来源:ping_test.go


示例13: 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"}
	assert.NoError(t, acc.ValidateTaggedValue("packets_transmitted", 5, tags))
	assert.NoError(t, acc.ValidateTaggedValue("packets_received", 3, tags))
	assert.NoError(t, acc.ValidateTaggedValue("percent_packet_loss", 40.0, tags))
	assert.NoError(t, acc.ValidateTaggedValue("average_response_ms", 44.033, tags))
}
开发者ID:toorop,项目名称:telegraf,代码行数:15,代码来源:ping_test.go


示例14: 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",
		"host":  ts.Listener.Addr().String(),
		"sv":    "host0",
	}

	assert.NoError(t, acc.ValidateTaggedValue("stot", uint64(171014), tags))
	assert.NoError(t, acc.ValidateTaggedValue("scur", uint64(1), tags))
	assert.NoError(t, acc.ValidateTaggedValue("rate", uint64(3), tags))
	assert.Equal(t, true, acc.CheckValue("bin", uint64(5557055817)))
}
开发者ID:toorop,项目名称:telegraf,代码行数:26,代码来源:haproxy_test.go


示例15: 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"}

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


示例16: TestFatalPingGather

// Test that a fatal ping command does not gather any statistics.
func TestFatalPingGather(t *testing.T) {
	var acc testutil.Accumulator
	p := Ping{
		Urls:     []string{"www.amazon.com"},
		pingHost: mockFatalHostPinger,
	}

	p.Gather(&acc)
	assert.False(t, acc.HasMeasurement("packets_transmitted"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasMeasurement("packets_received"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasMeasurement("percent_packet_loss"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasMeasurement("average_response_ms"),
		"Fatal ping should not have packet measurements")
}
开发者ID:toorop,项目名称:telegraf,代码行数:18,代码来源:ping_test.go


示例17: TestAddStorageStats

func TestAddStorageStats(t *testing.T) {
	storage := &Storage{
		Cache: Cache{
			BytesInUse: 0,
		},
		Disk: Disk{
			ReadBytesPerSec:  0,
			ReadBytesTotal:   0,
			WriteBytesPerSec: 0,
			WriteBytesTotal:  0,
			SpaceUsage: SpaceUsage{
				Data:     0,
				Garbage:  0,
				Metadata: 0,
				Prealloc: 0,
			},
		},
	}

	var acc testutil.Accumulator

	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",
	}

	storage.AddStats(&acc, tags)

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


示例18: TestElasticsearch

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

	var acc testutil.Accumulator
	if err := es.Gather(&acc); err != nil {
		t.Fatal(err)
	}

	tags := map[string]string{
		"cluster_name":          "es-testcluster",
		"node_attribute_master": "true",
		"node_id":               "SDFsfSDFsdfFSDSDfSFDSDF",
		"node_name":             "test.host.com",
		"node_host":             "test",
	}

	testTables := []map[string]float64{
		indicesExpected,
		osExpected,
		processExpected,
		jvmExpected,
		threadPoolExpected,
		networkExpected,
		fsExpected,
		transportExpected,
		httpExpected,
		breakersExpected,
	}

	for _, testTable := range testTables {
		for k, v := range testTable {
			assert.NoError(t, acc.ValidateTaggedValue(k, v, tags))
		}
	}
}
开发者ID:toorop,项目名称:telegraf,代码行数:37,代码来源:elasticsearch_test.go


示例19: TestSystemStats_GenerateStats

func TestSystemStats_GenerateStats(t *testing.T) {
	var mps MockPS

	defer mps.AssertExpectations(t)

	var acc testutil.Accumulator

	cts := cpu.CPUTimesStat{
		CPU:       "cpu0",
		User:      3.1,
		System:    8.2,
		Idle:      80.1,
		Nice:      1.3,
		Iowait:    0.2,
		Irq:       0.1,
		Softirq:   0.11,
		Steal:     0.0001,
		Guest:     8.1,
		GuestNice: 0.324,
		Stolen:    0.051,
	}

	cts2 := cpu.CPUTimesStat{
		CPU:       "cpu0",
		User:      11.4,     // increased by 8.3
		System:    10.9,     // increased by 2.7
		Idle:      158.8699, // increased by 78.7699 (for total increase of 100)
		Nice:      2.5,      // increased by 1.2
		Iowait:    0.7,      // increased by 0.5
		Irq:       1.2,      // increased by 1.1
		Softirq:   0.31,     // increased by 0.2
		Steal:     0.0002,   // increased by 0.0001
		Guest:     12.9,     // increased by 4.8
		GuestNice: 2.524,    // increased by 2.2
		Stolen:    0.281,    // increased by 0.23
	}

	mps.On("CPUTimes").Return([]cpu.CPUTimesStat{cts}, nil)

	du := &disk.DiskUsageStat{
		Path:        "/",
		Fstype:      "ext4",
		Total:       128,
		Free:        23,
		InodesTotal: 1234,
		InodesFree:  234,
	}

	mps.On("DiskUsage").Return([]*disk.DiskUsageStat{du}, nil)

	diskio := disk.DiskIOCountersStat{
		ReadCount:    888,
		WriteCount:   5341,
		ReadBytes:    100000,
		WriteBytes:   200000,
		ReadTime:     7123,
		WriteTime:    9087,
		Name:         "sda1",
		IoTime:       123552,
		SerialNumber: "ab-123-ad",
	}

	mps.On("DiskIO").Return(map[string]disk.DiskIOCountersStat{"sda1": diskio}, nil)

	netio := net.NetIOCountersStat{
		Name:        "eth0",
		BytesSent:   1123,
		BytesRecv:   8734422,
		PacketsSent: 781,
		PacketsRecv: 23456,
		Errin:       832,
		Errout:      8,
		Dropin:      7,
		Dropout:     1,
	}

	mps.On("NetIO").Return([]net.NetIOCountersStat{netio}, nil)

	vms := &mem.VirtualMemoryStat{
		Total:       12400,
		Available:   7600,
		Used:        5000,
		UsedPercent: 47.1,
		Free:        1235,
		Active:      8134,
		Inactive:    1124,
		Buffers:     771,
		Cached:      4312,
		Wired:       134,
		Shared:      2142,
	}

	mps.On("VMStat").Return(vms, nil)

	sms := &mem.SwapMemoryStat{
		Total:       8123,
		Used:        1232,
		Free:        6412,
		UsedPercent: 12.2,
		Sin:         7,
//.........这里部分代码省略.........
开发者ID:toorop,项目名称:telegraf,代码行数:101,代码来源:system_test.go


示例20: TestHaproxyGeneratesMetricsWithAuthentication

func TestHaproxyGeneratesMetricsWithAuthentication(t *testing.T) {
	//We create a fake server to return test data
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		username, password, ok := r.BasicAuth()
		if !ok {
			w.WriteHeader(http.StatusNotFound)
			fmt.Fprint(w, "Unauthorized")
			return
		}

		if username == "user" && password == "password" {
			fmt.Fprint(w, csvOutputSample)
		} else {
			w.WriteHeader(http.StatusNotFound)
			fmt.Fprint(w, "Unauthorized")
		}
	}))
	defer ts.Close()

	//Now we tested again above server, with our authentication data
	r := &haproxy{
		Servers: []string{strings.Replace(ts.URL, "http://", "http://user:[email protected]", 1)},
	}

	var acc testutil.Accumulator

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

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

	assert.NoError(t, acc.ValidateTaggedValue("stot", uint64(171014), tags))

	checkInt := []struct {
		name  string
		value uint64
	}{
		{"bin", 5557055817},
		{"scur", 288},
		{"qmax", 81},
		{"http_response.1xx", 0},
		{"http_response.2xx", 1314093},
		{"http_response.3xx", 537036},
		{"http_response.4xx", 123452},
		{"dreq", 1102},
		{"dresp", 80},
		{"wretr", 17},
		{"wredis", 19},
		{"ereq", 95740},
		{"econ", 0},
		{"eresp", 0},
		{"req_rate", 35},
		{"req_rate_max", 140},
		{"req_tot", 1987928},
		{"bin", 5557055817},
		{"bout", 24096715169},
		{"rate", 18},
		{"rate_max", 102},

		{"throttle", 13},
		{"lbtot", 114},
	}

	for _, c := range checkInt {
		assert.Equal(t, true, acc.CheckValue(c.name, c.value))
	}

	//Here, we should get error because we don't pass authentication data
	r = &haproxy{
		Servers: []string{ts.URL},
	}

	err = r.Gather(&acc)
	require.Error(t, err)
}
开发者ID:toorop,项目名称:telegraf,代码行数:79,代码来源:haproxy_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang webbrowser.Open函数代码示例发布时间:2022-05-28
下一篇:
Golang plugins.Accumulator类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap