Tuesday, January 26, 2016

4 podcasts to follow

4 podcasts to listen to while commuting (in no particular order):

  1. DevOps cafè : hosted monthly, features great guests and packs a tremendous amount of valuable information. Warm up by listening to a great episode with with Tom Limoncelli
  2. MagPipe Talk show : I discovered this gem because it recently featured Martin Fowler
  3. The Changelog: more targeted towards developers than the previous two. Make sure you listen to the recent episodes with Yehuda Katx and Mitchell Hashimoto
  4. Hansel Minutes. Usually this one is mostly of interest to Windows people. Useful if one wants to keep an eye on the ther side of the pond or catch the occasional high-level talk

Sunday, January 10, 2016

One-liner libvirt KVM guest

Boot and install a new KVM guest with guest agent support with this super simple libvirt one-liner (great for scripts and CI deployments).
Tested on a Centos 7.1 host creating a Centos 7.1 guest from a basic Kickstart file.

Parameters should be quite self-explanatory, in any case here's the documentation for virt-install. Important: remember to change the unix socket path on the last line.

Tuesday, December 22, 2015

How to automatically import a ZFS pool built on top of iSCSI devices with systemd

When using ZFS on top of iSCSI devices one needs to deal with the fact that iSCSI devices usually appear late in the boot process. ZFS on the other hand is loaded early and the iSCSI devices are not present at the time ZFS scans available devices for pools to import.

This means that not all ZFS pools might be imported after the system has completed boot, even if the underlying devices are present and functional. A quick and dirty solution would be to run zpool import <poolname> after boot, either manually or from cron.

A better, more elegant solution is instead to hook into systemd events and trigger zpool import as soon as the devices are created.

Friday, November 13, 2015

Centralized async logging from VBS scripts

Borrow a page out of the snowplow book and log asynchronously from any script with a GET request to a central system.

In Visual Basic Script:

URLGet "http://your.server.com/action/" & WshNetwork.ComputerName & "/" & activity & "/message/" & strValue

Function URLGet(URL)
  Set Http = CreateObject("Microsoft.XMLHTTP")
  Http.Open "GET",URL,True
  Http.Send
End Function

And get analytics for free on top of your scripts with logstash (or snowplow).

Tuesday, October 27, 2015

Fun with Postgresql and ZFS

I will show how to use ZFS instant snapshotting and cloning functionality to effortlessly clone a running postgres database regardless of its size.

Setup

Install your Linux OS of choice then ZFS and Postgres. I use Centos 7 but most commands used in this post are distro-indipendent.

Create a zfs pool called tank or use whatever name suits you. In the pool create a filesystem called pgdata. For the sake of following a minimalist ZFS best practice apply the following settings:

zfs set compression=lz4 tank/pgdata
zfs set xattr=sa tank/pgdata

Friday, August 14, 2015

Simple is beautiful: Guava LoadingCache

Cache is king.

Database lookups can be expensive and RAM prices have been falling for years to the point that developers don't care anymore (ops do, btw).
So what if you could use those gigabytes of RAM for caching expensive queries or frequently used data? If you are a Java developer chances are that you came across Ehcache, Spring cache, or perhaps rolled your own.
Disclaimer: not the Guava stuff described in this post

Grails bundles Ehcache because it can be used by Hibernate and also has a plugin which allows to cache methods just by annotating them. Unfortunately Ehcache has some quirks and with the stock configuration it will also not allow parallel deployment (I documented a fix here on this blog).

An alternative cache implementation that I recently had a chance to use is the Guava LoadingCache. The implementation is so elegant that it will make you want to use it everywhere! Basically you build a cache, configure TTL and size (optional) and supply a loader callback that will be invoked whenever an entry cannot be found in the cache. Example here.

Assuming you are accessing the cache implementation directly, no more complex if-peek-then-return-else-load-put-return. From now on just:

cache.getEntry(k)

An additional benefit is that Guava does not carry dependencies, is OSGi-ready, and will keep your project lighter.

Sunday, April 19, 2015

Detect missed executions with OpenNMS

Everyone knows that OpenNMS is a powerful monitoring solution, but not everyone knows that since version 1.10 circa it embeds the Drools rule processing engine. Drools programs can then be used to extend the event handling logic in new and powerful ways.

The following example shows how OpenNMS can be extended to detect missed executions for recurring activities like backups or scheduled jobs.