cloudscale 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ {
2
+ "mongo":{
3
+ "menuId" : "mongo",
4
+ "label" : "Mongo DB",
5
+ "description": "Mongo DB Stats information",
6
+ "order" : 1,
7
+ "agentInstanceId" : null,
8
+ "subItems" : [
9
+ {
10
+ "menuId" : "mongo.status",
11
+ "label" : "General Stats",
12
+ "description" : "All relevant information regarding the DBstats",
13
+ "order" : 1
14
+ },{
15
+ "menuId" : "mongo.collection",
16
+ "label" : "Collection Stats",
17
+ "description" : "All relevant information regarding the DB collection",
18
+ "order" : 3
19
+ },{
20
+ "menuId" : "mongo.replica",
21
+ "label" : "Replicaset Stats",
22
+ "description" : "All relevant information regarding the DB replicastats",
23
+ "order" : 4
24
+ },{
25
+ "menuId" : "mongo.server",
26
+ "label" : "Detailed Stats",
27
+ "description" : "All relevant information regarding the DB serverstats",
28
+ "order" : 2
29
+ }
30
+ ]
31
+ }
32
+ }
@@ -0,0 +1,65 @@
1
+ require "#{File.dirname(__FILE__)}/preops/mongodb_preop"
2
+ require "#{File.dirname(__FILE__)}/../plugin"
3
+
4
+ ##
5
+ #
6
+ # @author Johannes Hiemer.
7
+ #
8
+ ##
9
+ module Cloudscale
10
+ module Plugins
11
+ class MongoDbCollectionStatus < Plugins::Plugin
12
+ attr_reader :client
13
+
14
+ def is_enabled
15
+ Preops::MongodbPreop.instance.is_enabled
16
+ end
17
+
18
+ def initialize
19
+ super
20
+ if is_enabled
21
+ @client = Preops::MongodbPreop.instance.client
22
+ end
23
+ end
24
+
25
+ def collect(agentInstanceId)
26
+ registry = Monitor::Registry.instance
27
+ metrics = Metrics::Agent.new
28
+ log.info("Calling Collect on MongoDbCollectionStatus")
29
+
30
+ @client.database.collection_names.each do | collection |
31
+ stats = @client.command({:collstats => collection}).first
32
+
33
+ registry.metrics["mongo.coll.count." + collection ] = metrics.gauge ("status_count_" + collection).to_sym do
34
+ { :value => stats['count'] }
35
+ end
36
+
37
+ registry.metrics["mongo.coll.index.nindexes." + collection] = metrics.gauge ("status_nindexes_" + collection).to_sym do
38
+ { :value => stats['nindexes'] }
39
+ end
40
+
41
+ registry.metrics["mongo.coll.index.totalIndexSize." + collection] = metrics.gauge ("status_totalIndexSize_" + collection).to_sym do
42
+ { :value => stats['totalIndexSize'] }
43
+ end
44
+
45
+ registry.metrics["mongo.coll.size.size." + collection] = metrics.gauge ("status_size_" + collection).to_sym do
46
+ { :value => stats['size'] }
47
+ end
48
+
49
+ registry.metrics["mongo.coll.size.storageSize." + collection] = metrics.gauge ("status_storageSize_" + collection).to_sym do
50
+ { :value => stats['storageSize'] }
51
+ end
52
+
53
+ registry.metrics["mongo.coll.item.avgObjSize." + collection] = metrics.gauge ("status_avgObjSize_" + collection).to_sym do
54
+ { :value => stats['avgObjSize'] }
55
+ end
56
+
57
+ registry.metrics["mongo.coll.item.lastExtentSize." + collection] = metrics.gauge ("status_lastExtentSize_" + collection).to_sym do
58
+ { :value => stats['lastExtentSize'] }
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -9,7 +9,7 @@ require "#{File.dirname(__FILE__)}/../plugin"
9
9
  module Cloudscale
10
10
  module Plugins
11
11
  class MongoDbStatus < Plugins::Plugin
12
- attr_reader :db
12
+ attr_reader :client
13
13
 
14
14
  def is_enabled
15
15
  Preops::MongodbPreop.instance.is_enabled
@@ -18,7 +18,7 @@ module Cloudscale
18
18
  def initialize
19
19
  super
20
20
  if is_enabled
21
- @db = Preops::MongodbPreop.instance.db
21
+ @client = Preops::MongodbPreop.instance.client
22
22
  end
23
23
  end
24
24
 
@@ -26,7 +26,8 @@ module Cloudscale
26
26
  registry = Monitor::Registry.instance
27
27
  metrics = Metrics::Agent.new
28
28
  log.info("Calling Collect on MongoDbStatus")
29
- stats = @db.stats
29
+
30
+ stats = @client.database.command({:dbstats => 1}).first
30
31
 
