2015-07-07 01:20:11 +00:00
|
|
|
package mongodb
|
|
|
|
|
|
|
|
import (
|
2018-04-11 00:24:40 +00:00
|
|
|
"sort"
|
2015-07-07 01:20:11 +00:00
|
|
|
"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(),
|
2019-12-02 19:16:00 +00:00
|
|
|
UptimeNanos: 0,
|
2016-04-19 18:55:03 +00:00
|
|
|
Insert: 0,
|
|
|
|
Query: 0,
|
|
|
|
Update: 0,
|
2019-01-09 23:48:45 +00:00
|
|
|
UpdateCnt: 0,
|
2016-04-19 18:55:03 +00:00
|
|
|
Delete: 0,
|
|
|
|
GetMore: 0,
|
|
|
|
Command: 0,
|
|
|
|
Flushes: 0,
|
2019-01-09 23:48:45 +00:00
|
|
|
FlushesCnt: 0,
|
2016-04-19 18:55:03 +00:00
|
|
|
Virtual: 0,
|
|
|
|
Resident: 0,
|
|
|
|
QueuedReaders: 0,
|
|
|
|
QueuedWriters: 0,
|
|
|
|
ActiveReaders: 0,
|
|
|
|
ActiveWriters: 0,
|
|
|
|
NetIn: 0,
|
|
|
|
NetOut: 0,
|
|
|
|
NumConnections: 0,
|
|
|
|
Passes: 0,
|
|
|
|
DeletedDocuments: 0,
|
2018-05-07 22:00:24 +00:00
|
|
|
TimedOutC: 0,
|
|
|
|
NoTimeoutC: 0,
|
|
|
|
PinnedC: 0,
|
|
|
|
TotalC: 0,
|
2018-07-03 21:09:20 +00:00
|
|
|
DeletedD: 0,
|
|
|
|
InsertedD: 0,
|
|
|
|
ReturnedD: 0,
|
|
|
|
UpdatedD: 0,
|
|
|
|
CurrentC: 0,
|
|
|
|
AvailableC: 0,
|
|
|
|
TotalCreatedC: 0,
|
2015-07-07 01:20:11 +00:00
|
|
|
},
|
|
|
|
tags,
|
|
|
|
)
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
2016-01-07 00:19:39 +00:00
|
|
|
d.AddDefaultStats()
|
|
|
|
d.flush(&acc)
|
2015-07-07 01:20:11 +00:00
|
|
|
|
2018-10-19 20:32:54 +00:00
|
|
|
for key := range DefaultStats {
|
2019-01-15 19:31:52 +00:00
|
|
|
assert.True(t, acc.HasFloatField("mongodb", key) || acc.HasInt64Field("mongodb", key), 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
|
|
|
|
|
2016-01-07 00:19:39 +00:00
|
|
|
d.AddDefaultStats()
|
|
|
|
d.flush(&acc)
|
2015-07-07 01:20:11 +00:00
|
|
|
|
2018-10-19 20:32:54 +00:00
|
|
|
for key := range MmapStats {
|
2019-01-15 19:31:52 +00:00
|
|
|
assert.True(t, acc.HasInt64Field("mongodb", key), key)
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddWiredTigerStats(t *testing.T) {
|
|
|
|
d := NewMongodbData(
|
|
|
|
&StatLine{
|
2017-10-03 00:38:51 +00:00
|
|
|
StorageEngine: "wiredTiger",
|
|
|
|
CacheDirtyPercent: 0,
|
|
|
|
CacheUsedPercent: 0,
|
|
|
|
TrackedDirtyBytes: 0,
|
|
|
|
CurrentCachedBytes: 0,
|
|
|
|
MaxBytesConfigured: 0,
|
|
|
|
AppThreadsPageReadCount: 0,
|
|
|
|
AppThreadsPageReadTime: 0,
|
|
|
|
AppThreadsPageWriteCount: 0,
|
|
|
|
BytesWrittenFrom: 0,
|
|
|
|
BytesReadInto: 0,
|
|
|
|
PagesEvictedByAppThread: 0,
|
|
|
|
PagesQueuedForEviction: 0,
|
|
|
|
ServerEvictingPages: 0,
|
|
|
|
WorkerThreadEvictingPages: 0,
|
2019-12-06 00:38:51 +00:00
|
|
|
FaultsCnt: 204,
|
2015-07-07 01:20:11 +00:00
|
|
|
},
|
|
|
|
tags,
|
|
|
|
)
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
2016-01-07 00:19:39 +00:00
|
|
|
d.AddDefaultStats()
|
|
|
|
d.flush(&acc)
|
2015-07-07 01:20:11 +00:00
|
|
|
|
2018-10-19 20:32:54 +00:00
|
|
|
for key := range WiredTigerStats {
|
2019-01-15 19:31:52 +00:00
|
|
|
assert.True(t, acc.HasFloatField("mongodb", key), key)
|
|
|
|
}
|
|
|
|
|
|
|
|
for key := range WiredTigerExtStats {
|
|
|
|
assert.True(t, acc.HasFloatField("mongodb", key) || acc.HasInt64Field("mongodb", key), key)
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
2019-12-06 00:38:51 +00:00
|
|
|
|
|
|
|
assert.True(t, acc.HasInt64Field("mongodb", "page_faults"))
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 21:55:56 +00:00
|
|
|
func TestAddShardStats(t *testing.T) {
|
|
|
|
d := NewMongodbData(
|
|
|
|
&StatLine{
|
|
|
|
TotalInUse: 0,
|
|
|
|
TotalAvailable: 0,
|
|
|
|
TotalCreated: 0,
|
|
|
|
TotalRefreshing: 0,
|
|
|
|
},
|
|
|
|
tags,
|
|
|
|
)
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
d.AddDefaultStats()
|
|
|
|
d.flush(&acc)
|
|
|
|
|
2018-10-19 20:32:54 +00:00
|
|
|
for key := range DefaultShardStats {
|
2018-02-20 21:55:56 +00:00
|
|
|
assert.True(t, acc.HasInt64Field("mongodb", key))
|
2020-01-09 02:18:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddLatencyStats(t *testing.T) {
|
|
|
|
d := NewMongodbData(
|
|
|
|
&StatLine{
|
|
|
|
CommandOpsCnt: 73,
|
|
|
|
CommandLatency: 364,
|
|
|
|
ReadOpsCnt: 113,
|
|
|
|
ReadLatency: 201,
|
|
|
|
WriteOpsCnt: 7,
|
|
|
|
WriteLatency: 55,
|
|
|
|
},
|
|
|
|
tags,
|
|
|
|
)
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
d.AddDefaultStats()
|
|
|
|
d.flush(&acc)
|
|
|
|
|
|
|
|
for key := range DefaultLatencyStats {
|
|
|
|
assert.True(t, acc.HasInt64Field("mongodb", key))
|
2018-02-20 21:55:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 00:10:29 +00:00
|
|
|
func TestAddShardHostStats(t *testing.T) {
|
|
|
|
expectedHosts := []string{"hostA", "hostB"}
|
|
|
|
hostStatLines := map[string]ShardHostStatLine{}
|
|
|
|
for _, host := range expectedHosts {
|
|
|
|
hostStatLines[host] = ShardHostStatLine{
|
|
|
|
InUse: 0,
|
|
|
|
Available: 0,
|
|
|
|
Created: 0,
|
|
|
|
Refreshing: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d := NewMongodbData(
|
|
|
|
&StatLine{
|
|
|
|
ShardHostStatsLines: hostStatLines,
|
|
|
|
},
|
|
|
|
map[string]string{}, // Use empty tags, so we don't break existing tests
|
|
|
|
)
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
d.AddShardHostStats()
|
|
|
|
d.flush(&acc)
|
|
|
|
|
|
|
|
var hostsFound []string
|
2018-10-19 20:32:54 +00:00
|
|
|
for host := range hostStatLines {
|
|
|
|
for key := range ShardHostStats {
|
2018-04-11 00:10:29 +00:00
|
|
|
assert.True(t, acc.HasInt64Field("mongodb_shard_stats", key))
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, acc.HasTag("mongodb_shard_stats", "hostname"))
|
|
|
|
hostsFound = append(hostsFound, host)
|
|
|
|
}
|
2018-04-11 00:24:40 +00:00
|
|
|
sort.Strings(hostsFound)
|
|
|
|
sort.Strings(expectedHosts)
|
2018-04-11 00:10:29 +00:00
|
|
|
assert.Equal(t, hostsFound, expectedHosts)
|
|
|
|
}
|
|
|
|
|
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",
|
2016-12-16 13:46:32 +00:00
|
|
|
NodeState: "PRIMARY",
|
2015-07-07 01:20:11 +00:00
|
|
|
},
|
|
|
|
tags,
|
|
|
|
)
|
|
|
|
|
|
|
|
stateTags := make(map[string]string)
|
2019-12-02 19:19:14 +00:00
|
|
|
stateTags["node_type"] = "PRI"
|
2015-07-07 01:20:11 +00:00
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
2016-01-07 00:19:39 +00:00
|
|
|
d.AddDefaultStats()
|
|
|
|
d.flush(&acc)
|
|
|
|
fields := map[string]interface{}{
|
2018-07-03 21:09:20 +00:00
|
|
|
"active_reads": int64(0),
|
|
|
|
"active_writes": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"commands": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"commands_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"deletes": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"deletes_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"flushes": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"flushes_per_sec": int64(0),
|
2019-01-15 19:31:52 +00:00
|
|
|
"flushes_total_time_ns": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"getmores": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"getmores_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"inserts": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"inserts_per_sec": int64(0),
|
|
|
|
"member_status": "PRI",
|
|
|
|
"state": "PRIMARY",
|
2019-01-09 23:48:45 +00:00
|
|
|
"net_in_bytes_count": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"net_in_bytes": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"net_out_bytes_count": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"net_out_bytes": int64(0),
|
|
|
|
"open_connections": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"queries": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"queries_per_sec": int64(0),
|
|
|
|
"queued_reads": int64(0),
|
|
|
|
"queued_writes": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"repl_commands": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"repl_commands_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"repl_deletes": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"repl_deletes_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"repl_getmores": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"repl_getmores_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"repl_inserts": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"repl_inserts_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"repl_queries": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"repl_queries_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"repl_updates": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"repl_updates_per_sec": int64(0),
|
|
|
|
"repl_lag": int64(0),
|
|
|
|
"resident_megabytes": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"updates": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"updates_per_sec": int64(0),
|
2019-12-02 19:16:00 +00:00
|
|
|
"uptime_ns": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"vsize_megabytes": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"ttl_deletes": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"ttl_deletes_per_sec": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"ttl_passes": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"ttl_passes_per_sec": int64(0),
|
|
|
|
"jumbo_chunks": int64(0),
|
|
|
|
"total_in_use": int64(0),
|
|
|
|
"total_available": int64(0),
|
|
|
|
"total_created": int64(0),
|
|
|
|
"total_refreshing": int64(0),
|
|
|
|
"cursor_timed_out": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_timed_out_count": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"cursor_no_timeout": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_no_timeout_count": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"cursor_pinned": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_pinned_count": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"cursor_total": int64(0),
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_total_count": int64(0),
|
2018-07-03 21:09:20 +00:00
|
|
|
"document_deleted": int64(0),
|
|
|
|
"document_inserted": int64(0),
|
|
|
|
"document_returned": int64(0),
|
|
|
|
"document_updated": int64(0),
|
|
|
|
"connections_current": int64(0),
|
|
|
|
"connections_available": int64(0),
|
|
|
|
"connections_total_created": int64(0),
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
2016-01-07 00:19:39 +00:00
|
|
|
acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags)
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|