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


Golang Accumulator.ValidateValue方法代码示例

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


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

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

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

示例3: TestRedisGeneratesMetrics

func TestRedisGeneratesMetrics(t *testing.T) {
	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.NoError(t, acc.ValidateValue(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.NoError(t, acc.ValidateValue(c.name, c.value))
	}
}
开发者ID:kotopes,项目名称:telegraf,代码行数:90,代码来源:redis_test.go

示例4: TestSystemStats_GenerateStats


//.........这里部分代码省略.........
	assert.True(t, acc.CheckTaggedValue("inodes_used", uint64(1000), tags1))
	assert.True(t, acc.CheckTaggedValue("total", uint64(256), tags2))
	assert.True(t, acc.CheckTaggedValue("used", uint64(210), tags2))
	assert.True(t, acc.CheckTaggedValue("free", uint64(46), tags2))
	assert.True(t, acc.CheckTaggedValue("inodes_total", uint64(2468), tags2))
	assert.True(t, acc.CheckTaggedValue("inodes_free", uint64(468), tags2))
	assert.True(t, acc.CheckTaggedValue("inodes_used", uint64(2000), tags2))

	// We expect 6 more DiskPoints to show up with an explicit match on "/"
	// and /home not matching the /dev in Mountpoints
	err = (&DiskStats{ps: &mps, Mountpoints: []string{"/", "/dev"}}).Gather(&acc)
	assert.Equal(t, preDiskPoints+expectedAllDiskPoints+6, len(acc.Points))

	// We should see all the diskpoints as Mountpoints includes both
	// / and /home
	err = (&DiskStats{ps: &mps, Mountpoints: []string{"/", "/home"}}).Gather(&acc)
	assert.Equal(t, preDiskPoints+2*expectedAllDiskPoints+6, len(acc.Points))

	err = (&NetIOStats{ps: &mps, skipChecks: true}).Gather(&acc)
	require.NoError(t, err)

	ntags := map[string]string{
		"interface": "eth0",
	}

	assert.NoError(t, acc.ValidateTaggedValue("bytes_sent", uint64(1123), ntags))
	assert.NoError(t, acc.ValidateTaggedValue("bytes_recv", uint64(8734422), ntags))
	assert.NoError(t, acc.ValidateTaggedValue("packets_sent", uint64(781), ntags))
	assert.NoError(t, acc.ValidateTaggedValue("packets_recv", uint64(23456), ntags))
	assert.NoError(t, acc.ValidateTaggedValue("err_in", uint64(832), ntags))
	assert.NoError(t, acc.ValidateTaggedValue("err_out", uint64(8), ntags))
	assert.NoError(t, acc.ValidateTaggedValue("drop_in", uint64(7), ntags))
	assert.NoError(t, acc.ValidateTaggedValue("drop_out", uint64(1), ntags))
	assert.NoError(t, acc.ValidateValue("udp_noports", int64(892592)))
	assert.NoError(t, acc.ValidateValue("udp_indatagrams", int64(4655)))

	preDiskIOPoints := len(acc.Points)

	err = (&DiskIOStats{ps: &mps}).Gather(&acc)
	require.NoError(t, err)

	numDiskIOPoints := len(acc.Points) - preDiskIOPoints
	expectedAllDiskIOPoints := 14
	assert.Equal(t, expectedAllDiskIOPoints, numDiskIOPoints)

	dtags1 := map[string]string{
		"name":   "sda1",
		"serial": "ab-123-ad",
	}
	dtags2 := map[string]string{
		"name":   "sdb1",
		"serial": "bb-123-ad",
	}

	assert.True(t, acc.CheckTaggedValue("reads", uint64(888), dtags1))
	assert.True(t, acc.CheckTaggedValue("writes", uint64(5341), dtags1))
	assert.True(t, acc.CheckTaggedValue("read_bytes", uint64(100000), dtags1))
	assert.True(t, acc.CheckTaggedValue("write_bytes", uint64(200000), dtags1))
	assert.True(t, acc.CheckTaggedValue("read_time", uint64(7123), dtags1))
	assert.True(t, acc.CheckTaggedValue("write_time", uint64(9087), dtags1))
	assert.True(t, acc.CheckTaggedValue("io_time", uint64(123552), dtags1))
	assert.True(t, acc.CheckTaggedValue("reads", uint64(444), dtags2))
	assert.True(t, acc.CheckTaggedValue("writes", uint64(2341), dtags2))
	assert.True(t, acc.CheckTaggedValue("read_bytes", uint64(200000), dtags2))
	assert.True(t, acc.CheckTaggedValue("write_bytes", uint64(400000), dtags2))
	assert.True(t, acc.CheckTaggedValue("read_time", uint64(3123), dtags2))
开发者ID:timjwright,项目名称:telegraf,代码行数:67,代码来源:system_test.go


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