2009-08-21

Removing data from rrdtool files

We benchmarked our new SQL-server and caused a nasty peak in Munin graphs. The peaks really made the graps quite useless as the new information was flattened to the very bottom of the graph.

Nulling days of data was quite easy as rrdtool has dump and restore commands.

root@foo:/var/lib/munin/example.tld# for i in foo.example.tld-* ; do
rrdtool dump $i > /tmp/foo.xml &&\
awk -f /tmp/fix.awk /tmp/foo.xml > /tmp/bar.xml &&\
rrdtool restore -f /tmp/bar.xml $i
done

The /tmp/fix.awk awk script changes sample values to NaN which rrdtool regards as empty samples.

$2=="2009-08-20" || $2=="2009-08-21" {
$9="NaN";
}

{
print $0;
}

2009-05-20

PostgreSQL transaction stats to MRTG

The following perl fragment does "SELECT sum(xact_commit) FROM pg_stat_database;" and returns four lines suitable for use with mrtg (data1, data2, uptime, hostname):


0
12765

db1.example.tld


We don't have access to uptime, so we ignore it. The transaction count is in the second data field for purely aesthetic reasons.

Try that the script works before configuring mrtg:


#!/usr/bin/perl -w
use DBI;
use strict;

my $dbhost='db1.example.tld';
my $dbname='template1';
my $dbuser='monitor';
my $dbpass='secretword';

my $connstring = "DBI:Pg:dbname=$dbname;host=$dbhost";
my $connection = DBI->connect($connstring, $dbuser, $dbpass, {RaiseError => 0, PrintError => 0}) || die "Unable to access database: ". $DBI::errstr ."";

my $query = "select sum(xact_commit) + sum(xact_rollback) from pg_stat_database;";
my $stmt = $connection->prepare($query);
$stmt->execute() || die "Running query failed: ". $DBI::errstr ."";
my $row = $stmt->fetchrow();

print "0\n";
print $row . "\n";
print "\n";
print $dbhost . "\n";


I use the following MRTG fragment:

Target[sql.xacts]: `/etc/mrtg-sql-tps.pl`
MaxBytes[sql.xacts]: 1250000
Title[sql.xacts]: PostgreSQL transactions per second
PageTop[sql.xacts]: PostgreSQL transactions per second
YLegend[sql.xacts]: Xacts / second
ShortLegend[sql.xacts]: xact/s
LegendO[sql.xacts]: Transactions per second
Options[sql.xacts]: integer,nopercent,noinfo,nobanner,noi


noi option causes mrtg to ignore the first data field (Input) and LegendO sets description for the second data field we use (Output for MRTG).

Remeber to make a new index page with indexmaker.

2009-03-10

Silicon Labs CP2101 based USB to UART adapter on Mac OS X

I bought some embedded controllers and a USB to TTL-level UART serial converter from Omnima web store. After some googling with the the USB vendor and product id I figured out that the converter was based on Silicon Labs CP2101 chip. I installed Mac OS X drivers from https://www.silabs.com/products/interface/usbtouart/Pages/default.aspx but no luck. The device wouldn't be recognised.

System profiler tells me the product id is 0x10c5 and vendor id 0x10ab (product 4293, vendor 4267 in decimal) but there was no entry for that combination in driver's plist - /System/Library/Extensions/SiLabsUSBDriver.kext/Contents/Info.plist.

The trick was to copypaste and modify one of the sections used to register the driver for product+vendor combinations. Just use the decimal form of product and vendor codes. Rebuild of driver cache had to be triggered by touching /System/Library/Extensions.

http://ciz.fi/~jkj/silab-mac-usb-driver.patch

After patching info.plist and rebuilding driver cache, plugging the device generated a device node in /dev/cu.SLAB_USBtoUART