mysql_health 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mysql_health/health.rb +60 -52
- data/lib/mysql_health/version.rb +1 -1
- data/redhat/rubygem-mysql_health.spec +1 -1
- metadata +3 -3
data/lib/mysql_health/health.rb
CHANGED
@@ -106,78 +106,86 @@ module MysqlHealth
|
|
106
106
|
|
107
107
|
def check_master
|
108
108
|
MysqlHealth.log.debug("check_master")
|
109
|
-
|
110
|
-
# connect to the MySQL server
|
111
|
-
dbh = DBI.connect(@options[:dsn], @options[:username], @options[:password])
|
112
|
-
|
113
109
|
response = {}
|
114
110
|
response[:content_type] = 'text/plain'
|
115
111
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
112
|
+
begin
|
113
|
+
# connect to the MySQL server
|
114
|
+
dbh = DBI.connect(@options[:dsn], @options[:username], @options[:password])
|
115
|
+
|
116
|
+
status = {}
|
117
|
+
dbh.select_all('SHOW STATUS') do |row|
|
118
|
+
status[row[0].downcase.to_sym] = row[1]
|
119
|
+
end
|
120
|
+
mysqladmin_status = "Uptime: %s Threads: %s Questions: %s Slow queries: %s Opens: %s Flush tables: %s Open tables: %s Queries per second avg: %.3f\n" %
|
121
|
+
[ status[:uptime], status[:threads_running], status[:questions], status[:slow_queries], status[:opened_tables], status[:flush_commands], status[:open_tables], status[:queries].to_i/status[:uptime].to_i]
|
122
|
+
if status.length > 0
|
123
|
+
if read_only?(dbh)
|
124
|
+
response[:status] = '503 Service Read Only'
|
125
|
+
response[:content] = mysqladmin_status
|
126
|
+
else
|
127
|
+
response[:status] = '200 OK'
|
128
|
+
response[:content] = mysqladmin_status
|
129
|
+
end
|
126
130
|
else
|
127
|
-
response[:status] = '
|
131
|
+
response[:status] = '503 Service Unavailable'
|
128
132
|
response[:content] = mysqladmin_status
|
129
133
|
end
|
130
|
-
|
131
|
-
response[:status] = '
|
132
|
-
response[:content] =
|
134
|
+
rescue Exception => e
|
135
|
+
response[:status] = '500 Server Error'
|
136
|
+
response[:content] = e.message
|
133
137
|
end
|
134
138
|
self.master_status=(response)
|
135
139
|
end
|
136
140
|
|
137
141
|
def check_slave
|
138
142
|
MysqlHealth.log.debug("check_slave")
|
139
|
-
|
140
|
-
# connect to the MySQL server
|
141
|
-
dbh = DBI.connect(@options[:dsn], @options[:username], @options[:password])
|
142
|
-
|
143
143
|
response = {}
|
144
144
|
response[:content_type] = 'text/plain'
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
146
|
+
begin
|
147
|
+
# connect to the MySQL server
|
148
|
+
dbh = DBI.connect(@options[:dsn], @options[:username], @options[:password])
|
149
|
+
|
150
|
+
show_slave_status = []
|
151
|
+
status = {}
|
152
|
+
dbh.execute('SHOW SLAVE STATUS') do |sth|
|
153
|
+
sth.fetch_hash() do |row|
|
154
|
+
row.each_pair do |k,v|
|
155
|
+
status[k.downcase.to_sym] = v
|
156
|
+
show_slave_status << "#{k}: #{v}"
|
157
|
+
end
|
153
158
|
end
|
154
159
|
end
|
155
|
-
end
|
156
160
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
161
|
+
if status.length > 0
|
162
|
+
seconds_behind_master = status[:seconds_behind_master]
|
163
|
+
|
164
|
+
# We return a "203 Non-Authoritative Information" when replication is shot. We don't want to reduce site performance, but still want to track that something is awry.
|
165
|
+
if seconds_behind_master.eql?('NULL')
|
166
|
+
response[:status] = '203 Slave Stopped'
|
167
|
+
response[:content] = status.to_json
|
168
|
+
response[:content_type] = 'application/json'
|
169
|
+
elsif seconds_behind_master.to_i > 60*30
|
170
|
+
response[:status] = '203 Slave Behind'
|
171
|
+
response[:content] = status.to_json
|
172
|
+
response[:content_type] = 'application/json'
|
173
|
+
elsif read_only?(dbh)
|
174
|
+
response[:status] = '200 OK ' + seconds_behind_master + ' Seconds Behind Master'
|
175
|
+
response[:content] = status.to_json
|
176
|
+
response[:content_type] = 'application/json'
|
177
|
+
else
|
178
|
+
response[:status] = '503 Service Unavailable'
|
179
|
+
response[:content] = status.to_json
|
180
|
+
response[:content_type] = 'application/json'
|
181
|
+
end
|
173
182
|
else
|
174
|
-
response[:status] = '503
|
175
|
-
response[:content] =
|
176
|
-
response[:content_type] = 'application/json'
|
183
|
+
response[:status] = '503 Slave Not Configured'
|
184
|
+
response[:content] = show_slave_status.join("\n")
|
177
185
|
end
|
178
|
-
|
179
|
-
response[:status] = '
|
180
|
-
response[:content] =
|
186
|
+
rescue Exception => e
|
187
|
+
response[:status] = '500 Server Error'
|
188
|
+
response[:content] = e.message
|
181
189
|
end
|
182
190
|
self.slave_status=(response)
|
183
191
|
end
|
data/lib/mysql_health/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
%define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
|
2
2
|
%define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
|
3
3
|
%define gemname mysql_health
|
4
|
-
%define gemversion 0.5.
|
4
|
+
%define gemversion 0.5.6
|
5
5
|
%define geminstdir %{gemdir}/gems/%{gemname}-%{gemversion}
|
6
6
|
%define gemfile %{gemname}-%{gemversion}.gem
|
7
7
|
%define gemsummary %(ruby -rrubygems -e 'puts YAML.load(`gem specification %{gemfile}`).summary')
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 6
|
9
|
+
version: 0.5.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Erik Osterman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-12-05 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|