0.3.0 unit tests: rabbitmq, redis
This commit is contained in:
parent
ccbd7bb785
commit
c01594c2a4
|
@ -394,11 +394,7 @@ func TestRabbitMQGeneratesMetrics(t *testing.T) {
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
r := &RabbitMQ{
|
r := &RabbitMQ{
|
||||||
Servers: []*Server{
|
|
||||||
{
|
|
||||||
URL: ts.URL,
|
URL: ts.URL,
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
@ -423,7 +419,7 @@ func TestRabbitMQGeneratesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
assert.True(t, acc.HasIntValue(metric))
|
assert.True(t, acc.HasIntField("rabbitmq_overview", metric))
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeIntMetrics := []string{
|
nodeIntMetrics := []string{
|
||||||
|
@ -441,8 +437,8 @@ func TestRabbitMQGeneratesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range nodeIntMetrics {
|
for _, metric := range nodeIntMetrics {
|
||||||
assert.True(t, acc.HasIntValue(metric))
|
assert.True(t, acc.HasIntField("rabbitmq_node", metric))
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.True(t, acc.HasMeasurement("queue"))
|
assert.True(t, acc.HasMeasurement("rabbitmq_queue"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdb/telegraf/testutil"
|
"github.com/influxdb/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,61 +35,48 @@ func TestRedis_ParseMetrics(t *testing.T) {
|
||||||
err := gatherInfoOutput(rdr, &acc, tags)
|
err := gatherInfoOutput(rdr, &acc, tags)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
checkInt := []struct {
|
fields := map[string]interface{}{
|
||||||
name string
|
"uptime": uint64(238),
|
||||||
value uint64
|
"clients": uint64(1),
|
||||||
}{
|
"used_memory": uint64(1003936),
|
||||||
{"uptime", 238},
|
"used_memory_rss": uint64(811008),
|
||||||
{"clients", 1},
|
"used_memory_peak": uint64(1003936),
|
||||||
{"used_memory", 1003936},
|
"used_memory_lua": uint64(33792),
|
||||||
{"used_memory_rss", 811008},
|
"rdb_changes_since_last_save": uint64(0),
|
||||||
{"used_memory_peak", 1003936},
|
"total_connections_received": uint64(2),
|
||||||
{"used_memory_lua", 33792},
|
"total_commands_processed": uint64(1),
|
||||||
{"rdb_changes_since_last_save", 0},
|
"instantaneous_ops_per_sec": uint64(0),
|
||||||
{"total_connections_received", 2},
|
"sync_full": uint64(0),
|
||||||
{"total_commands_processed", 1},
|
"sync_partial_ok": uint64(0),
|
||||||
{"instantaneous_ops_per_sec", 0},
|
"sync_partial_err": uint64(0),
|
||||||
{"sync_full", 0},
|
"expired_keys": uint64(0),
|
||||||
{"sync_partial_ok", 0},
|
"evicted_keys": uint64(0),
|
||||||
{"sync_partial_err", 0},
|
"keyspace_hits": uint64(1),
|
||||||
{"expired_keys", 0},
|
"keyspace_misses": uint64(1),
|
||||||
{"evicted_keys", 0},
|
"pubsub_channels": uint64(0),
|
||||||
{"keyspace_hits", 1},
|
"pubsub_patterns": uint64(0),
|
||||||
{"keyspace_misses", 1},
|
"latest_fork_usec": uint64(0),
|
||||||
{"pubsub_channels", 0},
|
"connected_slaves": uint64(0),
|
||||||
{"pubsub_patterns", 0},
|
"master_repl_offset": uint64(0),
|
||||||
{"latest_fork_usec", 0},
|
"repl_backlog_active": uint64(0),
|
||||||
{"connected_slaves", 0},
|
"repl_backlog_size": uint64(1048576),
|
||||||
{"master_repl_offset", 0},
|
"repl_backlog_histlen": uint64(0),
|
||||||
{"repl_backlog_active", 0},
|
"mem_fragmentation_ratio": float64(0.81),
|
||||||
{"repl_backlog_size", 1048576},
|
"instantaneous_input_kbps": float64(876.16),
|
||||||
{"repl_backlog_histlen", 0},
|
"instantaneous_output_kbps": float64(3010.23),
|
||||||
{"keys", 2},
|
"used_cpu_sys": float64(0.14),
|
||||||
{"expires", 0},
|
"used_cpu_user": float64(0.05),
|
||||||
{"avg_ttl", 0},
|
"used_cpu_sys_children": float64(0.00),
|
||||||
|
"used_cpu_user_children": float64(0.00),
|
||||||
|
"keyspace_hitrate": float64(0.50),
|
||||||
}
|
}
|
||||||
|
keyspaceFields := map[string]interface{}{
|
||||||
for _, c := range checkInt {
|
"avg_ttl": uint64(0),
|
||||||
assert.True(t, acc.CheckValue(c.name, c.value))
|
"expires": uint64(0),
|
||||||
}
|
"keys": uint64(2),
|
||||||
|
|
||||||
checkFloat := []struct {
|
|
||||||
name string
|
|
||||||
value float64
|
|
||||||
}{
|
|
||||||
{"mem_fragmentation_ratio", 0.81},
|
|
||||||
{"instantaneous_input_kbps", 876.16},
|
|
||||||
{"instantaneous_output_kbps", 3010.23},
|
|
||||||
{"used_cpu_sys", 0.14},
|
|
||||||
{"used_cpu_user", 0.05},
|
|
||||||
{"used_cpu_sys_children", 0.00},
|
|
||||||
{"used_cpu_user_children", 0.00},
|
|
||||||
{"keyspace_hitrate", 0.50},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range checkFloat {
|
|
||||||
assert.True(t, acc.CheckValue(c.name, c.value))
|
|
||||||
}
|
}
|
||||||
|
acc.AssertContainsTaggedFields(t, "redis", fields, tags)
|
||||||
|
acc.AssertContainsTaggedFields(t, "redis_keyspace", keyspaceFields, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
const testOutput = `# Server
|
const testOutput = `# Server
|
||||||
|
|
Loading…
Reference in New Issue