Shoulda macro for the Userstamp plugin

written by Rahvin on December 28th, 2008 @ 02:03 AM

The following is a shoulda macro that I’ve written for the userstamp plugin. I recommend creating a file should_be_stampable.rb in the test/shoulda_macros folder. It will be loaded automagically.

The test is acts_as_paranoid aware so it also checks for the deleter part if it is available.

You can call

should_be_stampable

for models that have

class Post < ActiveRecord::Base
  stampable
end

and there is

should_stamp_models

for your User model that contains

class User < ActiveRecord::Base
  model_stamper
end

should_be_stampable.rb:

class Test::Unit::TestCase
  # Use this to test models that are equiped with 'stampable'
  def self.should_be_stampable
    klass = self.name.gsub(/Test$/, '').constantize
    include_deleted_by = klass.respond_to?(:paranoid?) && klass.paranoid?

    context "#{klass}" do
      should_have_db_column :creator_id, :type => "integer"
      should_have_db_column :updater_id, :type => "integer"
      should_have_db_column :deleter_id, :type => "integer" if include_deleted_by

      should_belong_to :creator
      should_belong_to :updater
      should_belong_to :deleter if include_deleted_by

      should_have_class_methods :without_stamps, :stamper_class, :stampable

      should_have_instance_methods :creator, :creator=, :updater, :updater=
      should_have_instance_methods :deleter, :deleter= if include_deleted_by
    end 
  end

  # Use this to test the user model that has 'model_stamper'
  def self.should_stamp_models
    klass = self.name.gsub(/Test$/, '').constantize

    context "#{klass}" do
      should_have_class_methods :stamper, :stamper=
    end
  end
end

The tests are quite simple, so if you have anything to add to it, please let me know.

How to install rbcdio on OS X Leopard

written by Rahvin on October 17th, 2008 @ 11:47 AM

After fighting with it for about half an hour, here is how you get the rbcdio gem working on OS X Leopard with the libcdio library installed from MacPorts.

First you have to install libcdio using MacPorts, this is the easy part:

sudo port install libcdio

This will install libcdio and libcddb, after this you can install the rbcdio gem using the following command. This is actually as easy as the previous command, after you find out you have to pass the include path.

sudo gem install rbcdio -- --with-opt-include=/opt/local/include/

Now add the following to your environment.rb

config.gem 'rbcdio', :lib => 'cdio'
config.gem 'rbcdio', :lib => 'iso9660'

And thats it.

Harddisk benchmarks with ZCAV and gnuplot

written by Rahvin on July 31st, 2008 @ 04:51 PM

I was browsing the campzone forums and came across a topic where everyone was showing their HD Tune graphs. Since I haven’t done any benchmarks on my new server yet, I became interested. Unfortunately HD Tune is only for windows so I fired up google to look for alternatives for BSD. I came across a site that used the output of ZCAV (a tool from the bonnie++ package) with gnuplot to create some cool graphs. I decided to try it out and installed gnuplot and bonnie++. After installing, I ran the zcav command for both my array’s:

zcav -c3 -laacd0 -f/dev/aacd0
zcav -c3 -laacd1 -f/dev/aacd1

This ran for a while and after that, the two logfiles aacd0 and aacd1 were created.

The -c3 specifies that zcav should run the test 3 times, this results in nicer graphs.

ZCAV reads the data from the harddisk and divides this up in zones, you then get the per-zone speed. Zones on the outside of the disk platter are faster than zones on the inside.

Then with the following gnuplot script I generated a graph:

unset autoscale x
set autoscale xmax
unset autoscale y
set autoscale ymax
set xlabel "Position MB"
set ylabel "KB/s"
set key right bottom
plot "aacd0" title "4x ST373207LC RAID10", "aacd1" title "2x ST373207LC RAID1"
set terminal png
set output "disks.png"
replot

ZCAV + gnuplot harddisk benchmark

The red array contains my /, the green array is for /home

The horizontal line shows that there is a bottleneck somewhere, the disks can go faster, but something is capping it at 110MB/s. Anyway, it’s a pretty good speed i’m getting there. These disks are all connected to one channel of the servers Adaptec AIC-7902 combined with the AOC-LPZCR2. The storage array is connected to the other channel.

After I finished the zcav run for my storage array, which I did with -c1 because of the amount of data, I made a graph of that too:

ZCAV + gnuplot harddisk benchmark

The Seagate’s are performing great. Especially the 250GB versions who stay at 55MB/s on the entire platter. Then the two Hitachi Deskstars, which are nicknamed Deathstars at my work, it seems these two are going to die too, judging by the speed drop on a large part of the disk. And then the Maxtors, which are just bad overall.

Cacti on FreeBSD with working graphs

written by Rahvin on July 17th, 2008 @ 01:53 AM

After days of searching for a solution or why my cacti wasn’t showing any graphs, I finally found this post. It turns out that little setting really is the solution. Now after manually switching to RRDTool 1.2.x everything is running fine.

Options:

Size

Colors