about

rss

A quick and dirty collectd plugin for the Varnish cache


#!/usr/bin/env ruby

require 'rubygems'
require 'eventmachine'
require 'getoptlong'

opts = GetoptLong.new(
  [ '--hostid', '-h', GetoptLong::OPTIONAL_ARGUMENT ],
  [ '--sampling-interval', '-i',  GetoptLong::OPTIONAL_ARGUMENT ]
)

def usage
  puts("#{$0} -h <host_id> [-i <sampling_interval>]")
  exit
end

sampling_interval = nil
hostname = `hostname`.chomp

opts.each do |opt, arg|
  case opt
    when '--hostid'
      hostname = arg
    when '--sampling-interval'
      sampling_interval = arg.to_i
  end
end

def underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  tr(" ", "_").
  downcase
end

EM.run do
    EM.add_periodic_timer(sampling_interval||2) do
    now = Time.now.to_i
    stats = `varnishstat -1` 
    stats.each_line do |line|
      #client_conn            211980         0.30 Client connections accepted
      next unless /^(\w+)\s+(\d+)\s+(\d+\.\d+)\s(.+)$/.match(line)
      puts("PUTVAL #{hostname}/varnish/counter-#{underscore $4} #{now}:#{$2}")
    end
    end
end

Copy this code in /usr/lib/collectd/varnish.rb

Then edit your collectd configuration to add (or uncomment) (don’t forget to change the user)


LoadPlugin exec

<Plugin exec>
  Exec "your_user" "/usr/lib/collectd/varnish.rb" 
  #Exec "user:group" "/path/to/exec" 
  #NotificationExec user "/path/to/exec" 
</Plugin>

A simple backupninja script for mongodb

After reading this stuff about corruption of mongodb http://ivoras.sharanet.org/blog/tree/2009-11-05.a-short-time-with-mongodb.html, I thought it was time to write a small script to backup our brand new mongodb databases at YeastyMobs

Here is the handler (in /usr/share/backupninja/mongodb):

getconf host localhost
getconf backupdir
getconf mongodump_path /opt/mongodb/bin/mongodump

info "Going to backup mongodb of $host in $backupdir" 

if [ ! -f $mongodump_path ]; then
        fatal "$mongodump_path does not exists" 
fi

if [ ! -d $backupdir ]; then
        fatal "$backupdir does not exists" 
fi

if [ ! -w $backupdir ]; then
        fatal "$backupdir is not writable by you" 
fi

if [ ! $test ]; then
        output=`$mongodump_path -h $host -o $backupdir`
        code=$?

        if [ "$code" == "0" ]; then
                debug $output
                info "Successfully finished dump of all mongodb databases" 
        else
                warning $output
                warning "Failed to dump all mongodb databases" 
        fi
else
        debug "running $mongodump_path -h $host -o $backupdir" 
fi


and the backup script (in /etc/backup.d/10-action.mongodb):


backupdir = /var/backups/mongodb
mongodump_path = /opt/mongodb/bin/mongodump

DB

10+ Deploys Per Day: Dev and Ops Cooperation at Flickr

ruby + arduino

Fuzzycom le tumblelog de Vincent Hellot