Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for WiredTiger Engine #61

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This CHANGELOG follows the format located [here](https://github.com/sensu-plugin

## [Unreleased]

## [2.0.3] - 2018-09-14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the versioning and dating are left to the maintainers for several reasons:

  • we may disagree on the impact of the change and therefore how its versioned (in this case it would be a minor so it would be 2.1.0) per our versioning guidelines
  • we date the release rather then when the contribution was submitted, PR review and acceptance has no SLA and is not guaranteed to be merged within the same day
  • PRs are not a FIFO queue, as such versioning them prior to acceptance leads to needing to ask people to rebase more often

### New Feature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding a new feature we use the ### Added header

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to update it.

- Adds WiredTiger Matrics (@parin921996)

## [2.0.2] - 2018-03-17
### Fixed
- renamed library file `metics` to `metrics` and updated all refrences in code to it (@majormoses)
Expand Down
78 changes: 63 additions & 15 deletions lib/sensu-plugins-mongodb/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,39 @@ def replicaset_status
end
end

def foo(key,json)
json.each do |key1, value1|
if value1.is_a? Hash
Temp_hash = {}
Temp_hash = foo(key1,value1)
return_json.merge(Temp_hash)
else
return key.gsub(/(,|\s|-|\()+/, '_').tr(')', '') + key1.gsub(/(,|\s|-|\()+/, '_').tr(')', '') => value1
end
end


def wiretiger_metrics(wiredtiger, server_metrics)
TEMP_VALUE = foo('wiretiger',wiredtiger)
puts TEMP_VALUE
server_metrics.merge()
# wiredtiger.each do |key1, value1|
# next unless value1.is_a? Hash
# wiredtiger[key1].each do |key2, value2|
# if value2.is_a? Hash
# wiredtiger[key1][key2].each do |key3, value3|
# server_metrics['wiredTiger.' + key1.gsub(/(,|\s|-|\()+/, '_').tr(')', '') + '.' +
# key2.gsub(/(,|\s|-|\()+/, '_').tr(')', '') + '.' + key3.gsub(/(,|\s|-|\()+/, '_').tr(')', '')] = value3
# end
# else
# server_metrics['wiredTiger.' + key1.gsub(/(,|\s|-|\()+/, '_').tr(')', '') +
# '.' + key2.gsub(/(,|\s|-|\()+/, '_').tr(')', '')] = value2
# end
# end
# end
server_metrics
end

# Fetches metrics for the server we are connected to.
#
# @return [Mash] the metrics for the server.
Expand Down Expand Up @@ -200,9 +233,8 @@ def server_metrics

# Extra info
extra_info = server_status['extra_info']
server_metrics['mem.heap_usage_bytes'] = extra_info['heap_usage_bytes']
server_metrics['mem.pageFaults'] = extra_info['page_faults']

server_metrics['mem.heap_size_bytes'] = extra_info['heap_size']
# Global Lock
global_lock = server_status['globalLock']
server_metrics['lock.totalTime'] = global_lock['totalTime']
Expand All @@ -217,7 +249,6 @@ def server_metrics
if Gem::Version.new(mongo_version) < Gem::Version.new('3.0.0')
index_counters = server_status['indexCounters']
index_counters = server_status['indexCounters']['btree'] unless server_status['indexCounters']['btree'].nil?

server_metrics['indexes.missRatio'] = sprintf('%.5f', index_counters['missRatio']).to_s
server_metrics['indexes.hits'] = index_counters['hits']
server_metrics['indexes.misses'] = index_counters['misses']
Expand Down Expand Up @@ -255,23 +286,28 @@ def server_metrics
server_metrics['network.bytesOut'] = network['bytesOut']
server_metrics['network.numRequests'] = network['numRequests']

# OpLatencies
if server_status.key?('opLatencies')
oplatencies = server_status['opLatencies']
server_metrics['oplatencies.read.latency'] = oplatencies['reads']['latency']
server_metrics['oplatencies.read.operations'] = oplatencies['reads']['ops']
server_metrics['oplatencies.write.latency'] = oplatencies['writes']['latency']
server_metrics['oplatencies.write.operations'] = oplatencies['writes']['ops']
server_metrics['oplatencies.command.latency'] = oplatencies['commands']['latency']
server_metrics['oplatencies.command.operations'] = oplatencies['commands']['ops']
end

# Opcounters
opcounters = server_status['opcounters']
server_metrics['opcounters.insert'] = opcounters['insert']
server_metrics['opcounters.query'] = opcounters['query']
server_metrics['opcounters.update'] = opcounters['update']
server_metrics['opcounters.delete'] = opcounters['delete']
server_metrics['opcounters.getmore'] = opcounters['getmore']
server_metrics['opcounters.command'] = opcounters['command']
opcounters.each do |key, value|
server_metrics['opcounters.' + key] = value
end

# Opcounters Replication
opcounters_repl = server_status['opcountersRepl']
server_metrics['opcountersRepl.insert'] = opcounters_repl['insert']
server_metrics['opcountersRepl.query'] = opcounters_repl['query']
server_metrics['opcountersRepl.update'] = opcounters_repl['update']
server_metrics['opcountersRepl.delete'] = opcounters_repl['delete']
server_metrics['opcountersRepl.getmore'] = opcounters_repl['getmore']
server_metrics['opcountersRepl.command'] = opcounters_repl['command']
opcounters_repl.each do |key, value|
server_metrics['opcountersRepl.' + key] = value
end

# Memory
mem = server_status['mem']
Expand All @@ -280,6 +316,18 @@ def server_metrics
server_metrics['mem.mapped'] = mem['mapped']
server_metrics['mem.mappedWithJournal'] = mem['mappedWithJournal']

# Malloc
if server_status.key?('wiredTiger')
malloc = server_status['tcmalloc']
server_metrics['mem.heap_size_bytes'] = malloc['generic']['heap_size']
server_metrics['mem.current_allocated_bytes'] = malloc['generic']['current_allocated_bytes']
end
# WiredTiger specific Metrics
if server_status.key?('wiredTiger')
wiredtiger = server_status['wiredTiger']
server_metrics = wiretiger_metrics(wiredtiger, server_metrics)
end

# Metrics (documents)
document = server_status['metrics']['document']
server_metrics['metrics.document.deleted'] = document['deleted']
Expand Down
2 changes: 1 addition & 1 deletion lib/sensu-plugins-mongodb/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SensuPluginsMongoDB
module Version
MAJOR = 2
MINOR = 0
PATCH = 2
PATCH = 3

VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
end
Expand Down
Loading