Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis service watcher #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ PATH
specs:
nerve (0.3.0)
bunny (= 1.0.0.rc2)
redis (~> 3.0.1)
zk (~> 1.9.2)

GEM
remote: https://rubygems.org/
specs:
amq-protocol (1.8.0)
amq-protocol (1.9.0)
bunny (1.0.0.rc2)
amq-protocol (>= 1.8.0)
little-plugger (1.1.3)
logging (1.7.2)
little-plugger (>= 1.1.3)
redis (3.0.6)
slyphon-log4j (1.2.15)
slyphon-zookeeper_jar (3.3.5-java)
zk (1.9.2)
logging (~> 1.7.2)
zookeeper (~> 1.4.0)
zookeeper (1.4.7)
zookeeper (1.4.7-java)
slyphon-log4j (= 1.2.15)
slyphon-zookeeper_jar (= 3.3.5)

PLATFORMS
java
Expand Down
13 changes: 13 additions & 0 deletions example/nerve.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@
"password": "guest"
}
]
},
"redis_service": {
"host": "127.0.0.1",
"port": 6379,
"zk_hosts": ["localhost:2181"],
"zk_path": "/nerve/services/your_redis_service/services",
"check_interval": 2,
"checks": [
{
"type": "redis",
"db": 0,
}
]
}
}
}
1 change: 1 addition & 0 deletions lib/nerve/service_watcher.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'nerve/service_watcher/tcp'
require 'nerve/service_watcher/http'
require 'nerve/service_watcher/rabbitmq'
require 'nerve/service_watcher/redis'

module Nerve
class ServiceWatcher
Expand Down
43 changes: 43 additions & 0 deletions lib/nerve/service_watcher/redis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'nerve/service_watcher/base'
require 'redis'

module Nerve
module ServiceCheck
class RedisServiceCheck < BaseServiceCheck

def initialize(opts={})
super

@host = opts['host'] || '127.0.0.1'
@port = opts ['port'] || 6379
@db = opts['db'] || 0
@name = "#{@db}@#{@host}:#{@port}"
end

def check
log.debug "nerve: running @host = #{@host} health check #{@name}"

begin
redis = Redis.new(:host => @host, :port => @port, :db => @db)

res = redis.ping

if res.eql? 'PONG'
return true
else
log.info "nerve: redis #{@name} failed to responde"
return false
end
rescue Redis::BaseError => e
log.info "nerve: unable to connect with redis #{@name} #{e}"
return false
ensure
redis.quit if redis
end
end
end

CHECKS ||= {}
CHECKS['redis'] = RedisServiceCheck
end
end
1 change: 1 addition & 0 deletions nerve.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Gem::Specification.new do |gem|

gem.add_runtime_dependency "zk", "~> 1.9.2"
gem.add_runtime_dependency "bunny", "= 1.0.0.rc2"
gem.add_runtime_dependency "redis", "~> 3.0.1"
end