MySQL Replication Health

MySQL Replication is a powerful tool to help with both disaster recovery and high availability, but many things can go wrong, including network and file corruption.

Where the two servers are in sync is tracked by the binary log files. To check for the current file and position of the binary log, you issue a show master status or show slave status commands, depending on if you are on the master or slave. Comparing these files you can determine if the slave is fully in sync with the master, or if problems have occurred.

Here is a simple bash script, which compares the filename and position of the binary log on both the master and slave. A side effect of the script is also that it logs on to both servers, telling you if the server is unreachable at all.

Setting up FreeTDS Against Sybase with Ruby

Connecting to Sybase from within Linux is not as easy as, say, connecting to PostgreSQL or MySQL, but if you know the steps involved it can be rather painless. To connect we are going to use the FreeTDS project and ODBC.
Configuring the FreeTDS Client

First step is to install the freetds package.
Arch Linux: pacman -Sy freetds
Debian Linux: apt-get install freetds-common

Next, setup your /etc/freetds/freetds.conf. In this example, our alias is “PROD”
1 2 3 4

[PROD]
host = sybase_hostname
port = sybase_port
tds version = 5.0

view raw
freetds.conf hosted with ❤ by GitHub

We can now test freetds with the included sqsh program:
sqsh -S PROD -U -P
Configuring UNIX ODBC Connections

Once successful with FreeTDS, we now will configure unix ODBC to work with it. This will let us use a plethora of tools and languages to interact with our database, including ruby.

Arch Linux: pacman -Sy unixodbc
Debian Linux: apt-get install unixodbc

/etc/odbcinst.ini
1 2 3 4 5 6 7

[TDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
FileUsage = 1
CPTimeout =
CPReuse =

view raw
odbcinst.ini hosted with ❤ by GitHub

/etc/odbc.ini
1 2 3 4 5 6

[prod]
Driver = /usr/lib/libtdsodbc.so
Description = ODBC
Trace = No
Servername = PROD
Database =

view raw
odbc.ini hosted with ❤ by GitHub

We can now test with isql. This program can also be used to run sql scripts, for example via cron. This is a great way to run miscellaneous reports and queries.
isql -v qual1
Configuring Ruby

gem install dbi
gem install dbd-odbc
gem install ruby-odbc

Simple test script
1 2 3 4 5 6 7 8 9 10 11 12

!/usr/bin/ruby

require ‘dbi’
require ‘odbc’

dbh = DBI.connect(‘DBI:ODBC:prod’, ‘username’, ‘password’)
query = “select getdate()”
row = dbh.select_one(query)

puts “got a value of: “ + row[0].to_s

dbh.disconnect if dbh

view raw
odbc_ruby_example.rb hosted with ❤ by GitHub

Connecting with PHP to Sybase on WAMP Server

Sybase is one of those systems that can be sometimes finicky to setup on the client side. I was pleasantly surprised to see that PHP has support for Sybase. When you need to quickly prototype a new feature or give your user’s a quick dynamic report, PHP can be a great path to go.

It took a little research to get all the parts necessary, but the installation is very smooth.

Install WAMP
Install Sybase client (you want the open client; login/pass required)
Update php.ini to: enable sybase extension (extension=php_sybase_ct.dll)
specify location of sybase sql.ini file (sybase.interface_file = 'c:\sybase\ini\sql.ini')

Tiling Window Managers and Productivity

On a recent walk whilst listening to one of my favorite podcast, the Stack Overflow Podcast, Joel and Jeff started talking about the productivity of dual monitors.

It is a [fairly] undisputed fact that having a second monitor makes any worker more productive. The reason for this is quite simple, more desktop real-estate means being able to see more applications at a time. This makes even more sense when you factor in all the tabbing between applications that you save, sometimes in my case this means tabbing multiple times because I had forgotten what I had just read.

Jeff made the point that often times he doesn’t bother with moving and resizing windows, and usually just brings it to the monitor he wants and then makes it full-screen. His point was that this makes him even more productive, because you no longer worry about placement of windows. I couldn’t agree more.

This is exactly the place where tiling window managers come in to play. A tiling window manager is one in which you do spend your time moving and resizing windows, as they are automatically placed for you. This allows you to focus on your work at hand, rather than tabbing to see all your windows, or moving and resizing to see two at once.

When you combine the power of a tiling window manager with dual screens, something magical happens. Now you have the increased desktop space in addition to no longer having to manage your windows. In my tiling window manager, XMonad, you treat each monitor as a separate window into your virtual desktops. By this I mean that you setup windows in a particular virtual desktop, and then have the ability to show that virtual desktop on whichever monitor you choose.
03-2009 XMonad Screenshot

I cannot emphasize enough the benefits of both dual screens and a tiling window manager. Some good managers for Linux are:

* XMonad
* Awesome
* DWM
* Subtle

Easy Email Disk Space Alerts

The other day I ran into an issue where a server of mine ran out of disk space. The server is part of a surveillance system I have and collects ~2 gigs of jpeg’s a day, and so can fill up every couple of months if I’m not careful. Not having an alert system finally caught up with me and I was greeted when I returned from work with a couple dozen failure e-mails from cron, indicating the system had run out of space.

Not to be caught in this situation again, I’ve added the below to my crontab. It’s a simple bash command that will e-mail me if my server gets over 80% utilized. I use the second line to send an SMS message to myself if the server becomes 90% or over utilized.

Email when storage gets low

00 * * * * full=/bin/df | /bin/egrep “(100\%|[89][0-9]\%)”&& echo $full | /usr/bin/mail -s "[$HOSTNAME] Warning: harddrive space issue" EMAIL_ADDRESS@PROVIDER.COM
00 * * * * full=/bin/df | /bin/egrep “(100\%|9[0-9]\%)”&& echo $full | /usr/bin/mail -s "[$HOSTNAME] URGENT: harddrive space issue" EMAIL_ADDRESS@PROVIDER.COM