예제 #1
0
func TestSNMPGet2(t *testing.T) {
	get1 := Data{
		Name: "oid1",
		Oid:  "ifNumber",
	}
	h := Host{
		Address:   testutil.GetLocalHost() + ":31161",
		Community: "telegraf",
		Version:   2,
		Timeout:   2.0,
		Retries:   2,
		Collect:   []string{"oid1"},
	}
	s := Snmp{
		SnmptranslateFile: "./testdata/oids.txt",
		Host:              []Host{h},
		Get:               []Data{get1},
	}

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

	acc.AssertContainsTaggedFields(t,
		"ifNumber",
		map[string]interface{}{
			"ifNumber": int(4),
		},
		map[string]string{
			"instance": "0",
			"host":     testutil.GetLocalHost(),
		},
	)
}
예제 #2
0
func TestSNMPEasyGet6(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}
	h := Host{
		Address:   testutil.GetLocalHost() + ":31161",
		Community: "telegraf",
		Version:   2,
		Timeout:   2.0,
		Retries:   2,
		GetOids:   []string{"1.3.6.1.2.1.2.1.0"},
	}
	s := Snmp{
		SnmptranslateFile: "./testdata/oids.txt",
		Host:              []Host{h},
	}

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

	acc.AssertContainsTaggedFields(t,
		"ifNumber",
		map[string]interface{}{
			"ifNumber": int(4),
		},
		map[string]string{
			"instance": "0",
			"host":     testutil.GetLocalHost(),
		},
	)
}
예제 #3
0
func TestSNMPGet1(t *testing.T) {
	get1 := Data{
		Name: "oid1",
		Unit: "octets",
		Oid:  ".1.3.6.1.2.1.2.2.1.16.1",
	}
	h := Host{
		Address:   testutil.GetLocalHost() + ":31161",
		Community: "telegraf",
		Version:   2,
		Timeout:   2.0,
		Retries:   2,
		Collect:   []string{"oid1"},
	}
	s := Snmp{
		Host: []Host{h},
		Get:  []Data{get1},
	}

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

	acc.AssertContainsTaggedFields(t,
		"oid1",
		map[string]interface{}{
			"oid1": uint(543846),
		},
		map[string]string{
			"unit": "octets",
			"host": testutil.GetLocalHost(),
		},
	)
}
func TestReadsMetricsFromKafka(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	brokerPeers := []string{testutil.GetLocalHost() + ":9092"}
	zkPeers := []string{testutil.GetLocalHost() + ":2181"}
	testTopic := fmt.Sprintf("telegraf_test_topic_%d", time.Now().Unix())

	// Send a Kafka message to the kafka host
	msg := "cpu_load_short,direction=in,host=server01,region=us-west value=23422.0 1422568543702900257"
	producer, err := sarama.NewSyncProducer(brokerPeers, nil)
	require.NoError(t, err)
	_, _, err = producer.SendMessage(
		&sarama.ProducerMessage{
			Topic: testTopic,
			Value: sarama.StringEncoder(msg),
		})
	require.NoError(t, err)
	defer producer.Close()

	// Start the Kafka Consumer
	k := &Kafka{
		ConsumerGroup:  "telegraf_test_consumers",
		Topics:         []string{testTopic},
		ZookeeperPeers: zkPeers,
		PointBuffer:    100000,
		Offset:         "oldest",
	}
	if err := k.Start(); err != nil {
		t.Fatal(err.Error())
	} else {
		defer k.Stop()
	}

	waitForPoint(k, t)

	// Verify that we can now gather the sent message
	var acc testutil.Accumulator
	// Sanity check
	assert.Equal(t, 0, len(acc.Points), "There should not be any points")

	// Gather points
	err = k.Gather(&acc)
	require.NoError(t, err)
	if len(acc.Points) == 1 {
		point := acc.Points[0]
		assert.Equal(t, "cpu_load_short", point.Measurement)
		assert.Equal(t, map[string]interface{}{"value": 23422.0}, point.Fields)
		assert.Equal(t, map[string]string{
			"host":      "server01",
			"direction": "in",
			"region":    "us-west",
		}, point.Tags)
		assert.Equal(t, time.Unix(0, 1422568543702900257).Unix(), point.Time.Unix())
	} else {
		t.Errorf("No points found in accumulator, expected 1")
	}
}
예제 #5
0
func TestSNMPEasyGet4(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}
	get1 := Data{
		Name:     "oid1",
		Unit:     "octets",
		Oid:      "ifSpeed",
		Instance: "1",
	}
	h := Host{
		Address:   testutil.GetLocalHost() + ":31161",
		Community: "telegraf",
		Version:   2,
		Timeout:   2.0,
		Retries:   2,
		Collect:   []string{"oid1"},
		GetOids:   []string{"ifNumber"},
	}
	s := Snmp{
		SnmptranslateFile: "./testdata/oids.txt",
		Host:              []Host{h},
		Get:               []Data{get1},
	}

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

	acc.AssertContainsTaggedFields(t,
		"ifSpeed",
		map[string]interface{}{
			"ifSpeed": uint(10000000),
		},
		map[string]string{
			"unit":     "octets",
			"instance": "1",
			"host":     testutil.GetLocalHost(),
		},
	)

	acc.AssertContainsTaggedFields(t,
		"ifNumber",
		map[string]interface{}{
			"ifNumber": int(4),
		},
		map[string]string{
			"instance": "0",
			"host":     testutil.GetLocalHost(),
		},
	)
}
예제 #6
0
func TestPostgresqlDefaultsToAllDatabases(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	p := &Postgresql{
		Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
			testutil.GetLocalHost()),
	}

	var acc testutil.Accumulator

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

	var found bool

	for _, pnt := range acc.Metrics {
		if pnt.Measurement == "postgresql" {
			if pnt.Tags["db"] == "postgres" {
				found = true
				break
			}
		}
	}

	assert.True(t, found)
}
예제 #7
0
func TestPostgresqlDatabaseBlacklistTest(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	p := &Postgresql{
		Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
			testutil.GetLocalHost()),
		IgnoredDatabases: []string{"template0"},
	}

	var acc testutil.Accumulator

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

	var foundTemplate0 = false
	var foundTemplate1 = false

	for _, pnt := range acc.Metrics {
		if pnt.Measurement == "postgresql" {
			if pnt.Tags["db"] == "template0" {
				foundTemplate0 = true
			}
		}
		if pnt.Measurement == "postgresql" {
			if pnt.Tags["db"] == "template1" {
				foundTemplate1 = true
			}
		}
	}

	assert.False(t, foundTemplate0)
	assert.True(t, foundTemplate1)
}
예제 #8
0
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", "uptime", "curr_items", "total_items",
		"curr_connections", "total_connections", "connection_structures", "cmd_get",
		"cmd_set", "delete_hits", "delete_misses", "incr_hits", "incr_misses",
		"decr_hits", "decr_misses", "cas_hits", "cas_misses", "evictions",
		"bytes_read", "bytes_written", "threads", "conn_yields"}

	for _, metric := range intMetrics {
		assert.True(t, acc.HasIntField("memcached", metric), metric)
	}
}
예제 #9
0
func TestZookeeperGeneratesMetrics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	z := &Zookeeper{
		Servers: []string{testutil.GetLocalHost() + ":2181"},
	}

	var acc testutil.Accumulator

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

	intMetrics := []string{
		"avg_latency",
		"max_latency",
		"min_latency",
		"packets_received",
		"packets_sent",
		"outstanding_requests",
		"znode_count",
		"watch_count",
		"ephemerals_count",
		"approximate_data_size",
		"open_file_descriptor_count",
		"max_file_descriptor_count",
	}

	for _, metric := range intMetrics {
		assert.True(t, acc.HasIntField("zookeeper", metric), metric)
	}
}
예제 #10
0
func TestWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	o := &OpenTSDB{
		Host:   testutil.GetLocalHost(),
		Port:   4242,
		Prefix: "prefix.test.",
	}

	// Verify that we can connect to the OpenTSDB instance
	err := o.Connect()
	require.NoError(t, err)

	// Verify that we can successfully write data to OpenTSDB
	err = o.Write(testutil.MockMetrics())
	require.NoError(t, err)

	// Verify postive and negative test cases of writing data
	metrics := testutil.MockMetrics()
	metrics = append(metrics, testutil.TestMetric(float64(1.0), "justametric.float"))
	metrics = append(metrics, testutil.TestMetric(int64(123456789), "justametric.int"))
	metrics = append(metrics, testutil.TestMetric(uint64(123456789012345), "justametric.uint"))
	metrics = append(metrics, testutil.TestMetric("Lorem Ipsum", "justametric.string"))
	metrics = append(metrics, testutil.TestMetric(float64(42.0), "justametric.anotherfloat"))

	err = o.Write(metrics)
	require.NoError(t, err)

}
예제 #11
0
func TestAerospikeStatistics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	a := &Aerospike{
		Servers: []string{testutil.GetLocalHost() + ":3000"},
	}

	var acc testutil.Accumulator

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

	// Only use a few of the metrics
	asMetrics := []string{
		"transactions",
		"stat_write_errs",
		"stat_read_reqs",
		"stat_write_reqs",
	}

	for _, metric := range asMetrics {
		assert.True(t, acc.HasIntField("aerospike", metric), metric)
	}

}
예제 #12
0
func TestAerospikeStatisticsPartialErr(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping aerospike integration tests.")
	}

	a := &Aerospike{
		Servers: []string{
			testutil.GetLocalHost() + ":3000",
			testutil.GetLocalHost() + ":9999",
		},
	}

	var acc testutil.Accumulator

	err := a.Gather(&acc)
	require.Error(t, err)

	assert.True(t, acc.HasMeasurement("aerospike_node"))
	assert.True(t, acc.HasMeasurement("aerospike_namespace"))
	assert.True(t, acc.HasIntField("aerospike_node", "batch_error"))
}
예제 #13
0
func TestAerospikeStatistics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	a := &Aerospike{
		Servers: []string{testutil.GetLocalHost() + ":3000"},
	}

	var acc testutil.Accumulator

	err := a.Gather(&acc)
	require.NoError(t, err)
}
예제 #14
0
func TestMysqlDefaultsToLocal(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

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

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

	assert.True(t, acc.HasMeasurement("mysql"))
}
예제 #15
0
func TestRedisConnect(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	addr := fmt.Sprintf(testutil.GetLocalHost() + ":6379")

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

	var acc testutil.Accumulator

	err := r.Gather(&acc)
	require.NoError(t, err)
}
예제 #16
0
func TestConnectAndWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	var url = testutil.GetLocalHost() + ":1883"
	m := &MQTT{
		Servers: []string{url},
	}

	// Verify that we can connect to the MQTT broker
	err := m.Connect()
	require.NoError(t, err)

	// Verify that we can successfully write data to the mqtt broker
	err = m.Write(testutil.MockBatchPoints().Points())
	require.NoError(t, err)
}
예제 #17
0
func TestConnectAndWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	url := testutil.GetLocalHost() + ":5555"

	r := &Riemann{
		URL:       url,
		Transport: "tcp",
	}

	err := r.Connect()
	require.NoError(t, err)

	err = r.Write(testutil.MockBatchPoints().Points())
	require.NoError(t, err)
}
예제 #18
0
func TestPostgresqlIgnoresUnwantedColumns(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	p := &Postgresql{
		Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
			testutil.GetLocalHost()),
	}

	var acc testutil.Accumulator

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

	for col := range p.IgnoredColumns() {
		assert.False(t, acc.HasMeasurement(col))
	}
}
예제 #19
0
func TestConnectAndWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	server := []string{testutil.GetLocalHost() + ":4150"}
	n := &NSQ{
		Server: server[0],
		Topic:  "telegraf",
	}

	// Verify that we can connect to the NSQ daemon
	err := n.Connect()
	require.NoError(t, err)

	// Verify that we can successfully write data to the NSQ daemon
	err = n.Write(testutil.MockBatchPoints().Points())
	require.NoError(t, err)
}
예제 #20
0
func TestSNMPErrorBulk(t *testing.T) {
	bulk1 := Data{
		Name: "oid1",
		Unit: "octets",
		Oid:  ".1.3.6.1.2.1.2.2.1.16",
	}
	h := Host{
		Address: testutil.GetLocalHost(),
		Collect: []string{"oid1"},
	}
	s := Snmp{
		Host: []Host{h},
		Bulk: []Data{bulk1},
	}

	var acc testutil.Accumulator
	err := s.Gather(&acc)
	require.Error(t, err)
}
예제 #21
0
func TestConnectAndWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	var url = "amqp://" + testutil.GetLocalHost() + ":5672/"
	q := &AMQP{
		URL:      url,
		Exchange: "telegraf_test",
	}

	// Verify that we can connect to the AMQP broker
	err := q.Connect()
	require.NoError(t, err)

	// Verify that we can successfully write data to the amqp broker
	err = q.Write(testutil.MockBatchPoints().Points())
	require.NoError(t, err)
}
예제 #22
0
func TestConnectAndWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	brokers := []string{testutil.GetLocalHost() + ":9092"}
	k := &Kafka{
		Brokers: brokers,
		Topic:   "Test",
	}

	// Verify that we can connect to the Kafka broker
	err := k.Connect()
	require.NoError(t, err)

	// Verify that we can successfully write data to the kafka broker
	err = k.Write(testutil.MockBatchPoints().Points())
	require.NoError(t, err)
}
예제 #23
0
func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	p := &Postgresql{
		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("postgresql")
	require.True(t, ok)

	assert.Equal(t, "postgres", point.Tags["db"])
}
예제 #24
0
func TestConnectAndWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	server := []string{"nats://" + testutil.GetLocalHost() + ":4222"}
	s, _ := serializers.NewInfluxSerializer()
	n := &NATS{
		Servers:    server,
		Subject:    "telegraf",
		serializer: s,
	}

	// Verify that we can connect to the NATS daemon
	err := n.Connect()
	require.NoError(t, err)

	// Verify that we can successfully write data to the NATS daemon
	err = n.Write(testutil.MockMetrics())
	require.NoError(t, err)
}
예제 #25
0
func TestPostgresqlGeneratesMetrics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	p := &Postgresql{
		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)

	availableColumns := make(map[string]bool)
	for _, col := range p.OrderedColumns {
		availableColumns[col] = true
	}

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

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

	metricsCounted := 0

	for _, metric := range intMetrics {
		_, ok := availableColumns[metric]
		if ok {
			assert.True(t, acc.HasIntField("postgresql", metric))
			metricsCounted++
		}
	}

	for _, metric := range floatMetrics {
		_, ok := availableColumns[metric]
		if ok {
			assert.True(t, acc.HasFloatField("postgresql", metric))
			metricsCounted++
		}
	}

	assert.True(t, metricsCounted > 0)
	assert.Equal(t, len(availableColumns)-len(p.IgnoredColumns()), metricsCounted)
}
예제 #26
0
// TODO find why, if this test is active
// Circle CI stops with the following error...
// bash scripts/circle-test.sh died unexpectedly
// Maybe the test is too long ??
func dTestSNMPBulk2(t *testing.T) {
	bulk1 := Data{
		Name:          "oid1",
		Unit:          "octets",
		Oid:           "ifOutOctets",
		MaxRepetition: 2,
	}
	h := Host{
		Address:   testutil.GetLocalHost() + ":31161",
		Community: "telegraf",
		Version:   2,
		Timeout:   2.0,
		Retries:   2,
		Collect:   []string{"oid1"},
	}
	s := Snmp{
		SnmptranslateFile: "./testdata/oids.txt",
		Host:              []Host{h},
		Bulk:              []Data{bulk1},
	}

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

	acc.AssertContainsTaggedFields(t,
		"ifOutOctets",
		map[string]interface{}{
			"ifOutOctets": uint(543846),
		},
		map[string]string{
			"unit":     "octets",
			"instance": "1",
			"host":     testutil.GetLocalHost(),
		},
	)

	acc.AssertContainsTaggedFields(t,
		"ifOutOctets",
		map[string]interface{}{
			"ifOutOctets": uint(26475179),
		},
		map[string]string{
			"unit":     "octets",
			"instance": "2",
			"host":     testutil.GetLocalHost(),
		},
	)

	acc.AssertContainsTaggedFields(t,
		"ifOutOctets",
		map[string]interface{}{
			"ifOutOctets": uint(108963968),
		},
		map[string]string{
			"unit":     "octets",
			"instance": "3",
			"host":     testutil.GetLocalHost(),
		},
	)

	acc.AssertContainsTaggedFields(t,
		"ifOutOctets",
		map[string]interface{}{
			"ifOutOctets": uint(12991453),
		},
		map[string]string{
			"unit":     "octets",
			"instance": "36",
			"host":     testutil.GetLocalHost(),
		},
	)
}