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


Golang Accumulator.CheckValue方法代码示例

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


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

示例2: 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

示例3: 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

示例4: TestRedisGeneratesMetrics

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

	l, err := net.Listen("tcp", ":0")
	require.NoError(t, err)

	defer l.Close()

	go func() {
		c, err := l.Accept()
		if err != nil {
			return
		}

		buf := bufio.NewReader(c)

		for {
			line, err := buf.ReadString('\n')
			if err != nil {
				return
			}

			if line != "info\r\n" {
				return
			}

			fmt.Fprintf(c, "$%d\n", len(testOutput))
			c.Write([]byte(testOutput))
		}
	}()

	addr := fmt.Sprintf("redis://%s", l.Addr().String())

	r := &Redis{
		Servers: []string{addr},
	}

	var acc testutil.Accumulator

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

	checkInt := []struct {
		name  string
		value uint64
	}{
		{"uptime", 238},
		{"clients", 1},
		{"used_memory", 1003936},
		{"used_memory_rss", 811008},
		{"used_memory_peak", 1003936},
		{"used_memory_lua", 33792},
		{"rdb_changes_since_last_save", 0},
		{"total_connections_received", 2},
		{"total_commands_processed", 1},
		{"instantaneous_ops_per_sec", 0},
		{"sync_full", 0},
		{"sync_partial_ok", 0},
		{"sync_partial_err", 0},
		{"expired_keys", 0},
		{"evicted_keys", 0},
		{"keyspace_hits", 0},
		{"keyspace_misses", 0},
		{"pubsub_channels", 0},
		{"pubsub_patterns", 0},
		{"latest_fork_usec", 0},
		{"connected_slaves", 0},
		{"master_repl_offset", 0},
		{"repl_backlog_active", 0},
		{"repl_backlog_size", 1048576},
		{"repl_backlog_histlen", 0},
	}

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

	checkFloat := []struct {
		name  string
		value float64
	}{
		{"mem_fragmentation_ratio", 0.81},
		{"used_cpu_sys", 0.14},
		{"used_cpu_user", 0.05},
		{"used_cpu_sys_children", 0.00},
		{"used_cpu_user_children", 0.00},
	}

	for _, c := range checkFloat {
		assert.True(t, acc.CheckValue(c.name, c.value))
	}
}
开发者ID:toorop,项目名称:telegraf,代码行数:94,代码来源:redis_test.go

示例5: TestDisqueCanPullStatsFromMultipleServers

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

	l, err := net.Listen("tcp", ":0")
	require.NoError(t, err)

	defer l.Close()

	go func() {
		c, err := l.Accept()
		if err != nil {
			return
		}

		buf := bufio.NewReader(c)

		for {
			line, err := buf.ReadString('\n')
			if err != nil {
				return
			}

			if line != "info\r\n" {
				return
			}

			fmt.Fprintf(c, "$%d\n", len(testOutput))
			c.Write([]byte(testOutput))
		}
	}()

	addr := fmt.Sprintf("disque://%s", l.Addr().String())

	r := &Disque{
		Servers: []string{addr},
	}

	var acc testutil.Accumulator

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

	checkInt := []struct {
		name  string
		value uint64
	}{
		{"uptime", 1452705},
		{"clients", 31},
		{"blocked_clients", 13},
		{"used_memory", 1840104},
		{"used_memory_rss", 3227648},
		{"used_memory_peak", 89603656},
		{"total_connections_received", 5062777},
		{"total_commands_processed", 12308396},
		{"instantaneous_ops_per_sec", 18},
		{"latest_fork_usec", 1644},
		{"registered_jobs", 360},
		{"registered_queues", 12},
	}

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

	checkFloat := []struct {
		name  string
		value float64
	}{
		{"mem_fragmentation_ratio", 1.75},
		{"used_cpu_sys", 19585.73},
		{"used_cpu_user", 11255.96},
		{"used_cpu_sys_children", 1.75},
		{"used_cpu_user_children", 1.91},
	}

	for _, c := range checkFloat {
		assert.True(t, acc.CheckValue(c.name, c.value))
	}
}
开发者ID:toorop,项目名称:telegraf,代码行数:81,代码来源:disque_test.go


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