Skip to content

Instantly share code, notes, and snippets.

@McRipper
Created November 26, 2013 12:58
Show Gist options
  • Save McRipper/7657897 to your computer and use it in GitHub Desktop.
Save McRipper/7657897 to your computer and use it in GitHub Desktop.
Check if CouchDb River to Elasticsearch is working
#!/usr/bin/env ruby
# ### README ####
#
# Check if the river is updating and alert if not
#
# gem install elasticsearch
# gem install couchrest
#
require 'rubygems'
require 'couchrest'
require 'elasticsearch'
def couch_seq(name)
couch = CouchRest.new("http://127.0.0.1:5984")
begin
couch_db = couch.database("#{name}")
return couch_db.info["update_seq"]
rescue RestClient::ResourceNotFound
nil
end
end
def elastic_seq(name)
client = Elasticsearch::Client.new host: "http://127.0.0.1:9200"
seq = client.search({
index: '_river',
body: {
query: {
bool: {
must: [{ match: { "_id" => '_seq'}}, { match: {"_type" => name}}]
}
}
}
})
if seq["hits"]["hits"].empty?
nil
else
seq["hits"]["hits"][0]["_source"]["couchdb"]["last_seq"].to_i
end
end
["db1", "db2"].each do |s|
cs = couch_seq(s)
next if cs.nil?
es = elastic_seq(s)
next if es.nil?
puts "#{s}: Es: #{es} < Cs: #{cs}"
if (es + 100) < cs # Prevent alert if update in progress
# Alert
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment