detector 0.7.0 → 0.8.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 +4 -4
- data/bin/detector +4 -1
- data/lib/detector/addons/mariadb.rb +21 -0
- data/lib/detector/addons/mysql.rb +20 -0
- data/lib/detector/addons/postgres.rb +22 -0
- data/lib/detector/addons/redis.rb +16 -0
- data/lib/detector/base.rb +9 -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: d21e960cc4220b3bf67a98d0ce5ef7f367710545173ff09cfcee580cc3895e64
|
4
|
+
data.tar.gz: dba6d148d06ea37444017539b0bb23fd43cb96c9deeedf6235fc8e5cfe3999b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19732b310f2f739e03c478103ebb1de34979145fd867d5beab4c82d8ef14c6405c7b4d9bac18849b79adba3dfc9e0e25c4dd0fcada4d6321e95a0822a9cc3efc
|
7
|
+
data.tar.gz: 318344d8e1f23196e5fe2eef8435aec32729fe488d41b0277bcf567117df1f3dbe105269777310a51344aba2453565adc1506c014d1c972a33b02c8f32d1afe5
|
data/bin/detector
CHANGED
@@ -48,7 +48,10 @@ puts "Detected: #{detector.kind}"
|
|
48
48
|
puts "Version: #{detector.version}"
|
49
49
|
puts "Host: #{detector.host}:#{detector.port}"
|
50
50
|
|
51
|
-
if detector.
|
51
|
+
if detector.respond_to?(:connection_info) && detector.connection_info
|
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]})"
|
54
|
+
elsif detector.connection_count && detector.connection_limit
|
52
55
|
usage = detector.connection_usage_percentage
|
53
56
|
puts "Connections: #{detector.connection_count}/#{detector.connection_limit} (#{usage}%)"
|
54
57
|
end
|
@@ -53,6 +53,27 @@ module Detector
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
def connection_info
|
57
|
+
return nil unless connection
|
58
|
+
begin
|
59
|
+
user_limit = connection.query("SELECT @@max_user_connections AS `limit`").first['limit'].to_i
|
60
|
+
user_count = connection.query("SELECT COUNT(*) AS count FROM information_schema.PROCESSLIST WHERE user = USER()").first['count'].to_i
|
61
|
+
global_limit = connection.query("SELECT @@max_connections AS `limit`").first['limit'].to_i
|
62
|
+
global_count = connection.query("SELECT COUNT(*) AS count FROM information_schema.PROCESSLIST").first['count'].to_i
|
63
|
+
|
64
|
+
# If user limit is 0, it means no specific per-user limit (use global)
|
65
|
+
user_limit = global_limit if user_limit == 0
|
66
|
+
|
67
|
+
{
|
68
|
+
connection_count: { user: user_count, global: global_count },
|
69
|
+
connection_limits: { user: user_limit, global: global_limit }
|
70
|
+
}
|
71
|
+
rescue => e
|
72
|
+
puts "Error getting connection info: #{e.message}"
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
56
77
|
def tables(database_name)
|
57
78
|
return [] unless connection
|
58
79
|
|
@@ -93,6 +93,26 @@ module Detector
|
|
93
93
|
connection.query("SHOW VARIABLES LIKE 'max_connections'").first['Value'].to_i
|
94
94
|
end
|
95
95
|
|
96
|
+
def connection_info
|
97
|
+
return nil unless connection
|
98
|
+
begin
|
99
|
+
user_limit = connection.query("SELECT @@max_user_connections AS `limit`").first['limit'].to_i
|
100
|
+
user_count = connection.query("SELECT COUNT(*) AS count FROM information_schema.PROCESSLIST WHERE user = USER()").first['count'].to_i
|
101
|
+
global_limit = connection.query("SELECT @@max_connections AS `limit`").first['limit'].to_i
|
102
|
+
global_count = connection.query("SELECT COUNT(*) AS count FROM information_schema.PROCESSLIST").first['count'].to_i
|
103
|
+
|
104
|
+
# If user limit is 0, it means no specific per-user limit (use global)
|
105
|
+
user_limit = global_limit if user_limit == 0
|
106
|
+
|
107
|
+
{
|
108
|
+
connection_count: { user: user_count, global: global_count },
|
109
|
+
connection_limits: { user: user_limit, global: global_limit }
|
110
|
+
}
|
111
|
+
rescue => e
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
96
116
|
def cli_name
|
97
117
|
"mysql"
|
98
118
|
end
|
@@ -146,6 +146,28 @@ module Detector
|
|
146
146
|
connection.exec("SELECT current_setting('max_connections')").first['current_setting'].to_i
|
147
147
|
end
|
148
148
|
|
149
|
+
def connection_info
|
150
|
+
return nil unless connection
|
151
|
+
begin
|
152
|
+
global_limit = connection.exec("SELECT current_setting('max_connections')").first['current_setting'].to_i
|
153
|
+
global_count = connection.exec("SELECT count(*) FROM pg_stat_activity").first['count'].to_i
|
154
|
+
|
155
|
+
# For PostgreSQL user connections - depends on per-user limits if set
|
156
|
+
user_limit_result = connection.exec("SELECT rolconnlimit FROM pg_roles WHERE rolname = current_user").first
|
157
|
+
user_limit = user_limit_result['rolconnlimit'].to_i
|
158
|
+
user_limit = global_limit if user_limit <= 0 # If unlimited, use global limit
|
159
|
+
|
160
|
+
user_count = connection.exec("SELECT count(*) FROM pg_stat_activity WHERE usename = current_user").first['count'].to_i
|
161
|
+
|
162
|
+
{
|
163
|
+
connection_count: { user: user_count, global: global_count },
|
164
|
+
connection_limits: { user: user_limit, global: global_limit }
|
165
|
+
}
|
166
|
+
rescue => e
|
167
|
+
nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
149
171
|
def cli_name
|
150
172
|
"psql"
|
151
173
|
end
|
@@ -69,6 +69,22 @@ module Detector
|
|
69
69
|
info['maxclients'].to_i rescue 0
|
70
70
|
end
|
71
71
|
|
72
|
+
def connection_info
|
73
|
+
return nil unless info
|
74
|
+
begin
|
75
|
+
# Redis doesn't have per-user connection limits, so user = global
|
76
|
+
global_count = info['connected_clients'].to_i rescue 0
|
77
|
+
global_limit = info['maxclients'].to_i rescue 0
|
78
|
+
|
79
|
+
{
|
80
|
+
connection_count: { user: global_count, global: global_count },
|
81
|
+
connection_limits: { user: global_limit, global: global_limit }
|
82
|
+
}
|
83
|
+
rescue => e
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
72
88
|
def cli_name
|
73
89
|
"redis-cli"
|
74
90
|
end
|
data/lib/detector/base.rb
CHANGED
@@ -233,6 +233,15 @@ module Detector
|
|
233
233
|
(connection_count.to_f / connection_limit.to_f * 100).round(1)
|
234
234
|
end
|
235
235
|
|
236
|
+
def connection_info
|
237
|
+
# Default implementation for databases without user-specific limits
|
238
|
+
return nil unless connection_count && connection_limit
|
239
|
+
{
|
240
|
+
connection_count: { user: connection_count, global: connection_count },
|
241
|
+
connection_limits: { user: connection_limit, global: connection_limit }
|
242
|
+
}
|
243
|
+
end
|
244
|
+
|
236
245
|
def estimated_row_count(table:, database: nil)
|
237
246
|
nil
|
238
247
|
end
|
data/lib/detector/version.rb
CHANGED