easymon 1.4.2 → 1.6.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54cb530caec2412771ed64ef0e61841aa44e7794b2556b5549dca177b6118bfa
4
- data.tar.gz: efd43b670a69577f16fd9a8ef83eb2748989c2a0992d07e5490d12290fdbd9e4
3
+ metadata.gz: cb55744be4fa12e4c7af34ae59091721967aaf08d1bd07e4bc0cca4bd2937c4a
4
+ data.tar.gz: ed1822f256bea98b6982f634487c676fad7e292ca093c10315ce72990ffb6778
5
5
  SHA512:
6
- metadata.gz: b79e1a2b8c43fd58ae493a7bfaf780ba6ab5948237454ee0ab86db14e1c2bb8988617f8cf68d11164c2bf94bef7373be1a77be803a0de47cb0b7e3ad33fe74bb
7
- data.tar.gz: 6190f08e784393b88c4d544b7385c66c3f25875ba35b0791f4abcd87b9481e2075bf8deddfef78b7b34db43687d11725cf753e556e16995bd42ab768fd72bfb2
6
+ metadata.gz: bd39994e506c00177688ae9ecb7ff660326cc44eec4374cdeb42873c3128bec45da18dfb54969b9a6494fb0d79ef1d87be4d223c4ef162a70bfc5d4db4345e9a
7
+ data.tar.gz: a6515ddbd1f7a0bce037815d8804c2c7689dfc943c1ad9c7f037d711ff41700efcc6367e261b2bd3a80b43590e30ef2523ec2bd639537aac7eada9fa5f000bbd
data/README.md CHANGED
@@ -203,7 +203,7 @@ module Easymon
203
203
  end
204
204
  end
205
205
  def database_configuration
206
- env = "#{Rails.env}_slave"
206
+ env = "#{Rails.env}_replica"
207
207
  config = YAML.load_file(Rails.root.join('config/database.yml'))[env]
208
208
  end
209
209
  end
@@ -0,0 +1,26 @@
1
+ module Easymon
2
+ class ActiveRecordMysqlWriteableCheck
3
+ attr_accessor :klass
4
+
5
+ def initialize(klass)
6
+ self.klass = klass
7
+ end
8
+
9
+ def check
10
+ check_status = database_writeable?
11
+ if check_status
12
+ message = "@@read_only is 0"
13
+ else
14
+ message = "@@read_only is 1"
15
+ end
16
+ [check_status, message]
17
+ end
18
+
19
+ private
20
+ def database_writeable?
21
+ klass.connection.execute("SELECT @@read_only").entries.flatten.first == 0
22
+ rescue
23
+ false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ require "redis"
2
+
3
+ module Easymon
4
+ class RedisWriteableCheck
5
+ attr_accessor :config
6
+
7
+ def initialize(config)
8
+ self.config = config
9
+ end
10
+
11
+ def check
12
+ check_status = redis_writeable?
13
+ message = check_status ? "Writeable" : "Read Only"
14
+
15
+ [check_status, message]
16
+ end
17
+
18
+ private
19
+ def redis_writeable?
20
+ redis = Redis.new(@config)
21
+ key = "easymon_#{Time.now.to_i}"
22
+ reply = redis.set(key, "true")
23
+ redis.del(key)
24
+
25
+ reply == "OK"
26
+ rescue
27
+ false
28
+ ensure
29
+ if redis.respond_to? :close
30
+ redis.close # Redis 4+
31
+ else
32
+ redis.client.disconnect # Older redis
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,10 +2,10 @@ module Easymon
2
2
  class SplitActiveRecordCheck
3
3
  attr_accessor :block
4
4
  attr_accessor :results
5
-
5
+
6
6
  # Here we pass a block so we get a fresh instance of ActiveRecord::Base or
7
7
  # whatever other class we might be using to make database connections
8
- #
8
+ #
9
9
  # For example, given the following other class:
10
10
  # module Easymon
11
11
  # class Base < ActiveRecord::Base
@@ -18,12 +18,12 @@ module Easymon
18
18
  # end
19
19
  #
20
20
  # def database_configuration
21
- # env = "#{Rails.env}_slave"
21
+ # env = "#{Rails.env}_replica"
22
22
  # config = YAML.load_file(Rails.root.join('config/database.yml'))[env]
23
23
  # end
24
24
  # end
25
25
  # end
26
- #
26
+ #
27
27
  # We would check both it and ActiveRecord::Base like so:
28
28
  # check = Easymon::SplitActiveRecordCheck.new {
29
29
  # [ActiveRecord::Base.connection, Easymon::Base.connection]
@@ -31,20 +31,20 @@ module Easymon
31
31
  # Easymon::Repository.add("split-database", check)
32
32
  def initialize(&block)
33
33
  self.block = block
34
- end
35
-
34
+ end
35
+
36
36
  # Assumes only 2 connections
37
37
  def check
38
38
  connections = Array(@block.call)
39
39
 
40
40
  results = connections.map{|connection| database_up?(connection) }
41
-
42
- master_status = results.first ? "Master: Up" : "Master: Down"
43
- slave_status = results.last ? "Slave: Up" : "Slave: Down"
44
-
45
- [(results.all? && results.count > 0), "#{master_status} - #{slave_status}"]
41
+
42
+ primary_status = results.first ? "Primary: Up" : "Primary: Down"
43
+ replica_status = results.last ? "Replica: Up" : "Replica: Down"
44
+
45
+ [(results.all? && results.count > 0), "#{primary_status} - #{replica_status}"]
46
46
  end
47
-
47
+
48
48
  private
49
49
  def database_up?(connection)
50
50
  connection.active?
@@ -1,3 +1,3 @@
1
1
  module Easymon
2
- VERSION = "1.4.2"
2
+ VERSION = "1.6.0"
3
3
  end
data/lib/easymon.rb CHANGED
@@ -8,8 +8,10 @@ require "easymon/repository"
8
8
  require "easymon/result"
9
9
 
10
10
  require "easymon/checks/active_record_check"
11
+ require "easymon/checks/active_record_mysql_writeable_check"
11
12
  require "easymon/checks/split_active_record_check"
12
13
  require "easymon/checks/redis_check"
14
+ require "easymon/checks/redis_writeable_check"
13
15
  require "easymon/checks/memcached_check"
14
16
  require "easymon/checks/semaphore_check"
15
17
  require "easymon/checks/traffic_enabled_check"
File without changes
@@ -17,10 +17,10 @@ test:
17
17
  host: 127.0.0.1
18
18
  port: 3306
19
19
 
20
- test_slave:
20
+ test_replica:
21
21
  adapter: mysql2
22
22
  encoding: utf8
23
- database: dummy_test_slave
23
+ database: dummy_test_replica
24
24
  username: root
25
25
  host: 127.0.0.1
26
26
  port: 3306
