#!/usr/bin/perl -w
#
# (c) 2004 Michael Kaiser
# tools (at) micha (dot) de
# 
# Plugin to monitor the number users logged in to a unix box.
# Based on an idea of a hotsanic script.
# Never tested for any other class than pts users. Until now,
# I've only tested on various Linux boxen, but it might work
# on other Un*x-alike systems as well. I'd like to hear from 
# you, if you can report this script running on any other 
# platform than Linux.
# 
#
# Usage: copy or link into /etc/munin/node.d/
#
# Parameters:
#
# 	config   (required)
#
# $Id: users.in 1142 2006-10-17 12:27:35Z tore $
#
# $Log$
# Revision 1.1.2.1  2005/01/11 13:48:33  ilmari
# Fix linux/users #! line.
#
# Revision 1.1  2004/12/20 13:43:36  jimmyo
# Added plugin linux/users, created by Michael Kaiser.
#
#
#%# family=contrib

if ( $ARGV[0] and $ARGV[0] eq "config" )
{
    print "graph_title Logged in users\n";
    print "graph_args --base 1000 -l 0\n";
    print "graph_vlabel Count/min\n";
    print "graph_scale  no\n";
    print "tty.label tty\n";
    print "tty.draw AREA\n";
    print "pty.label pty\n";
    print "pty.draw STACK\n";
    print "pts.label pts\n";
    print "pts.draw STACK\n";
    exit 0;
}

open (WHO,"who|tr -s ' '|cut -d' ' -f2|cut -d'/' -f1|");
@who = <WHO>;
close (WHO);

$tty =0;
$pty =0;
$pts =0;

foreach $tt (@who) {
	$tty++ if ($tt =~ /ttyv?/);
	$pty++ if ($tt =~ /pty|ttyp/);
	$pts++ if ($tt =~ /pts/);
}

print "tty.value $tty\n";
print "pty.value $pty\n";
print "pts.value $pts\n";

# vim:syntax=perl
