From 59004db8e97303ee8bdab9666a49df16213acdfe Mon Sep 17 00:00:00 2001 From: Munir Nassar Date: Mon, 10 Aug 2009 17:41:59 +0200 Subject: [PATCH] Initial version --- plugins/other/flexlm_ | 147 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100755 plugins/other/flexlm_ diff --git a/plugins/other/flexlm_ b/plugins/other/flexlm_ new file mode 100755 index 00000000..824b2d92 --- /dev/null +++ b/plugins/other/flexlm_ @@ -0,0 +1,147 @@ +#!/usr/bin/perl +# -*- perl -*- +# +# Copyright 2009 by the Regents of the University of Minnesota +# Written by Munir Nassar +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# The Minnesota Supercomputing Institute http://www.msi.umn.edu sponsored +# the development of this software. +# +# Requirements: +# - lmstat +# +# Note: +# - You must provide the daemon name as it is listed in the flexlm license +# if you want it displayed differently use the LMDISPLAYNAME variable +# +# Parameters supported: +# - config +# - autoconf +# +# Configuration variables +# - LMFEATURES: The individual features of each vendor daemon to graph +# - LMDISPLAYNAME: use the LMDISPLAYNAME instead of the daemon name when +# generating graph names +# - LMGRAPHISSUED: Generate a graph of the number of licenses issued for +# each feature . +# - LMSTAT: The path to the lmstat binary +# - LMLICFILE: The path to the FlexLM License File +# +# $Log$ +# Revision 1.00 20090807 nassarmu +# Initial public release. +# +# Magic markers: +#%# family=licensing +#%# capabilities=autoconf + +use strict; +use warnings; +use Munin::Plugin; + + +# What daemon are we going to graph? if none specified exit. +$0 =~ /flexlm_(.+)*$/; +my $daemon = $1; +exit 2 unless defined $daemon; + +# LMFEATURES should be provided by plugin-conf.d space delimited +if ( ! $ENV{'LMFEATURES'} ) { + print "You must provide a list of FlexLM features to monitor via the LMFEATURES variable.\n"; + exit 1 +} + +# This section is for some optional values, the defaults may work for you +# if not then i recommend setting these option via plugin-conf.d +# This would also allow you to theoretically support multiple flexlmds +# via different license files. +our $lmstat; +our $lmlicfile; +our $lmdisplayname; +our $lmgraphissued; +if ( $ENV{'LMSTAT'} ) { + $lmstat = $ENV{'LMSTAT'}; +} else { + $lmstat = "/opt/local/flexlm/bin/lmstat"; +} +if ( $ENV{'LMLICFILE'} ) { + $lmlicfile = $ENV{'LMLICFILE'}; +} else { + $lmlicfile = "/opt/local/flexlm/license/license.dat"; +} +if ( $ENV{'LMDISPLAYNAME'} ) { + $lmdisplayname = $ENV{'LMDISPLAYNAME'}; +} else { + $lmdisplayname = $daemon; +} +if ( $ENV{'LMGRAPHISSUED'} ) { + $lmgraphissued = "1"; +} else { + $lmgraphissued = "0"; +} + +# Parse LMFEATURES +my @features = split(/\s+/, $ENV{'LMFEATURES'}); + +# try and recommend autoconf (this will most likely result in a yes) +if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { + if ( scalar @features >= 1 ) { + print "yes\n"; + exit 0; + } + else { + print "no\n"; + exit 1; + } +} + +# print out a config screen when asked. +if ( $ARGV[0] and $ARGV[0] eq "config" ) { + print "graph_title FlexLM License usage for $lmdisplayname\n"; + print "graph_args --base 1000 --vertical-label licenses -l 0\n"; + print "graph_category licensing\n"; + print "graph_period minute\n"; + foreach my $feature (@features) { + my $clean_feature = clean_fieldname($feature); + print "$clean_feature".".label $feature actual\n"; + print "$clean_feature".".draw LINE2\n"; + print "$clean_feature".".info The number of $feature licenses checked out\n"; + if ( $lmgraphissued ) { + print "$clean_feature"."max.label $feature max\n"; + print "$clean_feature"."max.draw LINE3\n"; + print "$clean_feature"."max.info The total number of $feature licenses available\n"; + } + } + exit 0 +} + +# pull the info from lmstat and print the results +foreach my $feature (@features) { + my @results = `$lmstat -c $lmlicfile -S $daemon -f $feature`; + + foreach my $result (@results) { + if ($result =~ m/Users of $feature\:/ ) { + chomp ($result); + my (@fields) = split( m/\s+/, $result); + + my $clean_feature = clean_fieldname($feature); + print "$clean_feature".".value $fields[10]\n"; + if ( $lmgraphissued ) { + print "$clean_feature"."max.value $fields[5]\n"; + } + } + } +}