detector 0.8.0 → 0.8.2
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 +4 -4
- data/bin/detector +5 -1
- data/lib/detector/addons/mariadb.rb +11 -0
- data/lib/detector/addons/mysql.rb +17 -2
- data/lib/detector/addons/postgres.rb +2 -1
- data/lib/detector/addons/redis.rb +3 -4
- data/lib/detector/addons/smtp.rb +5 -6
- data/lib/detector/base.rb +15 -0
- data/lib/detector/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1005a81a12b0ba3854590f05209d1c420a32fa1a01ff6e12b6ce8e8d98aebc9
|
4
|
+
data.tar.gz: 071f0840a62f62af205f42e2fc314e5a0b02a202f229d7aaa91b89deb2b29ea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77b605d95e6ba1f5aab74d2060121b28bd44ee6057e4d6ceecf153e79065d7287a17e0b9e046cb24f7e056a4af53d445b757b02fc7a20e0be1eb1f7039206178
|
7
|
+
data.tar.gz: 05d528909480534ded0b1ce8b89aad390465e53713b8a8e8e5895d8a282a2bc7dc503ec1e3a82fc2aff4a203e0e71dfe6143b4fee4d8914b377b65d4ea427593
|
data/bin/detector
CHANGED
@@ -50,7 +50,11 @@ puts "Host: #{detector.host}:#{detector.port}"
|
|
50
50
|
|
51
51
|
if detector.respond_to?(:connection_info) && detector.connection_info
|
52
52
|
conn_info = detector.connection_info
|
53
|
-
|
53
|
+
if conn_info[:error]
|
54
|
+
puts "Connections: #{conn_info[:error]}"
|
55
|
+
else
|
56
|
+
puts "Connections: global #{conn_info[:connection_count][:global]}/#{conn_info[:connection_limits][:global]} (user #{conn_info[:connection_count][:user]}/#{conn_info[:connection_limits][:user]})"
|
57
|
+
end
|
54
58
|
elsif detector.connection_count && detector.connection_limit
|
55
59
|
usage = detector.connection_usage_percentage
|
56
60
|
puts "Connections: #{detector.connection_count}/#{detector.connection_limit} (#{usage}%)"
|
@@ -68,6 +68,17 @@ module Detector
|
|
68
68
|
connection_count: { user: user_count, global: global_count },
|
69
69
|
connection_limits: { user: user_limit, global: global_limit }
|
70
70
|
}
|
71
|
+
rescue Mysql2::Error => e
|
72
|
+
if e.error_number == 1226 # User has exceeded max_user_connections
|
73
|
+
{
|
74
|
+
connection_count: { user: "LIMIT EXCEEDED", global: "N/A" },
|
75
|
+
connection_limits: { user: "EXCEEDED", global: "N/A" },
|
76
|
+
error: "Error: User has exceeded max_user_connections limit"
|
77
|
+
}
|
78
|
+
else
|
79
|
+
puts "Error getting connection info: #{e.message}"
|
80
|
+
nil
|
81
|
+
end
|
71
82
|
rescue => e
|
72
83
|
puts "Error getting connection info: #{e.message}"
|
73
84
|
nil
|
@@ -12,12 +12,17 @@ module Detector
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def connection
|
15
|
-
|
15
|
+
# Create a new connection each time without caching
|
16
|
+
Mysql2::Client.new(
|
16
17
|
host: host,
|
17
18
|
username: uri.user,
|
18
19
|
password: uri.password,
|
19
20
|
database: uri.path[1..-1],
|
20
|
-
port: port
|
21
|
+
port: port,
|
22
|
+
connect_timeout: 5,
|
23
|
+
read_timeout: 10,
|
24
|
+
write_timeout: 10,
|
25
|
+
init_command: "SET wait_timeout=900; SET interactive_timeout=900;"
|
21
26
|
) rescue nil
|
22
27
|
end
|
23
28
|
|
@@ -108,6 +113,16 @@ module Detector
|
|
108
113
|
connection_count: { user: user_count, global: global_count },
|
109
114
|
connection_limits: { user: user_limit, global: global_limit }
|
110
115
|
}
|
116
|
+
rescue Mysql2::Error => e
|
117
|
+
if e.error_number == 1226 # User has exceeded max_user_connections
|
118
|
+
{
|
119
|
+
connection_count: { user: "LIMIT EXCEEDED", global: "N/A" },
|
120
|
+
connection_limits: { user: "EXCEEDED", global: "N/A" },
|
121
|
+
error: "Error: User has exceeded max_user_connections limit"
|
122
|
+
}
|
123
|
+
else
|
124
|
+
nil
|
125
|
+
end
|
111
126
|
rescue => e
|
112
127
|
nil
|
113
128
|
end
|
@@ -13,12 +13,11 @@ module Detector
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def connection
|
16
|
-
|
17
|
-
|
16
|
+
# Create a new connection each time without caching
|
18
17
|
if uri.scheme == 'rediss'
|
19
|
-
|
18
|
+
::Redis.new(url: @url, port: uri.port, timeout: 5.0, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) rescue nil
|
20
19
|
else
|
21
|
-
|
20
|
+
::Redis.new(url: @url, timeout: 5.0) rescue nil
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
data/lib/detector/addons/smtp.rb
CHANGED
@@ -12,13 +12,12 @@ module Detector
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def connection
|
15
|
-
|
16
|
-
|
15
|
+
# Create a new connection each time without caching
|
17
16
|
begin
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
conn = Net::SMTP.new(host, port)
|
18
|
+
conn.open_timeout = 5
|
19
|
+
conn.start('detector.local', uri.user, uri.password, :login)
|
20
|
+
conn
|
22
21
|
rescue => e
|
23
22
|
nil
|
24
23
|
end
|
data/lib/detector/base.rb
CHANGED
@@ -123,9 +123,24 @@ module Detector
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def connection
|
126
|
+
# Default implementation returns nil
|
127
|
+
# Each addon should implement its own connection method
|
128
|
+
# that creates a new connection for each request
|
126
129
|
nil
|
127
130
|
end
|
128
131
|
|
132
|
+
def with_connection
|
133
|
+
conn = connection
|
134
|
+
return yield(nil) unless conn
|
135
|
+
|
136
|
+
begin
|
137
|
+
result = yield(conn)
|
138
|
+
return result
|
139
|
+
ensure
|
140
|
+
close
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
129
144
|
def ping
|
130
145
|
return nil unless valid?
|
131
146
|
transport?
|
data/lib/detector/version.rb
CHANGED