31
32
  registry.metrics["mongo.status.objects"] = metrics.gauge :status_objects do
32
33
  { :value => stats['objects'] }
@@ -9,7 +9,7 @@ require "#{File.dirname(__FILE__)}/../plugin"
9
9
  module Cloudscale
10
10
  module Plugins
11
11
  class MongoReplicaStatus < Plugins::Plugin
12
- attr_reader :db
12
+ attr_reader :client
13
13
 
14
14
  def is_enabled
15
15
  Preops::MongodbPreop.instance.is_enabled
@@ -18,17 +18,18 @@ module Cloudscale
18
18
  def initialize
19
19
  super
20
20
  if is_enabled
21
- @db = Preops::MongodbPreop.instance.db
21
+ @client = Preops::MongodbPreop.instance.client
22
22
  end
23
23
  end
24
24
 
25
- def collectHourly()
25
+ def collect(agentInstanceId)
26
26
  registry = Monitor::Registry.instance
27
27
  metrics = Metrics::Agent.new
28
28
  log.info("Calling Collect on MongoReplicaStatus")
29
- replset_status = db.command({'replSetGetStatus' => 1}, :check_response => false)
30
29
 
31
- unless replset_status['ok'] == 1
30
+ begin
31
+ replset_status = @client.command({'replSetGetStatus' => 1}).first
32
+ rescue
32
33
  return "Node isn't a member of a Replica Set","Unable to fetch Replica Set status information."
33
34
  end
34
35
 
@@ -9,7 +9,7 @@ require "#{File.dirname(__FILE__)}/../plugin"
9
9
  module Cloudscale
10
10
  module Plugins
11
11
  class MongoServerStatus < Plugins::Plugin
12
- attr_reader :db
12
+ attr_reader :client
13
13
 
14
14
  def is_enabled
15
15
  Preops::MongodbPreop.instance.is_enabled
@@ -18,24 +18,25 @@ module Cloudscale
18
18
  def initialize
19
19
  super
20
20
  if is_enabled
21
- @db = Preops::MongodbPreop.instance.db
21
+ @client = Preops::MongodbPreop.instance.client
22
22
  end
23
23
  end
24
24
 
25
- def collect()
25
+ def collect(agentInstanceId)
26
26
  registry = Monitor::Registry.instance
27
27
  metrics = Metrics::Agent.new
28
28
  log.info("Calling Collect on MongoServerStatus")
29
- report_index_counters(registry, metrics)
30
- report_global_lock_times(registry, metrics)
31
- report_op_counters(registry, metrics)
32
- report_general_information(registry, metrics)
33
- report_memory(registry, metrics)
34
- report_network(registry, metrics)
29
+ stats = @client.command(:serverStatus => 1).first
30
+ report_index_counters(registry, metrics, stats)
31
+ report_global_lock_times(registry, metrics, stats)
32
+ report_op_counters(registry, metrics, stats)
33
+ report_general_information(registry, metrics, stats)
34
+ report_memory(registry, metrics, stats)
35
+ report_network(registry, metrics, stats)
35
36
  end
36
37
 
37
- def report_memory(registry, metrics)
38
- stats = @db.command('serverStatus' => 1)
38
+ def report_memory(registry, metrics, stats)
39
+
39
40
  registry.metrics["mongo.mem.bits"] = metrics.gauge :mem_bits do
40
41
  { :value => stats['mem']['bits'] }
41
42
  end
@@ -57,24 +58,22 @@ module Cloudscale
57
58
  end
58
59
  end
59
60
 
60
- def report_network(registry, metrics)
61
- stats = @db.command('serverStatus' => 1)
61
+ def report_network(registry, metrics, stats)
62
62
 
63
- registry.metrics["mongo.network.bytes.in"] = metrics.gauge :mem_bytesIn do
64
- { :value => stats['mem']['bytesIn'] }
63
+ registry.metrics["mongo.network.bytes.in"] = metrics.gauge :network_bytesIn do
64
+ { :value => stats['network']['bytesIn'] }
65
65
  end
66
66
 
67
- registry.metrics["mongo.network.bytes.out"] = metrics.gauge :mem_bytesOut do
68
- { :value => stats['mem']['bytesOut'] }
67
+ registry.metrics["mongo.network.bytes.out"] = metrics.gauge :network_bytesOut do
68
+ { :value => stats['network']['bytesOut'] }
69
69
  end
70
70
 
71
- registry.metrics["mongo.network.num.requests"] = metrics.gauge :mem_numRequests do
72
- { :value => stats['mem']['numRequests'] }
71
+ registry.metrics["mongo.network.num.requests"] = metrics.gauge :network_numRequests do
72
+ { :value => stats['network']['numRequests'] }
73
73
  end
74
74
  end
75
75
 
76
- def report_general_information(registry, metrics)
77
- stats = @db.command('serverStatus' => 1)
76
+ def report_general_information(registry, metrics, stats)
78
77
 
79
78
  registry.metrics["mongo.general.uptime"] = metrics.gauge :general_uptime do
80
79
  { :value => stats['uptime'] }
@@ -87,10 +86,13 @@ module Cloudscale
87
86
  registry.metrics["mongo.general.connections.available"] = metrics.gauge :general_connections_available do
88
87
  { :value => stats['connections']['available'] }
89
88
  end
89
+
90
+ registry.metrics["mongo.general.connections.total"] = metrics.gauge :general_connections_total do
91
+ { :value => stats['connections']['totalCreated'] }
92
+ end
90
93
  end
91
94
 
92
- def report_op_counters(registry, metrics)
93
- stats = @db.command('serverStatus' => 1)
95
+ def report_op_counters(registry, metrics, stats)
94
96
 
95
97
  registry.metrics["mongo.opcounts.insert"] = metrics.gauge :opcounters_inserts do
96
98
  { :value => stats['opcounters']['insert'] }
@@ -113,26 +115,34 @@ module Cloudscale
113
115
  end
114
116
  end
115
117
 
116
- def report_index_counters(registry, metrics)
117
- stats = @db.command('serverStatus' => 1)
118
+ def report_index_counters(registry, metrics, stats)
119
+ {"accesses"=>6896, "hits"=>6896, "misses"=>0, "resets"=>0, "missRatio"=>0.0}
120
+
121
+ if (stats["indexCounters"])
122
+ registry.metrics["mongo.index.counters.accesses"] = metrics.gauge :counters_accesses do
123
+ { :value => stats['indexCounters']['accesses'] }
124
+ end
125
+
126
+ registry.metrics["mongo.index.counters.misses"] = metrics.gauge :counters_misses do
127
+ { :value => stats['indexCounters']['misses'] }
128
+ end
118
129
 
119
- if (stats["indexCounters"] and stats["indexCounters"]["btree"])
120
- registry.metrics["mongo.index.counters.btree.accesses"] = metrics.gauge :counters_btree_accesses do
121
- { :value => stats['indexCounters']['btree']['accesses'] }
130
+ registry.metrics["mongo.index.counters.hits"] = metrics.gauge :counters_hits do
131
+ { :value => stats['indexCounters']['hits'] }
122
132
  end
123
133
 
124
- registry.metrics["mongo.index.counters.btree.misses"] = metrics.gauge :counters_btree_misses do
125
- { :value => stats['indexCounters']['btree']['misses'] }
134
+ registry.metrics["mongo.index.counters.resets"] = metrics.gauge :counters_resets do
135
+ { :value => stats['indexCounters']['resets'] }
126
136
  end
127
137
 
128
- registry.metrics["mongo.index.counters.btree.hits"] = metrics.gauge :counters_btree_hits do
129
- { :value => stats['indexCounters']['btree']['hits'] }
138
+ registry.metrics["mongo.index.counters.missRatio"] = metrics.gauge :counters_missRatio do
139
+ { :value => stats['indexCounters']['missRatio'] }
130
140
  end
131
141
  end
132
142
  end
133
143
 
134
- def report_global_lock_times(registry, metrics)
135
- stats = @db.command('serverStatus' => 1)
144
+ def report_global_lock_times(registry, metrics, stats)
145
+
136
146
  if stats['globalLock']
137
147
  registry.metrics["mongo.global.lock.time"] = metrics.gauge :global_lock_time do
138
148
  { :value => stats['globalLock']['lockTime'] }
@@ -17,95 +17,93 @@ module Cloudscale
17
17
  class MongodbPreop < Preops::PluginPreop
18
18
  include Singleton
19
19
 
20
+ attr_accessor :options
21
+
20
22
  def is_enabled
21
23
  true
22
24
  end
23
25
 
