2015-07-07 01:20:11 +00:00
|
|
|
package mongodb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"strconv"
|
|
|
|
|
2016-01-27 21:21:36 +00:00
|
|
|
"github.com/influxdata/telegraf"
|
2015-07-07 01:20:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MongodbData struct {
|
2018-04-11 00:10:29 +00:00
|
|
|
StatLine *StatLine
|
|
|
|
Fields map[string]interface{}
|
|
|
|
Tags map[string]string
|
|
|
|
DbData []DbData
|
2019-07-31 04:36:19 +00:00
|
|
|
ColData []ColData
|
2018-04-11 00:10:29 +00:00
|
|
|
ShardHostData []DbData
|
2016-07-19 11:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DbData struct {
|
|
|
|
Name string
|
|
|
|
Fields map[string]interface{}
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 04:36:19 +00:00
|
|
|
type ColData struct {
|
|
|
|
Name string
|
|
|
|
DbName string
|
|
|
|
Fields map[string]interface{}
|
|
|
|
}
|
|
|
|
|
2015-07-07 01:20:11 +00:00
|
|
|
func NewMongodbData(statLine *StatLine, tags map[string]string) *MongodbData {
|
|
|
|
return &MongodbData{
|
|
|
|
StatLine: statLine,
|
|
|
|
Tags: tags,
|
2015-12-19 20:31:22 +00:00
|
|
|
Fields: make(map[string]interface{}),
|
2016-07-19 11:47:12 +00:00
|
|
|
DbData: []DbData{},
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var DefaultStats = map[string]string{
|
2019-12-02 19:16:00 +00:00
|
|
|
"uptime_ns": "UptimeNanos",
|
2019-01-09 23:48:45 +00:00
|
|
|
"inserts": "InsertCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"inserts_per_sec": "Insert",
|
2019-01-09 23:48:45 +00:00
|
|
|
"queries": "QueryCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"queries_per_sec": "Query",
|
2019-01-09 23:48:45 +00:00
|
|
|
"updates": "UpdateCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"updates_per_sec": "Update",
|
2019-01-09 23:48:45 +00:00
|
|
|
"deletes": "DeleteCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"deletes_per_sec": "Delete",
|
2019-01-09 23:48:45 +00:00
|
|
|
"getmores": "GetMoreCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"getmores_per_sec": "GetMore",
|
2019-01-09 23:48:45 +00:00
|
|
|
"commands": "CommandCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"commands_per_sec": "Command",
|
2019-01-09 23:48:45 +00:00
|
|
|
"flushes": "FlushesCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"flushes_per_sec": "Flushes",
|
2019-01-15 19:31:52 +00:00
|
|
|
"flushes_total_time_ns": "FlushesTotalTime",
|
2018-07-03 21:09:20 +00:00
|
|
|
"vsize_megabytes": "Virtual",
|
|
|
|
"resident_megabytes": "Resident",
|
|
|
|
"queued_reads": "QueuedReaders",
|
|
|
|
"queued_writes": "QueuedWriters",
|
|
|
|
"active_reads": "ActiveReaders",
|
|
|
|
"active_writes": "ActiveWriters",
|
2020-03-23 23:14:56 +00:00
|
|
|
"available_reads": "AvailableReaders",
|
|
|
|
"available_writes": "AvailableWriters",
|
|
|
|
"total_tickets_reads": "TotalTicketsReaders",
|
|
|
|
"total_tickets_writes": "TotalTicketsWriters",
|
2019-01-09 23:48:45 +00:00
|
|
|
"net_in_bytes_count": "NetInCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"net_in_bytes": "NetIn",
|
2019-01-09 23:48:45 +00:00
|
|
|
"net_out_bytes_count": "NetOutCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"net_out_bytes": "NetOut",
|
|
|
|
"open_connections": "NumConnections",
|
2019-01-09 23:48:45 +00:00
|
|
|
"ttl_deletes": "DeletedDocumentsCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"ttl_deletes_per_sec": "DeletedDocuments",
|
2019-01-09 23:48:45 +00:00
|
|
|
"ttl_passes": "PassesCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"ttl_passes_per_sec": "Passes",
|
|
|
|
"cursor_timed_out": "TimedOutC",
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_timed_out_count": "TimedOutCCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"cursor_no_timeout": "NoTimeoutC",
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_no_timeout_count": "NoTimeoutCCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"cursor_pinned": "PinnedC",
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_pinned_count": "PinnedCCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"cursor_total": "TotalC",
|
2019-01-09 23:48:45 +00:00
|
|
|
"cursor_total_count": "TotalCCnt",
|
2018-07-03 21:09:20 +00:00
|
|
|
"document_deleted": "DeletedD",
|
|
|
|
"document_inserted": "InsertedD",
|
|
|
|
"document_returned": "ReturnedD",
|
|
|
|
"document_updated": "UpdatedD",
|
|
|
|
"connections_current": "CurrentC",
|
|
|
|
"connections_available": "AvailableC",
|
|
|
|
"connections_total_created": "TotalCreatedC",
|
2020-05-12 18:31:54 +00:00
|
|
|
"operation_scan_and_order": "ScanAndOrderOp",
|
|
|
|
"operation_write_conflicts": "WriteConflictsOp",
|
|
|
|
"total_keys_scanned": "TotalKeysScanned",
|
|
|
|
"total_docs_scanned": "TotalObjectsScanned",
|
|
|
|
}
|
|
|
|
|
|
|
|
var DefaultAssertsStats = map[string]string{
|
|
|
|
"assert_regular": "Regular",
|
|
|
|
"assert_warning": "Warning",
|
|
|
|
"assert_msg": "Msg",
|
|
|
|
"assert_user": "User",
|
|
|
|
"assert_rollovers": "Rollovers",
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 19:33:10 +00:00
|
|
|
var DefaultCommandsStats = map[string]string{
|
2020-05-12 18:31:54 +00:00
|
|
|
"aggregate_command_total": "AggregateCommandTotal",
|
|
|
|
"aggregate_command_failed": "AggregateCommandFailed",
|
|
|
|
"count_command_total": "CountCommandTotal",
|
|
|
|
"count_command_failed": "CountCommandFailed",
|
2020-03-23 19:33:10 +00:00
|
|
|
"delete_command_total": "DeleteCommandTotal",
|
|
|
|
"delete_command_failed": "DeleteCommandFailed",
|
2020-05-12 18:31:54 +00:00
|
|
|
"distinct_command_total": "DistinctCommandTotal",
|
|
|
|
"distinct_command_failed": "DistinctCommandFailed",
|
2020-03-23 19:33:10 +00:00
|
|
|
"find_command_total": "FindCommandTotal",
|
|
|
|
"find_command_failed": "FindCommandFailed",
|
|
|
|
"find_and_modify_command_total": "FindAndModifyCommandTotal",
|
|
|
|
"find_and_modify_command_failed": "FindAndModifyCommandFailed",
|
|
|
|
"get_more_command_total": "GetMoreCommandTotal",
|
|
|
|
"get_more_command_failed": "GetMoreCommandFailed",
|
|
|
|
"insert_command_total": "InsertCommandTotal",
|
|
|
|
"insert_command_failed": "InsertCommandFailed",
|
|
|
|
"update_command_total": "UpdateCommandTotal",
|
|
|
|
"update_command_failed": "UpdateCommandFailed",
|
|
|
|
}
|
|
|
|
|
2020-01-09 02:18:12 +00:00
|
|
|
var DefaultLatencyStats = map[string]string{
|
|
|
|
"latency_writes_count": "WriteOpsCnt",
|
|
|
|
"latency_writes": "WriteLatency",
|
|
|
|
"latency_reads_count": "ReadOpsCnt",
|
|
|
|
"latency_reads": "ReadLatency",
|
|
|
|
"latency_commands_count": "CommandOpsCnt",
|
|
|
|
"latency_commands": "CommandLatency",
|
|
|
|
}
|
|
|
|
|
2015-07-07 01:20:11 +00:00
|
|
|
var DefaultReplStats = map[string]string{
|
2020-05-12 18:31:54 +00:00
|
|
|
"repl_inserts": "InsertRCnt",
|
|
|
|
"repl_inserts_per_sec": "InsertR",
|
|
|
|
"repl_queries": "QueryRCnt",
|
|
|
|
"repl_queries_per_sec": "QueryR",
|
|
|
|
"repl_updates": "UpdateRCnt",
|
|
|
|
"repl_updates_per_sec": "UpdateR",
|
|
|
|
"repl_deletes": "DeleteRCnt",
|
|
|
|
"repl_deletes_per_sec": "DeleteR",
|
|
|
|
"repl_getmores": "GetMoreRCnt",
|
|
|
|
"repl_getmores_per_sec": "GetMoreR",
|
|
|
|
"repl_commands": "CommandRCnt",
|
|
|
|
"repl_commands_per_sec": "CommandR",
|
|
|
|
"member_status": "NodeType",
|
|
|
|
"state": "NodeState",
|
2020-05-21 00:34:50 +00:00
|
|
|
"repl_state": "NodeStateInt",
|
2020-05-12 18:31:54 +00:00
|
|
|
"repl_lag": "ReplLag",
|
|
|
|
"repl_network_bytes": "ReplNetworkBytes",
|
|
|
|
"repl_network_getmores_num": "ReplNetworkGetmoresNum",
|
|
|
|
"repl_network_getmores_total_millis": "ReplNetworkGetmoresTotalMillis",
|
|
|
|
"repl_network_ops": "ReplNetworkOps",
|
|
|
|
"repl_buffer_count": "ReplBufferCount",
|
|
|
|
"repl_buffer_size_bytes": "ReplBufferSizeBytes",
|
|
|
|
"repl_apply_batches_num": "ReplApplyBatchesNum",
|
|
|
|
"repl_apply_batches_total_millis": "ReplApplyBatchesTotalMillis",
|
|
|
|
"repl_apply_ops": "ReplApplyOps",
|
|
|
|
"repl_executor_pool_in_progress_count": "ReplExecutorPoolInProgressCount",
|
|
|
|
"repl_executor_queues_network_in_progress": "ReplExecutorQueuesNetworkInProgress",
|
|
|
|
"repl_executor_queues_sleepers": "ReplExecutorQueuesSleepers",
|
|
|
|
"repl_executor_unsignaled_events": "ReplExecutorUnsignaledEvents",
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 16:40:26 +00:00
|
|
|
var DefaultClusterStats = map[string]string{
|
|
|
|
"jumbo_chunks": "JumboChunksCount",
|
|
|
|
}
|
|
|
|
|
2018-02-20 21:55:56 +00:00
|
|
|
var DefaultShardStats = map[string]string{
|
|
|
|
"total_in_use": "TotalInUse",
|
|
|
|
"total_available": "TotalAvailable",
|
|
|
|
"total_created": "TotalCreated",
|
|
|
|
"total_refreshing": "TotalRefreshing",
|
|
|
|
}
|
|
|
|
|
2018-04-11 00:10:29 +00:00
|
|
|
var ShardHostStats = map[string]string{
|
|
|
|
"in_use": "InUse",
|
|
|
|
"available": "Available",
|
|
|
|
"created": "Created",
|
|
|
|
"refreshing": "Refreshing",
|
|
|
|
}
|
|
|
|
|
2015-07-07 01:20:11 +00:00
|
|
|
var MmapStats = map[string]string{
|
|
|
|
"mapped_megabytes": "Mapped",
|
|
|
|
"non-mapped_megabytes": "NonMapped",
|
2019-01-09 23:48:45 +00:00
|
|
|
"page_faults": "FaultsCnt",
|
2015-07-07 01:20:11 +00:00
|
|
|
"page_faults_per_sec": "Faults",
|
|
|
|
}
|
|
|
|
|
|
|
|
var WiredTigerStats = map[string]string{
|
|
|
|
"percent_cache_dirty": "CacheDirtyPercent",
|
|
|
|
"percent_cache_used": "CacheUsedPercent",
|
|
|
|
}
|
|
|
|
|
2017-10-03 00:38:51 +00:00
|
|
|
var WiredTigerExtStats = map[string]string{
|
|
|
|
"wtcache_tracked_dirty_bytes": "TrackedDirtyBytes",
|
|
|
|
"wtcache_current_bytes": "CurrentCachedBytes",
|
|
|
|
"wtcache_max_bytes_configured": "MaxBytesConfigured",
|
|
|
|
"wtcache_app_threads_page_read_count": "AppThreadsPageReadCount",
|
|
|
|
"wtcache_app_threads_page_read_time": "AppThreadsPageReadTime",
|
|
|
|
"wtcache_app_threads_page_write_count": "AppThreadsPageWriteCount",
|
|
|
|
"wtcache_bytes_written_from": "BytesWrittenFrom",
|
|
|
|
"wtcache_bytes_read_into": "BytesReadInto",
|
|
|
|
"wtcache_pages_evicted_by_app_thread": "PagesEvictedByAppThread",
|
|
|
|
"wtcache_pages_queued_for_eviction": "PagesQueuedForEviction",
|
2019-01-16 23:39:55 +00:00
|
|
|
"wtcache_pages_read_into": "PagesReadIntoCache",
|
2019-01-15 19:31:52 +00:00
|
|
|
"wtcache_pages_requested_from": "PagesRequestedFromCache",
|
2017-10-03 00:38:51 +00:00
|
|
|
"wtcache_server_evicting_pages": "ServerEvictingPages",
|
|
|
|
"wtcache_worker_thread_evictingpages": "WorkerThreadEvictingPages",
|
2019-01-15 19:31:52 +00:00
|
|
|
"wtcache_internal_pages_evicted": "InternalPagesEvicted",
|
|
|
|
"wtcache_modified_pages_evicted": "ModifiedPagesEvicted",
|
|
|
|
"wtcache_unmodified_pages_evicted": "UnmodifiedPagesEvicted",
|
2017-10-03 00:38:51 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:31:54 +00:00
|
|
|
var DefaultTCMallocStats = map[string]string{
|
|
|
|
"tcmalloc_current_allocated_bytes": "TCMallocCurrentAllocatedBytes",
|
|
|
|
"tcmalloc_heap_size": "TCMallocHeapSize",
|
|
|
|
"tcmalloc_central_cache_free_bytes": "TCMallocCentralCacheFreeBytes",
|
|
|
|
"tcmalloc_current_total_thread_cache_bytes": "TCMallocCurrentTotalThreadCacheBytes",
|
|
|
|
"tcmalloc_max_total_thread_cache_bytes": "TCMallocMaxTotalThreadCacheBytes",
|
|
|
|
"tcmalloc_total_free_bytes": "TCMallocTotalFreeBytes",
|
|
|
|
"tcmalloc_transfer_cache_free_bytes": "TCMallocTransferCacheFreeBytes",
|
|
|
|
"tcmalloc_thread_cache_free_bytes": "TCMallocThreadCacheFreeBytes",
|
|
|
|
"tcmalloc_spinlock_total_delay_ns": "TCMallocSpinLockTotalDelayNanos",
|
|
|
|
"tcmalloc_pageheap_free_bytes": "TCMallocPageheapFreeBytes",
|
|
|
|
"tcmalloc_pageheap_unmapped_bytes": "TCMallocPageheapUnmappedBytes",
|
|
|
|
"tcmalloc_pageheap_committed_bytes": "TCMallocPageheapComittedBytes",
|
|
|
|
"tcmalloc_pageheap_scavenge_count": "TCMallocPageheapScavengeCount",
|
|
|
|
"tcmalloc_pageheap_commit_count": "TCMallocPageheapCommitCount",
|
|
|
|
"tcmalloc_pageheap_total_commit_bytes": "TCMallocPageheapTotalCommitBytes",
|
|
|
|
"tcmalloc_pageheap_decommit_count": "TCMallocPageheapDecommitCount",
|
|
|
|
"tcmalloc_pageheap_total_decommit_bytes": "TCMallocPageheapTotalDecommitBytes",
|
|
|
|
"tcmalloc_pageheap_reserve_count": "TCMallocPageheapReserveCount",
|
|
|
|
"tcmalloc_pageheap_total_reserve_bytes": "TCMallocPageheapTotalReserveBytes",
|
|
|
|
}
|
|
|
|
|
|
|
|
var DefaultStorageStats = map[string]string{
|
|
|
|
"storage_freelist_search_bucket_exhausted": "StorageFreelistSearchBucketExhausted",
|
|
|
|
"storage_freelist_search_requests": "StorageFreelistSearchRequests",
|
|
|
|
"storage_freelist_search_scanned": "StorageFreelistSearchScanned",
|
|
|
|
}
|
|
|
|
|
2016-07-19 11:47:12 +00:00
|
|
|
var DbDataStats = map[string]string{
|
|
|
|
"collections": "Collections",
|
|
|
|
"objects": "Objects",
|
|
|
|
"avg_obj_size": "AvgObjSize",
|
|
|
|
"data_size": "DataSize",
|
|
|
|
"storage_size": "StorageSize",
|
|
|
|
"num_extents": "NumExtents",
|
|
|
|
"indexes": "Indexes",
|
|
|
|
"index_size": "IndexSize",
|
|
|
|
"ok": "Ok",
|
|
|
|
}
|
|
|
|
|
2019-07-31 04:36:19 +00:00
|
|
|
var ColDataStats = map[string]string{
|
|
|
|
"count": "Count",
|
|
|
|
"size": "Size",
|
|
|
|
"avg_obj_size": "AvgObjSize",
|
|
|
|
"storage_size": "StorageSize",
|
|
|
|
"total_index_size": "TotalIndexSize",
|
|
|
|
"ok": "Ok",
|
|
|
|
}
|
|
|
|
|
2016-07-19 11:47:12 +00:00
|
|
|
func (d *MongodbData) AddDbStats() {
|
|
|
|
for _, dbstat := range d.StatLine.DbStatsLines {
|
|
|
|
dbStatLine := reflect.ValueOf(&dbstat).Elem()
|
|
|
|
newDbData := &DbData{
|
|
|
|
Name: dbstat.Name,
|
|
|
|
Fields: make(map[string]interface{}),
|
|
|
|
}
|
|
|
|
newDbData.Fields["type"] = "db_stat"
|
|
|
|
for key, value := range DbDataStats {
|
|
|
|
val := dbStatLine.FieldByName(value).Interface()
|
|
|
|
newDbData.Fields[key] = val
|
|
|
|
}
|
|
|
|
d.DbData = append(d.DbData, *newDbData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 04:36:19 +00:00
|
|
|
func (d *MongodbData) AddColStats() {
|
|
|
|
for _, colstat := range d.StatLine.ColStatsLines {
|
|
|
|
colStatLine := reflect.ValueOf(&colstat).Elem()
|
|
|
|
newColData := &ColData{
|
|
|
|
Name: colstat.Name,
|
|
|
|
DbName: colstat.DbName,
|
|
|
|
Fields: make(map[string]interface{}),
|
|
|
|
}
|
|
|
|
newColData.Fields["type"] = "col_stat"
|
|
|
|
for key, value := range ColDataStats {
|
|
|
|
val := colStatLine.FieldByName(value).Interface()
|
|
|
|
newColData.Fields[key] = val
|
|
|
|
}
|
|
|
|
d.ColData = append(d.ColData, *newColData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 00:10:29 +00:00
|
|
|
func (d *MongodbData) AddShardHostStats() {
|
|
|
|
for host, hostStat := range d.StatLine.ShardHostStatsLines {
|
|
|
|
hostStatLine := reflect.ValueOf(&hostStat).Elem()
|
|
|
|
newDbData := &DbData{
|
|
|
|
Name: host,
|
|
|
|
Fields: make(map[string]interface{}),
|
|
|
|
}
|
|
|
|
newDbData.Fields["type"] = "shard_host_stat"
|
|
|
|
for k, v := range ShardHostStats {
|
|
|
|
val := hostStatLine.FieldByName(v).Interface()
|
|
|
|
newDbData.Fields[k] = val
|
|
|
|
}
|
|
|
|
d.ShardHostData = append(d.ShardHostData, *newDbData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-19 20:31:22 +00:00
|
|
|
func (d *MongodbData) AddDefaultStats() {
|
2015-07-07 01:20:11 +00:00
|
|
|
statLine := reflect.ValueOf(d.StatLine).Elem()
|
2015-12-19 20:31:22 +00:00
|
|
|
d.addStat(statLine, DefaultStats)
|
2015-07-07 01:20:11 +00:00
|
|
|
if d.StatLine.NodeType != "" {
|
2015-12-19 20:31:22 +00:00
|
|
|
d.addStat(statLine, DefaultReplStats)
|
2019-12-02 19:19:14 +00:00
|
|
|
d.Tags["node_type"] = d.StatLine.NodeType
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
2019-08-27 17:31:42 +00:00
|
|
|
|
2020-01-09 02:18:12 +00:00
|
|
|
if d.StatLine.ReadLatency > 0 {
|
|
|
|
d.addStat(statLine, DefaultLatencyStats)
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:46:23 +00:00
|
|
|
if d.StatLine.ReplSetName != "" {
|
|
|
|
d.Tags["rs_name"] = d.StatLine.ReplSetName
|
|
|
|
}
|
|
|
|
|
2019-08-27 17:31:42 +00:00
|
|
|
if d.StatLine.OplogStats != nil {
|
|
|
|
d.add("repl_oplog_window_sec", d.StatLine.OplogStats.TimeDiff)
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:31:54 +00:00
|
|
|
if d.StatLine.Version != "" {
|
|
|
|
d.add("version", d.StatLine.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
d.addStat(statLine, DefaultAssertsStats)
|
2016-04-29 16:40:26 +00:00
|
|
|
d.addStat(statLine, DefaultClusterStats)
|
2020-05-12 18:31:54 +00:00
|
|
|
d.addStat(statLine, DefaultCommandsStats)
|
2018-02-20 21:55:56 +00:00
|
|
|
d.addStat(statLine, DefaultShardStats)
|
2020-05-12 18:31:54 +00:00
|
|
|
d.addStat(statLine, DefaultStorageStats)
|
|
|
|
d.addStat(statLine, DefaultTCMallocStats)
|
2020-03-23 19:33:10 +00:00
|
|
|
|
2018-03-29 20:32:05 +00:00
|
|
|
if d.StatLine.StorageEngine == "mmapv1" || d.StatLine.StorageEngine == "rocksdb" {
|
2015-12-19 20:31:22 +00:00
|
|
|
d.addStat(statLine, MmapStats)
|
2015-07-07 01:20:11 +00:00
|
|
|
} else if d.StatLine.StorageEngine == "wiredTiger" {
|
|
|
|
for key, value := range WiredTigerStats {
|
|
|
|
val := statLine.FieldByName(value).Interface()
|
|
|
|
percentVal := fmt.Sprintf("%.1f", val.(float64)*100)
|
|
|
|
floatVal, _ := strconv.ParseFloat(percentVal, 64)
|
2015-12-19 20:31:22 +00:00
|
|
|
d.add(key, floatVal)
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
2017-10-03 00:38:51 +00:00
|
|
|
d.addStat(statLine, WiredTigerExtStats)
|
2019-12-06 00:38:51 +00:00
|
|
|
d.add("page_faults", d.StatLine.FaultsCnt)
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 00:38:51 +00:00
|
|
|
func (d *MongodbData) addStat(statLine reflect.Value, stats map[string]string) {
|
2015-07-07 01:20:11 +00:00
|
|
|
for key, value := range stats {
|
|
|
|
val := statLine.FieldByName(value).Interface()
|
2015-12-19 20:31:22 +00:00
|
|
|
d.add(key, val)
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-19 20:31:22 +00:00
|
|
|
func (d *MongodbData) add(key string, val interface{}) {
|
|
|
|
d.Fields[key] = val
|
|
|
|
}
|
|
|
|
|
2016-01-27 21:21:36 +00:00
|
|
|
func (d *MongodbData) flush(acc telegraf.Accumulator) {
|
2015-10-16 22:13:32 +00:00
|
|
|
acc.AddFields(
|
2015-12-19 20:31:22 +00:00
|
|
|
"mongodb",
|
|
|
|
d.Fields,
|
2015-07-07 01:20:11 +00:00
|
|
|
d.Tags,
|
|
|
|
d.StatLine.Time,
|
|
|
|
)
|
2015-12-19 20:31:22 +00:00
|
|
|
d.Fields = make(map[string]interface{})
|
2016-07-19 11:47:12 +00:00
|
|
|
|
|
|
|
for _, db := range d.DbData {
|
|
|
|
d.Tags["db_name"] = db.Name
|
|
|
|
acc.AddFields(
|
|
|
|
"mongodb_db_stats",
|
|
|
|
db.Fields,
|
|
|
|
d.Tags,
|
|
|
|
d.StatLine.Time,
|
|
|
|
)
|
|
|
|
db.Fields = make(map[string]interface{})
|
|
|
|
}
|
2019-07-31 04:36:19 +00:00
|
|
|
for _, col := range d.ColData {
|
|
|
|
d.Tags["collection"] = col.Name
|
|
|
|
d.Tags["db_name"] = col.DbName
|
|
|
|
acc.AddFields(
|
|
|
|
"mongodb_col_stats",
|
|
|
|
col.Fields,
|
|
|
|
d.Tags,
|
|
|
|
d.StatLine.Time,
|
|
|
|
)
|
|
|
|
col.Fields = make(map[string]interface{})
|
|
|
|
}
|
2018-04-11 00:10:29 +00:00
|
|
|
for _, host := range d.ShardHostData {
|
|
|
|
d.Tags["hostname"] = host.Name
|
|
|
|
acc.AddFields(
|
|
|
|
"mongodb_shard_stats",
|
|
|
|
host.Fields,
|
|
|
|
d.Tags,
|
|
|
|
d.StatLine.Time,
|
|
|
|
)
|
|
|
|
host.Fields = make(map[string]interface{})
|
|
|
|
}
|
2015-07-07 01:20:11 +00:00
|
|
|
}
|