diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a97f0a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +config.yml diff --git a/README.md b/README.md index 73cdf3d..1976c4d 100644 --- a/README.md +++ b/README.md @@ -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 + +### 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. diff --git a/config.yml.example b/config.yml.example new file mode 100644 index 0000000..fd64656 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/gc-git-repos b/gc-git-repos index 5d28649..d4d5b49 100755 --- a/gc-git-repos +++ b/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 diff --git a/notify-if-queue-becomes-large b/notify-if-queue-becomes-large index 2d801c8..544d8a4 100755 --- a/notify-if-queue-becomes-large +++ b/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| @@ -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 diff --git a/shared.rb b/shared.rb index 4e3f03f..89b18d8 100644 --- a/shared.rb +++ b/shared.rb @@ -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