easymon 1.4 → 1.5

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: 995c7954f5c5d720f9840c0f93b1d673de2e6a6682c7a134336cac6d21f2a280
4
- data.tar.gz: 7cbce9feb1e3a4f4fc7c661a5597314fb2107e3ac36d5ee84cfa2810c218dc75
3
+ metadata.gz: 46eed6312dd05be2f1cc453b481dbbe26cbed28e6a9954d68aee4ed96b5d2935
4
+ data.tar.gz: 57a512d8baf55d331a7386ccc80ea9879820cb2775327d321ba8d11d0b630660
5
5
  SHA512:
6
- metadata.gz: c805aec0b3a45ac5e289ffe5fe7f17e85abb250dbd31d09787e1e3912e11d4040a3a7aa9c04018fc8dfe4febc3e0aaeb638f4ef4e4a65eea8d0250d2fb60b090
7
- data.tar.gz: 2763483c3faf6714ccfbc3ea055bb985a9ed0a125527e41ec9e72e25946a85979794590c6886fa42259c9e1fa6dbac99b441ac575ef89a3bfbebdf7c8d8372b0
6
+ metadata.gz: cfe6ee337e9353b08dd9dcb7b807f2f8881d471e884257fd8a21e48bf29f79fb6680ba29a56b2cea2b40ac365d46ca9566fa89c1df98808832e11bf93d45ee66
7
+ data.tar.gz: 13e4c388db907301c04ed04a3fe25b8eba77b78e88496d3b1ac1a993980fb65ecf75db24c91b1f90ad230b47ad4c70919b973b587280a7ec9bd95d6b09433291
@@ -17,8 +17,8 @@ module Easymon
17
17
 
18
18
  rescue_from Easymon::NoSuchCheck do |e|
19
19
  respond_to do |format|
20
- format.any(:text, :html) { render_result e.message, :not_found }
21
- format.json { render :json => e.message, :status => :not_found }
20
+ format.any(:text, :html) { render_result "Check Not Found", :not_found }
21
+ format.json { render :json => "Check Not Found", :status => :not_found }
22
22
  end
23
23
  end
24
24
 
@@ -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
@@ -3,11 +3,11 @@ require "redis"
3
3
  module Easymon
4
4
  class RedisCheck
5
5
  attr_accessor :config
6
-
6
+
7
7
  def initialize(config)
8
8
  self.config = config
9
- end
10
-
9
+ end
10
+
11
11
  def check
12
12
  check_status = redis_up?
13
13
  if check_status
@@ -17,12 +17,16 @@ module Easymon
17
17
  end
18
18
  [check_status, message]
19
19
  end
20
-
20
+
21
21
  private
22
22
  def redis_up?
23
23
  redis = Redis.new(@config)
24
24
  reply = redis.ping == 'PONG'
25
- redis.close
25
+ if redis.respond_to? :close
26
+ redis.close # Redis 4+
27
+ else
28
+ redis.client.disconnect # Older redis
29
+ end
26
30
  reply
27
31
  rescue
28
32
  false
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Easymon
2
- VERSION = "1.4"
2
+ VERSION = "1.5"
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"
@@ -0,0 +1,24 @@
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