24
- attr_accessor :db, :connection
25
- @@options = {
26
- :"mongo-host" => {
27
- :argument => "--mongo-host",
28
- :description => "Host for your MongoDB Instance (e.g. host.mongodb.com)",
29
- :required => true,
30
- :value => nil
31
- },
32
- :"mongo-port" => {
33
- :argument => "--mongo-port",
34
- :description => "Port for your MongoDB Instance (Standard 27017)",
35
- :required => false,
36
- :value => 27017
37
- },
38
- :"mongo-db" => {
39
- :argument => "--mongo-db",
40
- :description => "Database of your MongoDB instance",
41
- :required => true,
42
- :value => nil
43
- },
44
- :"mongo-ssl" => {
45
- :argument => "--mongo-ssl",
46
- :description => "Usage SSL of your MongoDB instance",
47
- :required => false,
48
- :value => false
49
- },
50
- :"mongo-username" => {
51
- :argument => "--mongo-username",
52
- :description => "Username for your MongoDB instance",
53
- :required => false,
54
- :value => nil
55
- },
56
- :"mongo-password" => {
57
- :argument => "--mongo-password",
58
- :description => "Password for your MongoDB instance",
59
- :required => false,
60
- :value => nil
61
- },
62
- :"mongo-connect-timeout" => {
63
- :argument => "--mongo-connect-timeout",
64
- :description => "Connection Timeout for your MongoDB instance",
65
- :required => false,
66
- :value => 30
67
- },
68
- :"mongo-op-timeout" => {
69
- :argument => "--mongo-timeout",
70
- :description => "Operation Timeout for your MongoDB instance",
71
- :required => false,
72
- :value => 30
73
- }
74
- }
75
-
76
- def options
77
- @@options
26
+ def register
27
+ init_charts("#{File.dirname(__FILE__)}/../data/mongo_chart.json")
28
+ init_menus("#{File.dirname(__FILE__)}/../data/mongo_menu.json")
78
29
  end
79
30
 
80
31
  def initialize
81
32
  self.init
82
- if defined? Mongo
83
- begin Mongo
84
- @connection = Mongo::Connection.new(options[:host][:value], options[:port][:value])
85
- rescue Mongo::ConnectionFailure
86
- puts "Unable to connect to the MongoDB Daemon.",
87
- "Please ensure it is running on #{@host}:#{@port}\n\nException Message: #{$!.message}. Also confirm if SSL should be enabled or disabled."
88
- end
33
+ @options = {
34
+ :'mongo-host' => {
35
+ :argument => "--mongo-host",
36
+ :description => "Host for your MongoDB Instance (e.g. host.mongodb.com)",
37
+ :required => true,
38
+ :value => nil
39
+ },
40
+ :'mongo-port' => {
41
+ :argument => "--mongo-port",
42
+ :description => "Port for your MongoDB Instance (Standard 27017)",
43
+ :required => false,
44
+ :value => 27017
45
+ },
46
+ :'mongo-db' => {
47
+ :argument => "--mongo-db",
48
+ :description => "Database of your MongoDB instance",
49
+ :required => true,
50
+ :value => nil
51
+ },
52
+ :'mongo-ssl' => {
53
+ :argument => "--mongo-ssl",
54
+ :description => "Usage SSL of your MongoDB instance",
55
+ :required => false,
56
+ :value => false
57
+ },
58
+ :'mongo-username' => {
59
+ :argument => "--mongo-username",
60
+ :description => "Username for your MongoDB instance",
61
+ :required => false,
62
+ :value => nil
63
+ },
64
+ :'mongo-password' => {
65
+ :argument => "--mongo-password",
66
+ :description => "Password for your MongoDB instance",
67
+ :required => false,
68
+ :value => nil
69
+ },
70
+ :'mongo-connect-timeout' => {
71
+ :argument => "--mongo-connect-timeout",
72
+ :description => "Connection Timeout for your MongoDB instance",
73
+ :required => false,
74
+ :value => 30
75
+ },
76
+ :'mongo-op-timeout' => {
77
+ :argument => "--mongo-timeout",
78
+ :description => "Operation Timeout for your MongoDB instance",
79
+ :required => false,
80
+ :value => 30
81
+ }
82
+ }
83
+ end
89
84
 
90
- if @connection != nil
85
+ def client
86
+ if @client == nil
87
+ if defined? Mongo
91
88
  begin
92
- @db = @connection.db(options[:db][:value])
93
- if (@username != nil)
94
- @db.authenticate(options[:username][:value], options[:password][:value])
95
- end
89
+ @client = Mongo::Client.new([@options[:'mongo-host'][:value] + ":" + @options[:'mongo-port'][:value].to_s],
90
+ :database => @options[:'mongo-db'][:value])
96
91
  rescue Exception
97
- puts "Unable to authenticate to MongoDB Database." << $!.message
92
+ puts "Unable to connect to the MongoDB Daemon. Exception: #{$!.message}. Also confirm if SSL should be enabled or disabled."
93
+ end
94
+
95
+ if @client != nil
96
+ begin
97
+ if (@options[:'mongo-username'][:value] != nil)
98
+ @client = @client.with(user: @options[:'mongo-username'][:value], password: @options[:'mongo-password'][:value])
99
+ end
100
+ rescue Exception
101
+ puts "Unable to authenticate to MongoDB Database." << $!.message
102
+ end
98
103
  end
99
104
  end
100
105
  end
101
- end
102
-
103
- def connection
104
- @connection
105
- end
106
-
107
- def db
108
- @db
106
+ @client
109
107
  end
110
108
 
111
109
  end