Пример #1
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)
	}
}
Пример #2
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)
	}
}
Пример #3
0
func TestAddNonReplStats(t *testing.T) {
	d := NewMongodbData(
		&StatLine{
			StorageEngine:    "",
			Time:             time.Now(),
			Insert:           0,
			Query:            0,
			Update:           0,
			Delete:           0,
			GetMore:          0,
			Command:          0,
			Flushes:          0,
			Virtual:          0,
			Resident:         0,
			QueuedReaders:    0,
			QueuedWriters:    0,
			ActiveReaders:    0,
			ActiveWriters:    0,
			NetIn:            0,
			NetOut:           0,
			NumConnections:   0,
			Passes:           0,
			DeletedDocuments: 0,
		},
		tags,
	)
	var acc testutil.Accumulator

	d.AddDefaultStats()
	d.flush(&acc)

	for key, _ := range DefaultStats {
		assert.True(t, acc.HasIntField("mongodb", key))
	}
}
Пример #4
0
// Test that a fatal ping command does not gather any statistics.
func TestFatalPingGather(t *testing.T) {
	var acc testutil.Accumulator
	p := Ping{
		Urls:     []string{"www.amazon.com"},
		pingHost: mockFatalHostPinger,
	}

	p.Gather(&acc)
	assert.True(t, acc.HasFloatField("ping", "errors"),
		"Fatal ping should have packet measurements")
	assert.False(t, acc.HasIntField("ping", "packets_transmitted"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasIntField("ping", "packets_received"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasFloatField("ping", "percent_packet_loss"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasFloatField("ping", "percent_reply_loss"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasIntField("ping", "average_response_ms"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasIntField("ping", "maximum_response_ms"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasIntField("ping", "minimum_response_ms"),
		"Fatal ping should not have packet measurements")
}
Пример #5
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)
	}

}
Пример #6
0
func TestAddEngineStatsPartial(t *testing.T) {
	engine := &Engine{
		ClientConns:   0,
		ClientActive:  0,
		QueriesPerSec: 0,
		ReadsPerSec:   0,
		WritesPerSec:  0,
	}

	var acc testutil.Accumulator

	keys := []string{
		"active_clients",
		"clients",
		"queries_per_sec",
		"read_docs_per_sec",
		"written_docs_per_sec",
	}

	missing_keys := []string{
		"total_queries",
		"total_reads",
		"total_writes",
	}
	engine.AddEngineStats(keys, &acc, tags)

	for _, metric := range missing_keys {
		assert.False(t, acc.HasIntField("rethinkdb", metric))
	}
}
Пример #7
0
func TestAerospikeStatistics(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping aerospike integration tests.")
	}

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

	var acc testutil.Accumulator

	err := a.Gather(&acc)
	require.NoError(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"))
}
Пример #8
0
func TestAddReplStats(t *testing.T) {
	d := NewMongodbData(
		&StatLine{
			StorageEngine: "mmapv1",
			Mapped:        0,
			NonMapped:     0,
			Faults:        0,
		},
		tags,
	)

	var acc testutil.Accumulator

	d.AddDefaultStats()
	d.flush(&acc)

	for key, _ := range MmapStats {
		assert.True(t, acc.HasIntField("mongodb", key))
	}
}
Пример #9
0
// in case 'Destination net unreachable' ping app return receive packet which is not what we need
// it's not contain valid metric so treat it as lost one
func TestTTLExpiredPingGather(t *testing.T) {
	var acc testutil.Accumulator
	p := Ping{
		Urls:     []string{"www.google.com"},
		pingHost: mockTTLExpiredPinger,
	}

	p.Gather(&acc)

	tags := map[string]string{"url": "www.google.com"}
	fields := map[string]interface{}{
		"packets_transmitted": 4,
		"packets_received":    1,
		"reply_received":      0,
		"percent_packet_loss": 75.0,
		"percent_reply_loss":  100.0,
	}
	acc.AssertContainsTaggedFields(t, "ping", fields, tags)

	assert.False(t, acc.HasFloatField("ping", "errors"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasIntField("ping", "average_response_ms"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasIntField("ping", "maximum_response_ms"),
		"Fatal ping should not have packet measurements")
	assert.False(t, acc.HasIntField("ping", "minimum_response_ms"),
		"Fatal ping should not have packet measurements")
}
Пример #10
0
func TestAddStorageStats(t *testing.T) {
	storage := &Storage{
		Cache: Cache{
			BytesInUse: 0,
		},
		Disk: Disk{
			ReadBytesPerSec:  0,
			ReadBytesTotal:   0,
			WriteBytesPerSec: 0,
			WriteBytesTotal:  0,
			SpaceUsage: SpaceUsage{
				Data:     0,
				Garbage:  0,
				Metadata: 0,
				Prealloc: 0,
			},
		},
	}

	var acc testutil.Accumulator

	keys := []string{
		"cache_bytes_in_use",
		"disk_read_bytes_per_sec",
		"disk_read_bytes_total",
		"disk_written_bytes_per_sec",
		"disk_written_bytes_total",
		"disk_usage_data_bytes",
		"disk_usage_garbage_bytes",
		"disk_usage_metadata_bytes",
		"disk_usage_preallocated_bytes",
	}

	storage.AddStats(&acc, tags)

	for _, metric := range keys {
		assert.True(t, acc.HasIntField("rethinkdb", metric))
	}
}
Пример #11
0
func TestMemcachedGeneratesMetrics(t *testing.T) {
	// We create a fake server to return test data
	var randomNumber int64
	binary.Read(rand.Reader, binary.LittleEndian, &randomNumber)
	socket, err := net.Listen("unix", fmt.Sprintf("/tmp/pdns%d.controlsocket", randomNumber))
	if err != nil {
		t.Fatal("Cannot initalize server on port ")
	}

	defer socket.Close()

	s := statServer{}
	go s.serverSocket(socket)

	p := &Powerdns{
		UnixSockets: []string{fmt.Sprintf("/tmp/pdns%d.controlsocket", randomNumber)},
	}

	var acc testutil.Accumulator

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

	intMetrics := []string{"corrupt-packets", "deferred-cache-inserts",
		"deferred-cache-lookup", "dnsupdate-answers", "dnsupdate-changes",
		"dnsupdate-queries", "dnsupdate-refused", "packetcache-hit",
		"packetcache-miss", "packetcache-size", "query-cache-hit", "query-cache-miss",
		"rd-queries", "recursing-answers", "recursing-questions",
		"recursion-unanswered", "security-status", "servfail-packets", "signatures",
		"tcp-answers", "tcp-queries", "timedout-packets", "udp-answers",
		"udp-answers-bytes", "udp-do-queries", "udp-queries", "udp4-answers",
		"udp4-queries", "udp6-answers", "udp6-queries", "key-cache-size", "latency",
		"meta-cache-size", "qsize-q", "signature-cache-size", "sys-msec", "uptime", "user-msec"}

	for _, metric := range intMetrics {
		assert.True(t, acc.HasIntField("powerdns", metric), metric)
	}
}
Пример #12
0
func TestProcesses(t *testing.T) {
	processes := &Processes{
		execPS:       execPS,
		readProcFile: readProcFile,
	}
	var acc testutil.Accumulator

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

	assert.True(t, acc.HasIntField("processes", "running"))
	assert.True(t, acc.HasIntField("processes", "sleeping"))
	assert.True(t, acc.HasIntField("processes", "stopped"))
	assert.True(t, acc.HasIntField("processes", "total"))
	total, ok := acc.Get("processes")
	require.True(t, ok)
	assert.True(t, total.Fields["total"].(int64) > 0)
}
Пример #13
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)
}
Пример #14
0
func TestRabbitMQGeneratesMetrics(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		var rsp string

		switch r.URL.Path {
		case "/api/overview":
			rsp = sampleOverviewResponse
		case "/api/nodes":
			rsp = sampleNodesResponse
		case "/api/queues":
			rsp = sampleQueuesResponse
		default:
			panic("Cannot handle request")
		}

		fmt.Fprintln(w, rsp)
	}))
	defer ts.Close()

	r := &RabbitMQ{
		URL: ts.URL,
	}

	var acc testutil.Accumulator

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

	intMetrics := []string{
		"messages",
		"messages_ready",
		"messages_unacked",

		"messages_acked",
		"messages_delivered",
		"messages_published",

		"channels",
		"connections",
		"consumers",
		"exchanges",
		"queues",
	}

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

	nodeIntMetrics := []string{
		"disk_free",
		"disk_free_limit",
		"fd_total",
		"fd_used",
		"mem_limit",
		"mem_used",
		"proc_total",
		"proc_used",
		"run_queue",
		"sockets_total",
		"sockets_used",
	}

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

	assert.True(t, acc.HasMeasurement("rabbitmq_queue"))
}