File without changes
@@ -1,66 +1,24 @@
1
- DEPRECATION WARNING: Using `Rails::Application` subclass to start the server is deprecated and will be removed in Rails 6.0. Please change `run Dummy::Application` to `run Rails.application` in config.ru. (called from require at script/rails:6)
2
- Started GET "/up" for 127.0.0.1 at 2018-11-08 22:46:44 -0500
3
- Processing by Easymon::ChecksController#index as */*
4
- Rendering text template
5
- Rendered text template (0.0ms)
6
- Completed 503 Service Unavailable in 33ms (Views: 0.6ms)
7
-
8
-
9
- Started GET "/up/foobar" for 127.0.0.1 at 2018-11-08 22:46:48 -0500
10
- Processing by Easymon::ChecksController#show as */*
11
- Parameters: {"check"=>"foobar"}
12
- Rendering text template
13
- Rendered text template (0.0ms)
14
- Completed 404 Not Found in 1ms (Views: 0.3ms)
15
-
16
-
17
- Started GET "/up/foobar" for 127.0.0.1 at 2018-11-08 22:47:10 -0500
18
- Processing by Easymon::ChecksController#show as */*
19
- Parameters: {"check"=>"foobar"}
20
- Rendering text template
21
- Rendered text template (0.0ms)
22
- Completed 404 Not Found in 1ms (Views: 0.4ms)
23
-
24
-
25
- Started GET "/up/foobar" for 127.0.0.1 at 2018-11-08 22:49:15 -0500
26
- Processing by Easymon::ChecksController#show as */*
27
- Parameters: {"check"=>"foobar"}
28
- Rendering text template
29
- Rendered text template (0.0ms)
30
- Completed 404 Not Found in 1ms (Views: 0.5ms)
31
-
32
-
33
- DEPRECATION WARNING: Using `Rails::Application` subclass to start the server is deprecated and will be removed in Rails 6.0. Please change `run Dummy::Application` to `run Rails.application` in config.ru. (called from require at script/rails:6)
34
- Started GET "/up/critical/foobar" for 127.0.0.1 at 2018-11-08 22:50:46 -0500
35
-
36
- ActionController::RoutingError (No route matches [GET] "/up/critical/foobar"):
37
-
38
- actionpack (5.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
39
- actionpack (5.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
40
- railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
41
- railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
42
- activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `block in tagged'
43
- activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
44
- activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `tagged'
45
- railties (5.2.1) lib/rails/rack/logger.rb:26:in `call'
46
- actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
47
- actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
48
- rack (2.0.6) lib/rack/method_override.rb:22:in `call'
49
- rack (2.0.6) lib/rack/runtime.rb:22:in `call'
50
- activesupport (5.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
51
- actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
52
- actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:in `call'
53
- rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
54
- railties (5.2.1) lib/rails/engine.rb:524:in `call'
55
- rack (2.0.6) lib/rack/handler/webrick.rb:86:in `service'
56
- /Users/nathan/.rbenv/versions/2.5.3/lib/ruby/2.5.0/webrick/httpserver.rb:140:in `service'
57
- /Users/nathan/.rbenv/versions/2.5.3/lib/ruby/2.5.0/webrick/httpserver.rb:96:in `run'
58
- /Users/nathan/.rbenv/versions/2.5.3/lib/ruby/2.5.0/webrick/server.rb:307:in `block in start_thread'
59
- Started GET "/up/critical" for 127.0.0.1 at 2018-11-08 22:51:07 -0500
60
- Processing by Easymon::ChecksController#show as */*
61
- Parameters: {"check"=>"critical"}
62
- Rendering text template
63
- Rendered text template (0.0ms)
64
- Completed 503 Service Unavailable in 29ms (Views: 0.5ms)
65
-
66
-
1
+  (0.3ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
2
+  (1.4ms) CREATE DATABASE `dummy_development` DEFAULT CHARACTER SET `utf8`
3
+  (0.3ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
4
+  (1.0ms) CREATE DATABASE `dummy_test` DEFAULT CHARACTER SET `utf8`
5
+  (0.3ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
6
+  (0.3ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
7
+  (25.9ms) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL PRIMARY KEY)
8
+  (20.9ms) CREATE TABLE `ar_internal_metadata` (`key` varchar(255) NOT NULL PRIMARY KEY, `value` varchar(255), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL)
9
+  (0.1ms) SELECT GET_LOCK('1721091371569202325', 0)
10
+  (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
11
+ ActiveRecord::InternalMetadata Load (0.2ms) SELECT `ar_internal_metadata`.* FROM `ar_internal_metadata` WHERE `ar_internal_metadata`.`key` = 'environment' LIMIT 1
12
+  (0.1ms) BEGIN
13
+ ActiveRecord::InternalMetadata Create (0.2ms) INSERT INTO `ar_internal_metadata` (`key`, `value`, `created_at`, `updated_at`) VALUES ('environment', 'development', '2022-05-04 18:01:28', '2022-05-04 18:01:28')
14
+  (0.1ms) COMMIT
15
+  (0.1ms) SELECT RELEASE_LOCK('1721091371569202325')
16
+  (0.3ms) SELECT @@read_only
17
+  (0.2ms) SELECT @@read_only
18
+  (0.1ms) SELECT @@read_only
19
+  (0.8ms) SELECT @@read_only;
20
+  (0.9ms) SELECT @@read_only;
21
+  (3.2ms) SELECT @@read_only;
22
+  (0.2ms) SELECT @@read_only
23
+  (0.2ms) SELECT @@read_only;
24
+  (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC