Permalink
Browse files

Document more scripts and introduce a config file.

  • Loading branch information...
1 parent 92816f7 commit 313705fc3145262dc4a137993cd80cadb757d952 @FooBarWidget FooBarWidget committed Apr 18, 2011
Showing with 70 additions and 15 deletions.
  1. +2 −0 .gitignore
  2. +24 −0 README.md
  3. +9 −0 config.yml.example
  4. +3 −9 gc-git-repos
  5. +8 −4 notify-if-queue-becomes-large
  6. +24 −2 shared.rb
View
@@ -0,0 +1,2 @@
+.DS_Store
+config.yml
View
@@ -56,6 +56,30 @@ You must also make sure your filesystem is mounted with ACL support, e.g.:
Don't forget to update /etc/fstab too.
+### display-queue - Display statistics for local RabbitMQ queues
+
+This tool displays statistics for RabbitMQ queues in a more friendly formatter than `rabbitmqctl list_queues`. The meanings of the columns are as follows:
+
+ * Messages - Total number of messages in the queue. Equal to `Ready + Unack`.
+ * Ready - Number of messages in the queue not yet consumed.
+ * Unack - Number of messages in the queue that have been consumed, but not yet acknowledged.
+ * Consumers - Number of consumers subscribed to this queue.
+ * Memory - The amount of memory that RabbitMQ is using for this queue.
+
+### watch-queue - Display changes in local RabbitMQ queues
+
+`watch-queue` combines the `watch` tool with `display-queue`. It continuously displays the latest queue statistics and highlights changes.
+
+### purge-queue - Removes all messages from a local RabbitMQ queue
+
+`purge-queue` removes all messages from given given RabbitMQ queue. It connects to a RabbitMQ server on localhost on the default port. Note that consumed-but-unacknowledged messages in the queue cannot be removed.
+
+ purge-queue <QUEUE NAME HERE>
+
+### truncate
+
+Truncates the all passed files to 0 bytes.
+
### silcence-unless-failed
Runs the given command but only print its output (both STDOUT and STDERR) if its exit code is non-zero. The script's own exit code is the same as the command's exit code.
View
@@ -0,0 +1,9 @@
+git-gc-repos:
+ glob:
+ - /u/apps/**/.git
+
+notify-if-queue-becomes-large:
+ threshold: 1000
+ to: your@email.com
+ from: your@server.com
+ subject: Queue going out of control
View
@@ -1,20 +1,14 @@
#!/usr/bin/env ruby
-# This script is automatically called in a cron job by root.
+require File.expand_path(File.dirname(__FILE__) + '/shared')
require 'etc'
-DIRS = Dir[
- "/u/apps/**/.git"
-]
+DIRS = Dir[*config(:glob)]
DIRS.each do |dir|
puts "# Garbage collecting #{dir}"
Dir.chdir(dir) do
stat = File.stat(dir)
username = Etc.getpwuid(stat.uid).name
- command = "su -c 'git gc' #{username}"
- puts command
- if !system(command)
- abort "'git gc' failed"
- end
+ quiet_sh "su -c 'git gc' #{username}"
end
puts
end
@@ -1,5 +1,9 @@
#!/usr/bin/env ruby
-THRESHOLD=1000
+require File.expand_path(File.dirname(__FILE__) + '/shared')
+THRESHOLD = config(:threshold)
+FROM = config(:from)
+TO = config(:to)
+SUBJECT = config(:subject)
warnings = []
`rabbitmqctl list_queues -q name messages`.split("\n").each do |line|
@@ -12,9 +16,9 @@ end
if !warnings.empty?
IO.popen("sendmail -t", "w") do |f|
- f.puts "To: info@phusion.nl"
- f.puts "From: noreply@unionstationapp.com"
- f.puts "Subject: [Union Station] Queue going out of control"
+ f.puts "To: #{TO}"
+ f.puts "From: #{FROM}"
+ f.puts "Subject: #{SUBJECT}"
f.puts
f.puts warnings.join("\n")
end
View
@@ -3,9 +3,12 @@
def sh(command, *args)
puts "# #{command} #{args.join(' ')}"
+ quiet_sh(command, *args)
+end
+
+def quiet_sh(command, *args)
if !system(command, *args)
- STDERR.puts "*** ERROR"
- exit 1
+ abort "*** COMMAND FAILED: #{command} #{args.join(' ')}".strip
end
end
@@ -35,3 +38,22 @@ def pv_or_cat
return 'cat'
end
end
+
+def load_config
+ require 'yaml'
+ if !File.exist?("#{TOOLS_DIR}/config.yml")
+ abort "*** ERROR: you must create a #{TOOLS_DIR}/config.yml. " +
+ "Please see #{TOOLS_DIR}/config.yml.example for an example."
+ end
+ all_config = YAML.load_file("#{TOOLS_DIR}/config.yml")
+ $TOOL_CONFIG = all_config[File.basename($0)]
+end
+
+def config(name)
+ load_config if !$TOOL_CONFIG
+ value = $TOOL_CONFIG[name.to_s]
+ if !value
+ abort "*** ERROR: configuration option #{File.basename($0)}.#{name} not set."
+ end
+ return value
+end

0 comments on commit 313705f

Please sign in to comment.