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.
@@ -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
- 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
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] = '200 OK'
131
+ response[:status] = '503 Service Unavailable'
128
132
  response[:content] = mysqladmin_status
129
133
  end
130
- else
131
- response[:status] = '503 Service Unavailable'
132
- response[:content] = mysqladmin_status
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
- show_slave_status = []
147
- status = {}
148
- dbh.execute('SHOW SLAVE STATUS') do |sth|
149
- sth.fetch_hash() do |row|
150
- row.each_pair do |k,v|
151
- status[k.downcase.to_sym] = v
152
- show_slave_status << "#{k}: #{v}"
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
- if status.length > 0
158
- seconds_behind_master = status[:seconds_behind_master]
159
-
160
- # 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.
161
- if seconds_behind_master.eql?('NULL')
162
- response[:status] = '203 Slave Stopped'
163
- response[:content] = status.to_json
164
- response[:content_type] = 'application/json'
165
- elsif seconds_behind_master.to_i > 60*30
166
- response[:status] = '203 Slave Behind'
167
- response[:content] = status.to_json
168
- response[:content_type] = 'application/json'
169
- elsif read_only?(dbh)
170
- response[:status] = '200 OK ' + seconds_behind_master + ' Seconds Behind Master'
171
- response[:content] = status.to_json
172
- response[:content_type] = 'application/json'
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 Service Unavailable'
175
- response[:content] = status.to_json
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
- else
179
- response[:status] = '503 Slave Not Configured'
180
- response[:content] = show_slave_status.join("\n")
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
@@ -18,5 +18,5 @@
18
18
  # along with mysql_health. If not, see <http://www.gnu.org/licenses/>.
19
19
  #
20
20
  module MysqlHealth
21
- VERSION = "0.5.5"
21
+ VERSION = "0.5.6"
22
22
  end
@@ -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.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
- - 5
9
- version: 0.5.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-08-05 00:00:00 -07:00
17
+ date: 2012-12-05 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency