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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d21e960cc4220b3bf67a98d0ce5ef7f367710545173ff09cfcee580cc3895e64
4
- data.tar.gz: dba6d148d06ea37444017539b0bb23fd43cb96c9deeedf6235fc8e5cfe3999b7
3
+ metadata.gz: c1005a81a12b0ba3854590f05209d1c420a32fa1a01ff6e12b6ce8e8d98aebc9
4
+ data.tar.gz: 071f0840a62f62af205f42e2fc314e5a0b02a202f229d7aaa91b89deb2b29ea8
5
5
  SHA512:
6
- metadata.gz: 19732b310f2f739e03c478103ebb1de34979145fd867d5beab4c82d8ef14c6405c7b4d9bac18849b79adba3dfc9e0e25c4dd0fcada4d6321e95a0822a9cc3efc
7
- data.tar.gz: 318344d8e1f23196e5fe2eef8435aec32729fe488d41b0277bcf567117df1f3dbe105269777310a51344aba2453565adc1506c014d1c972a33b02c8f32d1afe5
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
- puts "Connections: global #{conn_info[:connection_count][:global]}/#{conn_info[:connection_limits][:global]} (user #{conn_info[:connection_count][:user]}/#{conn_info[:connection_limits][:user]})"
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
- @conn ||= Mysql2::Client.new(
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
@@ -12,7 +12,8 @@ module Detector
12
12
  end
13
13
 
14
14
  def connection
15
- @conn ||= PG::Connection.new(uri) rescue nil
15
+ # Create a new connection each time without caching
16
+ PG::Connection.new(uri) rescue nil
16
17
  end
17
18
 
18
19
  def version
@@ -13,12 +13,11 @@ module Detector
13
13
  end
14
14
 
15
15
  def connection
16
- return @conn if @conn
17
-
16
+ # Create a new connection each time without caching
18
17
  if uri.scheme == 'rediss'
19
- @conn = ::Redis.new(url: @url, port: uri.port, timeout: 5.0, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) rescue nil
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
- @conn = ::Redis.new(url: @url, timeout: 5.0) rescue nil
20
+ ::Redis.new(url: @url, timeout: 5.0) rescue nil
22
21
  end
23
22
  end
24
23
 
@@ -12,13 +12,12 @@ module Detector
12
12
  end
13
13
 
14
14
  def connection
15
- return @conn if @conn
16
-
15
+ # Create a new connection each time without caching
17
16
  begin
18
- @conn = Net::SMTP.new(host, port)
19
- @conn.open_timeout = 5
20
- @conn.start('detector.local', uri.user, uri.password, :login)
21
- @conn
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?
@@ -1,3 +1,3 @@
1
1
  module Detector
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel