murakumo 0.3.2 → 0.3.3

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.
@@ -1,5 +1,5 @@
1
1
  module Murakumo
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
 
4
4
  # Priority
5
5
  MASTER = 1
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'net/smtp'
3
+ require 'net/telnet'
3
4
  require 'socket'
4
5
 
5
6
  require 'misc/murakumo_const'
@@ -26,7 +27,7 @@ module Murakumo
26
27
  end
27
28
 
28
29
  # HTTPチェッカー
29
- def http_get(path, statuses = [200], host = '127.0.0.1', port = 80)
30
+ def http_get(path, statuses = [200], port = 80, host = '127.0.0.1')
30
31
  res = Net::HTTP.start('127.0.0.1', 80) do |http|
31
32
  http.read_timeout = @options['timeout']
32
33
  http.get(path)
@@ -46,8 +47,18 @@ module Murakumo
46
47
  return false
47
48
  end
48
49
 
49
- # MySQLのドライバがあれば、MySQLチェッカーを定義
50
- mysql_class = nil
50
+ # memcachedチェッカー
51
+ def memcached_check(port = 11211, host = '127.0.0.1')
52
+ telnet = Net::Telnet.new('Host' => host, 'Port' => port)
53
+ !!telnet.cmd('String' => 'stats', 'Match' => /END/i, 'Timeout' => @options['timeout'])
54
+ rescue =>e
55
+ @logger.debug("#{@name}: #{e.message}")
56
+ return false
57
+ ensure
58
+ if telnet
59
+ telnet.close rescue nil
60
+ end
61
+ end
51
62
 
52
63
  begin
53
64
  require 'mysql'
@@ -68,37 +79,43 @@ module Murakumo
68
79
  @logger.debug("#{@name}: #{e.message}")
69
80
  return false
70
81
  ensure
71
- my.close if my
82
+ if my
83
+ my.close rescue nil
84
+ end
72
85
  end
73
86
  rescue LoadError
74
87
  end
75
88
 
76
- begin
77
- require 'mysql2'
78
-
79
- def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil)
80
- opts = {}
81
- opts[:username] = user
82
- opts[:password] = passwd if passwd
83
- opts[:host] = host if host
84
- opts[:database] = db if db
85
-
86
- if port_sock.kind_of?(Integer)
87
- opts[:port] = port_sock
88
- else
89
- opts[:socket] = port_sock
89
+ unless defined?(:mysql_check)
90
+ begin
91
+ require 'mysql2'
92
+
93
+ def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil)
94
+ opts = {}
95
+ opts[:username] = user
96
+ opts[:password] = passwd if passwd
97
+ opts[:host] = host if host
98
+ opts[:database] = db if db
99
+
100
+ if port_sock.kind_of?(Integer)
101
+ opts[:port] = port_sock
102
+ else
103
+ opts[:socket] = port_sock
104
+ end
105
+
106
+ my = Mysql2::Client.new(opts)
107
+ my.ping
108
+ rescue => e
109
+ @logger.debug("#{@name}: #{e.message}")
110
+ return false
111
+ ensure
112
+ if my
113
+ my.close rescue nil
114
+ end
90
115
  end
91
-
92
- my = Mysql2::Client.new(opts)
93
- my.ping
94
- rescue => e
95
- @logger.debug("#{@name}: #{e.message}")
96
- return false
97
- ensure
98
- my.close if my
116
+ rescue LoadError
99
117
  end
100
- rescue LoadError
101
- end
118
+ end # unless defined?(:mysql_check)
102
119
 
103
120
  end # HealthCheckContext
104
121
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murakumo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel