2010/11/16

Global networks

At work, each network segment is classified with a color based on its access list. We have brown, green, red, purple, blue, orange, and firewalls all over the place. This has inspired...

The Network Connection

Why are there so many damn network colors,
And routers and firewalls?
Show them on pow'r point, but only to man'gers
And they will approve the change.
So we've been told and some choose to believe it
I know that I'll wait and see
Someday they'll make it
My Network Connection,
The cables, the VLANs, and me...

Who said that every server needs IP
A link to one thousand base T
Somebody thought of that, approving the purchase
Except for the cabling
A WAN so amazing, with OC-3's blazing
Sometimes the pings make it through.
Someday they'll make it,
A global connection,
The cables, the VLANS, and me...

All of us scanned by Nessus,
We know that it's probably magic

Have you been half-routed? Dropped by Rule Zero?
Lost packets silently
This is annoying, quit making changes
On Friday at end of the day.
Some of us do work, even on weekends, we need the network to flow.
Someday I'll have it
A working connection,
The cables, the VLANS and me...

--Joe

2010/11/08

Building stand-alone Collectd plugin - Part 2

Actually, this wasn't as difficult as I was expecting.

The only real challenge was in the fact that the ESX Guest SDK libraries are only distributed as a shared object, which means my plugin had to dlopen() the required library, rather than being able to link it in statically. Luckily, I was able to cannibalize some of the example guest SDK code for this.

Here's the basic idea:
// Function to get how much CPU time we've gotten
VMGuestLibError (*GuestLib_GetCpuUsedMs)(VMGuestLibHandle handle, uint64 *cpuUsedMs);

//In the plugin_init function, I dlopen("libvmGuestLib.so") and assign the function
GuestLib_GetCpuUsedMs = dlsym(dlHandle, "VMGuestLib_GetCpuUsedMs");
//And open the Guestlib handle. Each plugin_read loop, I
// GuestLib_UpdateInfo(glHandle); and then can get the latest data.
glError = GuestLib_GetCpuUsedMs(glHandle, &(CpuUsedMs));
values[0].counter = CpuUsedMs;
// and plugin_dispatch_values().


Then I copied the resulting .libs/esx_guest* and the libvmGuestLib.so into the ~collectd/lib/collectd/ directory (where it looks for plugin SOs) and fired it up. I also had to add entries to the types.db for my data sources.

From here, I get cool graphs for my Linux VMs like these.


I'll put this code up on my personal site when I get a chance, and contribute these documentation to the collectd project.

--Joe

2010/11/03

Building stand-alone Collectd plugin

I'm working on building a plugin for the collectd data collection system (www.collectd.org) that will gather stats on our ESX RedHat VMs through the VMware Guest API.

Here's what I've found so far...

unpack collectd, configure and make it.
In a separate directory, create the source files for the new plugin.

(minimal plugin code:
#include "collectd.h"
#include "common.h"
#include "plugin.h"

static int my_read(void) {
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;

values[0].counter = 0;

vl.values = values;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "test1", sizeof (vl.plugin));
sstrncpy (vl.type, "counter", sizeof (vl.type));

plugin_dispatch_values (&vl);

return 0;
}

void module_register(void) {
plugin_register_read ("test1", my_read);
}


Then I use libtool to build the .o:
$ libtool --mode=compile gcc -DHAVE_CONFIG_H -I ../collectd-4.10.1/src -Wall -Werror -g -O2 -MT test1.lo -MD -MP -MF test1.Tpo -c -o test1.lo test1.c
and link it:
$ libtool --tag=CC --mode=link gcc -Wall -Werror -g -O2 -module -avoid-version -o test1.la -rpath /apps/collectd-4.10.1/lib/collectd -lpthread -ldl test1.lo

This generates the files in ./libs/test1.* which I copy into the $prefix/lib/collectd/ directory and enable it in my config.

So much for part 1... Up next, getting actual data.

--Joe

2010/08/06

DVDs with VLC

Mostly to install this into my NVRAM, but also because there seems to be a shortage of quick instructions for this.

Using VLC Media Player (Windows, version 1.1.2 in my case)
Ctrl-S (streaming)
Disc tab, No Menus, adjust title/chapter if needed
_S_tream
Next
Add a destination file and optionally "Display Locally"
I added a custom profile, MPEG-PS, Video and audio codec "Keep Original"
Stream

This apparently builds a stream output string of ":sout=#file{dst=d:\\junk.ps} :no-sout-rtp-sap :no-sout-standard-sap :sout-keep"

Then rename the .ps to .mpeg or .mpg or whatever.

This runs faster than DVD-time (at least on my system) and doesn't appear to lose any quality, presumably since it doesn't re-code anything.

--Joe

2010/07/09

Windows NLB clustering and SIDs

A colleague has been working to set up a MS NLB cluster for a set of .NET machines. As is our standard practice, these are created as ESX VMs, and for convenience, we create them based on our standard template. Then the VMware guest customization process runs, and we have a VM we can turn over to the application team.

The problem in this case (the reason I'm involved in a Windows issue) is that NLB wasn't starting. There were various false-starts with configuration items randomly disappearing (why is only one of the NICs in the selection box on this system?).

Somehow, it was suggested that maybe the reason NLB wouldn't start was because the SID of the two VMs was the same. Of course, no, since we run the guest customization which does a NewSID(1m). That'd be impossible.

But it turns out that the SIDs were the same, popping the machines out of the domain and newsid'ing them resolved the issue. Whod'a thunk?

On further reflection, the system's SID is probably the best option for a locally-unique identifier to use to map the loadbalancing traffic via NLB. There has to be some way for all the cluster members to agree on who cares about which packets, so why not use the SID as part of the hash function? Makes perfect sense, since SIDs are, of course, unique.

--Joe

2010/03/29

Is today the last $weekday of the month?

Classic problem in sysadmin: How to run a script on the last Sunday (or whatever day) of the month. This snippet is correct for all days, even in leap years between 1904 and 2096, inclusive. It messes up on February 22 each century, except when the year is divisible by 400 (works in 1600, 2000, 2400, etc. but breaks in 2100, 2200, 2300) But I'll be retired by then...

My answer, in Korn Shell:


# Day of the week to run on:
DOW=Sunday

OLDLC_TIME=$LC_TIME
export LC_TIME=C
# Requires /usr/bin/ksh to run correctly.
# I couldn't be bothered to get the expr quoting and backquoting working in /bin/sh
case `date +%b` in
Jan|Mar|May|Jul|Aug|Oct|Dec) D=31;;
Apr|Jun|Sep|Nov) D=30;;
Feb) D=$(( 28 + ( $(date +%Y) %4 == 0 ));;
# FIXME: Y2.1K bug here.
esac

if [[ `date +%A` == "$DOW" ]] && [[ $(( $(date +%e) + 7 -gt $D ]]
# then next Sunday is after the end of this month, so today's the last Sunday of this month
then
....
fi

LC_TIME=$OLDLC_TIME