Class: Murakumo::HealthCheckerContext
- Inherits:
-
Object
- Object
- Murakumo::HealthCheckerContext
- Defined in:
- lib/srv/murakumo_health_checker_context.rb
Overview
ヘルスチェックのコンテキスト
Instance Method Summary collapse
-
#http_get(path, statuses = [200], host = '127.0.0.1', port = 80) ⇒ Object
HTTPチェッカー.
- #mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil) ⇒ Object
-
#tcp_check(port, host = '127.0.0.1') ⇒ Object
TCPチェッカー.
Instance Method Details
#http_get(path, statuses = [200], host = '127.0.0.1', port = 80) ⇒ Object
HTTPチェッカー
21 22 23 24 25 26 27 28 29 |
# File 'lib/srv/murakumo_health_checker_context.rb', line 21 def http_get(path, statuses = [200], host = '127.0.0.1', port = 80) res = Net::HTTP.start('127.0.0.1', 80) do |http| http.get(path) end statuses.include?(res.code.to_i) rescue Exception return false end |
#mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/srv/murakumo_health_checker_context.rb', line 46 def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil) port = nil sock = nil if port_sock.kind_of?(Integer) port = port_sock else sock = port_sock end my = Mysql.new(host, user, passwd, db, port, sock) !!(my.respond_to?(:ping) ? my.ping : my.stat) rescue false end |
#tcp_check(port, host = '127.0.0.1') ⇒ Object
TCPチェッカー
12 13 14 15 16 17 18 |
# File 'lib/srv/murakumo_health_checker_context.rb', line 12 def tcp_check(port, host = '127.0.0.1') s = TCPSocket.new(host, port) s.close return true rescue Exception return false end |