コード例 #1
0
ファイル: snmp_test.go プロジェクト: zooplus/telegraf
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
ファイル: snmp_test.go プロジェクト: cwegener/telegraf
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
ファイル: snmp_test.go プロジェクト: zooplus/telegraf
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(),
		},
	)
}
コード例 #4
0
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
ファイル: snmp_test.go プロジェクト: cwegener/telegraf
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
ファイル: postgresql_test.go プロジェクト: zooplus/telegraf
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
ファイル: postgresql_test.go プロジェクト: jeichorn/telegraf
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
ファイル: memcached_test.go プロジェクト: jeichorn/telegraf
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
ファイル: opentsdb_test.go プロジェクト: zooplus/telegraf
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
ファイル: aerospike_test.go プロジェクト: lizaoreo/telegraf
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
ファイル: aerospike_test.go プロジェクト: allen13/telegraf
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
ファイル: mysql_test.go プロジェクト: Wikia/telegraf
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
ファイル: redis_test.go プロジェクト: jeichorn/telegraf
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
ファイル: mqtt_test.go プロジェクト: bahadrix/telegraf
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
ファイル: riemann_test.go プロジェクト: bahadrix/telegraf
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
ファイル: postgresql_test.go プロジェクト: zooplus/telegraf
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
ファイル: nsq_test.go プロジェクト: bahadrix/telegraf
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
ファイル: snmp_test.go プロジェクト: cwegener/telegraf
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
ファイル: amqp_test.go プロジェクト: bahadrix/telegraf
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
ファイル: kafka_test.go プロジェクト: bahadrix/telegraf
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
ファイル: postgresql_test.go プロジェクト: zooplus/telegraf
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
ファイル: nats_test.go プロジェクト: jeichorn/telegraf
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
ファイル: postgresql_test.go プロジェクト: zooplus/telegraf
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
ファイル: snmp_test.go プロジェクト: cwegener/telegraf
// 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(),
		},
	)
}