easymon 1.4 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/controllers/easymon/checks_controller.rb +2 -2
- data/lib/easymon/checks/active_record_mysql_writeable_check.rb +26 -0
- data/lib/easymon/checks/redis_check.rb +9 -5
- data/lib/easymon/checks/redis_writeable_check.rb +36 -0
- data/lib/easymon/checks/split_active_record_check.rb +12 -12
- data/lib/easymon/version.rb +1 -1
- data/lib/easymon.rb +2 -0
- data/test/dummy/app/assets/config/manifest.js +0 -0
- data/test/dummy/config/database.yml +2 -2
- data/test/dummy/config/storage.yml +0 -0
- data/test/dummy/log/development.log +24 -0
- data/test/dummy/log/test.log +6944 -873
- data/test/dummy/tmp/cache/4D4/7A0/health_check +1 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/checks/active_record_mysql_writeable_check_test.rb +27 -0
- data/test/unit/checks/redis_writeable_check_test.rb +28 -0
- data/test/unit/checks/split_active_record_check_test.rb +19 -19
- metadata +19 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb55744be4fa12e4c7af34ae59091721967aaf08d1bd07e4bc0cca4bd2937c4a
|
4
|
+
data.tar.gz: ed1822f256bea98b6982f634487c676fad7e292ca093c10315ce72990ffb6778
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd39994e506c00177688ae9ecb7ff660326cc44eec4374cdeb42873c3128bec45da18dfb54969b9a6494fb0d79ef1d87be4d223c4ef162a70bfc5d4db4345e9a
|
7
|
+
data.tar.gz: a6515ddbd1f7a0bce037815d8804c2c7689dfc943c1ad9c7f037d711ff41700efcc6367e261b2bd3a80b43590e30ef2523ec2bd639537aac7eada9fa5f000bbd
|
data/README.md
CHANGED
@@ -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
|
21
|
-
format.json { render :json =>
|
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
|
@@ -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}
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
[(results.all? && results.count > 0), "#{
|
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?
|
data/lib/easymon/version.rb
CHANGED
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
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
[1m[35m (0.3ms)[0m [1m[35mSET 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[0m
|
2
|
+
[1m[35m (1.4ms)[0m [1m[35mCREATE DATABASE `dummy_development` DEFAULT CHARACTER SET `utf8`[0m
|
3
|
+
[1m[35m (0.3ms)[0m [1m[35mSET 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[0m
|
4
|
+
[1m[35m (1.0ms)[0m [1m[35mCREATE DATABASE `dummy_test` DEFAULT CHARACTER SET `utf8`[0m
|
5
|
+
[1m[35m (0.3ms)[0m [1m[35mSET 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[0m
|
6
|
+
[1m[35m (0.3ms)[0m [1m[35mSET 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[0m
|
7
|
+
[1m[35m (25.9ms)[0m [1m[35mCREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL PRIMARY KEY)[0m
|
8
|
+
[1m[35m (20.9ms)[0m [1m[35mCREATE TABLE `ar_internal_metadata` (`key` varchar(255) NOT NULL PRIMARY KEY, `value` varchar(255), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL)[0m
|
9
|
+
[1m[35m (0.1ms)[0m [1m[34mSELECT GET_LOCK('1721091371569202325', 0)[0m
|
10
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC[0m
|
11
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.2ms)[0m [1m[34mSELECT `ar_internal_metadata`.* FROM `ar_internal_metadata` WHERE `ar_internal_metadata`.`key` = 'environment' LIMIT 1[0m
|
12
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
13
|
+
[1m[36mActiveRecord::InternalMetadata Create (0.2ms)[0m [1m[32mINSERT 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')[0m
|
14
|
+
[1m[35m (0.1ms)[0m [1m[35mCOMMIT[0m
|
15
|
+
[1m[35m (0.1ms)[0m [1m[34mSELECT RELEASE_LOCK('1721091371569202325')[0m
|
16
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT @@read_only[0m
|
17
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT @@read_only[0m
|
18
|
+
[1m[35m (0.1ms)[0m [1m[34mSELECT @@read_only[0m
|
19
|
+
[1m[35m (0.8ms)[0m [1m[34mSELECT @@read_only;[0m
|
20
|
+
[1m[35m (0.9ms)[0m [1m[34mSELECT @@read_only;[0m
|
21
|
+
[1m[35m (3.2ms)[0m [1m[34mSELECT @@read_only;[0m
|
22
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT @@read_only[0m
|
23
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT @@read_only;[0m
|
24
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC[0m
|