telegraf/plugins/inputs/mongodb/mongodb_data_test.go

138 lines
2.9 KiB
Go
Raw Normal View History

2015-07-07 01:20:11 +00:00
package mongodb
import (
"testing"
"time"
2016-01-20 18:57:35 +00:00
"github.com/influxdata/telegraf/testutil"
2015-07-07 01:20:11 +00:00
"github.com/stretchr/testify/assert"
)
var tags = make(map[string]string)
func TestAddNonReplStats(t *testing.T) {
d := NewMongodbData(
&StatLine{
2016-04-19 18:55:03 +00:00
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,
2015-07-07 01:20:11 +00:00
},
tags,
)
var acc testutil.Accumulator
d.AddDefaultStats()
d.flush(&acc)
2015-07-07 01:20:11 +00:00
for key, _ := range DefaultStats {
assert.True(t, acc.HasIntField("mongodb", key))
2015-07-07 01:20:11 +00:00
}
}
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)
2015-07-07 01:20:11 +00:00
for key, _ := range MmapStats {
assert.True(t, acc.HasIntField("mongodb", key))
2015-07-07 01:20:11 +00:00
}
}
func TestAddWiredTigerStats(t *testing.T) {
d := NewMongodbData(
&StatLine{
StorageEngine: "wiredTiger",
CacheDirtyPercent: 0,
CacheUsedPercent: 0,
},
tags,
)
var acc testutil.Accumulator
d.AddDefaultStats()
d.flush(&acc)
2015-07-07 01:20:11 +00:00
for key, _ := range WiredTigerStats {
assert.True(t, acc.HasFloatField("mongodb", key))
2015-07-07 01:20:11 +00:00
}
}
func TestStateTag(t *testing.T) {
d := NewMongodbData(
&StatLine{
StorageEngine: "",
Time: time.Now(),
Insert: 0,
Query: 0,
NodeType: "PRI",
},
tags,
)
stateTags := make(map[string]string)
stateTags["state"] = "PRI"
var acc testutil.Accumulator
d.AddDefaultStats()
d.flush(&acc)
fields := map[string]interface{}{
"active_reads": int64(0),
"active_writes": int64(0),
"commands_per_sec": int64(0),
"deletes_per_sec": int64(0),
"flushes_per_sec": int64(0),
"getmores_per_sec": int64(0),
"inserts_per_sec": int64(0),
"member_status": "PRI",
"net_in_bytes": int64(0),
"net_out_bytes": int64(0),
"open_connections": int64(0),
"queries_per_sec": int64(0),
"queued_reads": int64(0),
"queued_writes": int64(0),
"repl_commands_per_sec": int64(0),
"repl_deletes_per_sec": int64(0),
"repl_getmores_per_sec": int64(0),
"repl_inserts_per_sec": int64(0),
"repl_queries_per_sec": int64(0),
"repl_updates_per_sec": int64(0),
"resident_megabytes": int64(0),
"updates_per_sec": int64(0),
"vsize_megabytes": int64(0),
2016-04-19 18:55:03 +00:00
"ttl_deletes_per_sec": int64(0),
"ttl_passes_per_sec": int64(0),
2015-07-07 01:20:11 +00:00
}
acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags)
2015-07-07 01:20:11 +00:00
}