Beispiel #1
0
func TestGather(t *testing.T) {
	var acc testutil.Accumulator
	pid := os.Getpid()
	file, err := ioutil.TempFile(os.TempDir(), "telegraf")
	require.NoError(t, err)
	file.Write([]byte(strconv.Itoa(pid)))
	file.Close()
	defer os.Remove(file.Name())
	specifications := []*Specification{&Specification{PidFile: file.Name(), Prefix: "foo"}}
	p := Procstat{
		Specifications: specifications,
	}
	p.Gather(&acc)
	assert.True(t, acc.HasFloatValue("foo_cpu_user"))
	assert.True(t, acc.HasUIntValue("foo_memory_vms"))
}
Beispiel #2
0
func TestLustre2GeneratesMetrics(t *testing.T) {

	tempdir := os.TempDir() + "/telegraf/proc/fs/lustre/"
	ost_name := "OST0001"

	mdtdir := tempdir + "/mdt/"
	err := os.MkdirAll(mdtdir+"/"+ost_name, 0755)
	require.NoError(t, err)

	osddir := tempdir + "/osd-ldiskfs/"
	err = os.MkdirAll(osddir+"/"+ost_name, 0755)
	require.NoError(t, err)

	obddir := tempdir + "/obdfilter/"
	err = os.MkdirAll(obddir+"/"+ost_name, 0755)
	require.NoError(t, err)

	err = ioutil.WriteFile(mdtdir+"/"+ost_name+"/md_stats", []byte(mdtProcContents), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(osddir+"/"+ost_name+"/stats", []byte(osdldiskfsProcContents), 0644)
	require.NoError(t, err)

	err = ioutil.WriteFile(obddir+"/"+ost_name+"/stats", []byte(obdfilterProcContents), 0644)
	require.NoError(t, err)

	m := &Lustre2{
		Ost_procfiles: []string{obddir + "/*/stats", osddir + "/*/stats"},
		Mds_procfiles: []string{mdtdir + "/*/md_stats"},
	}

	var acc testutil.Accumulator

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

	tags := map[string]string{
		"name": ost_name,
	}

	intMetrics := []*metrics{
		{
			name:  "write_bytes",
			value: 15201500833981,
		},
		{
			name:  "read_bytes",
			value: 78026117632000,
		},
		{
			name:  "write_calls",
			value: 71893382,
		},
		{
			name:  "read_calls",
			value: 203238095,
		},
		{
			name:  "cache_hit",
			value: 7393729777,
		},
		{
			name:  "cache_access",
			value: 19047063027,
		},
		{
			name:  "cache_miss",
			value: 11653333250,
		},
	}

	for _, metric := range intMetrics {
		assert.True(t, acc.HasUIntValue(metric.name), metric.name)
		assert.True(t, acc.CheckTaggedValue(metric.name, metric.value, tags))
	}

	err = os.RemoveAll(os.TempDir() + "/telegraf")
	require.NoError(t, err)
}
Beispiel #3
0
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)

	intMetrics := []*metrics{
		{
			name:  "dirty_data",
			value: 1610612736,
		},
		{
			name:  "bypassed",
			value: 5167704440832,
		},
		{
			name:  "cache_bypass_hits",
			value: 146155333,
		},
		{
			name:  "cache_bypass_misses",
			value: 0,
		},
		{
			name:  "cache_hit_ratio",
			value: 90,
		},
		{
			name:  "cache_hits",
			value: 511469583,
		},
		{
			name:  "cache_miss_collisions",
			value: 157567,
		},
		{
			name:  "cache_misses",
			value: 50616331,
		},
		{
			name:  "cache_readaheads",
			value: 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)

	for _, metric := range intMetrics {
		assert.True(t, acc.HasUIntValue(metric.name), metric.name)
		assert.True(t, acc.CheckTaggedValue(metric.name, metric.value, tags))
	}

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

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

	for _, metric := range intMetrics {
		assert.True(t, acc.HasUIntValue(metric.name), metric.name)
		assert.True(t, acc.CheckTaggedValue(metric.name, metric.value, tags))
	}

	err = os.RemoveAll(os.TempDir() + "/telegraf")
	require.NoError(t, err)
}