Skip to content

Commit

Permalink
Document more scripts and introduce a config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Apr 18, 2011
1 parent 92816f7 commit 313705f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store
config.yml
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions config.yml.example
@@ -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
12 changes: 3 additions & 9 deletions gc-git-repos
@@ -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
12 changes: 8 additions & 4 deletions notify-if-queue-becomes-large
@@ -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|
Expand All @@ -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
Expand Down
26 changes: 24 additions & 2 deletions shared.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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.