Skip to content

Instantly share code, notes, and snippets.

@rusllonrails
Forked from McRipper/check_river
Created May 27, 2014 08:52
Show Gist options
  • Save rusllonrails/6a7e60a1a0a1c9708061 to your computer and use it in GitHub Desktop.
Save rusllonrails/6a7e60a1a0a1c9708061 to your computer and use it in GitHub Desktop.
#!/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