Thank you Vladimir for the script!  Unfortunately my team has decided to
go a different direction with Ganglia. 
Thanks again for helping me out though, I do appreciate it.
Chris Stackpole

-----Original Message-----
From: Vladimir [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 14, 2006 6:38 PM
To: Stackpole, Chris
Cc: [email protected]
Subject: Re: [Ganglia-general] Using Custom Metrics to Pass Messages

Stackpole, Chris wrote:
>
> I have been wondering if it would be possible to use some kind of 
> metric to pass information from the "nodes" back to the Ganglia 
> frontend and have them displayed on a sub webpage.
>
 
>
> I did not find anything in the archives so I figured I would ask for 
> pointers before I began on my own. Does anyone have any ideas on how 
> feasible this may be and where I might begin?
>
I would think this would be feasible. You can use gmetric to add your 
own "metrics". A metric can be a string.

For example we use Nagios for alerting and to avoid having to use 
Nagios' nsca daemon to pass information like diskfree I simply use 
Ganglia to get that info (since it already runs on the Nagios box).  If 
you can get the ganglia python client running use that. Otherwise I 
wrote a command line PHP script that uses Ganglia's web frontend scripts

to parse Ganglia's XML. Here is my code that simply

Hope this helps.

#!/usr/bin/php
<?php

########################################################################
##############
$GANGLIA_DIR='/srv/www/htdocs/ganglia';
########################################################################
##############

if ( $argc != 2 ) {
   echo "Not enough arguments. Please supply Fully Qualified name for 
the host
Usage:  $argv[0] <hostname>  ie.
        $argv[0] server.domain.net
Exiting ....\n";
   exit (1);
}

include_once $GANGLIA_DIR .  "/conf.php";
include_once $GANGLIA_DIR . "/get_context.php";
$context = "cluster";
include_once $GANGLIA_DIR . "/functions.php";
include_once $GANGLIA_DIR . "/ganglia.php";
include_once $GANGLIA_DIR . "/get_ganglia.php";

# Make sure it is FQDN
if ( strpos($argv[1], ".") != FALSE )
        $hostname = substr($argv[1], 0, strpos($argv[1], "."));
else
        $hostname = $argv[1];

########################################################################
##############
# Get list of hosts in Ganglia
########################################################################
##############
$ganglia_hosts = array_keys($metrics);

########################################################################
##############
# Because we have multiple interfaces on machines we need to find the 
exact name
# of the machine that the Ganglia is using otherwise this script blows
up
########################################################################
##############
for ( $i = 0 ; $i < sizeof($ganglia_hosts) ; $i++ ) {
        if ( eregi ( $hostname, $ganglia_hosts[$i] ) ) {
                $fqdn = $ganglia_hosts[$i];
                break;
        }
}

########################################################################
##############
# $metrics is an array of
[Metrics][Hostname][NAME|VAL|TYPE|UNITS|SOURCE].
# Make sure that hostname actually has metrics available. If not report 
UNKNOWN state
########################################################################
##############
if ( ! is_array($metrics[$fqdn])) {
   echo("DISKFREE UNKNOWN - Hostname info not available. Likely invalid 
hostname");
   exit(3);
}

# Make sure that host is providing disk_free and disk_total to the
cluster
if ( isset($metrics[$fqdn]['disk_free']['VAL']) && 
isset($metrics[$fqdn]['disk_total']['VAL']) ) {
   $disk_free_percent = 
$metrics[$fqdn]['disk_free']['VAL']/$metrics[$fqdn]['disk_total']['VAL']
;
} else {
   echo("DISKFREE UNKNOWN - Disk free or disk total not available for 
this host.");
   exit(3);
}

########################################################################
##############
# If disk available is less then 8% mark it critical
########################################################################
##############
if ( $disk_free_percent > 0.08 ) {
        echo(sprintf("DISKFREE OK - %01.2f%% free\n", $disk_free_percent

* 100));
        exit (0);
} else {
        echo(sprintf("DISKFREE CRITICAL - %01.2f%% free\n", 
$disk_free_percent * 100));
        exit (2);
}
?>



Reply via email to