Created
November 18, 2010 22:00
-
-
Save gilles/705726 to your computer and use it in GitHub Desktop.
Compact chef's couchdb indexes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim:ts=2:expandtab | |
require 'rubygems' | |
require 'open-uri' | |
require 'json' | |
#http://wiki.apache.org/couchdb/Compaction | |
if JSON::parse(open("http://localhost:5984/chef").read)["disk_size"] > 100_000_000 | |
res = Net::HTTP.post_form(URI.parse('http://localhost:5984/chef/_compact'), {}) | |
puts res.body | |
end | |
%w(nodes roles registrations clients data_bags data_bag_items users).each do |view| | |
puts "check for clean: #{view}" | |
begin | |
res = open("http://localhost:5984/chef/_design/#{view}/_info") | |
if JSON::parse(res.read)['view_index']["disk_size"] > 100_000_000 | |
res = Net::HTTP.post_form(URI.parse("http://localhost:5984/chef/_compact/#{view}"), {}) | |
puts res.body | |
end | |
rescue | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think getting a list of chef views using http://localhost:5984/chef/_all_docs?startkey="_design/"&endkey="_design0"&include_docs=false is more dynamic