2009-08-10 17:41:59 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# -*- perl -*-
|
2012-06-25 19:15:50 +02:00
|
|
|
#
|
2009-08-10 17:41:59 +02:00
|
|
|
# Copyright 2009 by the Regents of the University of Minnesota
|
|
|
|
# Written by Munir Nassar <nassarmu@msi.umn.edu>
|
2012-06-25 19:15:50 +02:00
|
|
|
# Rewrite contribution by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
|
2009-08-10 17:41:59 +02:00
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# The Minnesota Supercomputing Institute http://www.msi.umn.edu sponsored
|
|
|
|
# the development of this software.
|
2012-06-25 19:15:50 +02:00
|
|
|
#
|
2009-08-10 17:41:59 +02:00
|
|
|
# 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
|
2012-06-25 19:15:50 +02:00
|
|
|
#
|
2009-08-10 17:41:59 +02:00
|
|
|
# Parameters supported:
|
|
|
|
# - config
|
|
|
|
# - autoconf
|
2012-06-25 19:15:50 +02:00
|
|
|
#
|
2009-08-10 17:41:59 +02:00
|
|
|
# Configuration variables
|
2012-06-25 19:15:50 +02:00
|
|
|
# - LMFEATURES: The individual features of each vendor daemon to graph.
|
|
|
|
# If no features are given, all features
|
|
|
|
# reported by vendor daemon are treated to graph.
|
2009-08-10 17:41:59 +02:00
|
|
|
# - LMDISPLAYNAME: use the LMDISPLAYNAME instead of the daemon name when
|
2012-06-25 19:15:50 +02:00
|
|
|
# generating graph names
|
|
|
|
# - LMGRAPHISSUED: If set generate a graph of the number of licenses issued for
|
|
|
|
# each feature.
|
|
|
|
# - LMSTAT: The path to the lmstat binary
|
2009-08-10 17:41:59 +02:00
|
|
|
# - LMLICFILE: The path to the FlexLM License File
|
2010-09-02 22:52:54 +02:00
|
|
|
# - LMLOGARITHMIC If set then graph use a logarithmic scale
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2009-08-10 17:41:59 +02:00
|
|
|
# $Log$
|
|
|
|
# Revision 1.00 20090807 nassarmu
|
|
|
|
# Initial public release.
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2012-06-25 19:15:50 +02:00
|
|
|
# Revision 1.10 20120625 nassarmu@msi.umn.edu
|
|
|
|
# incorporate the rewrite by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
|
2009-08-10 17:41:59 +02:00
|
|
|
#
|
|
|
|
# Magic markers:
|
|
|
|
#%# family=licensing
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
2012-06-25 19:15:50 +02:00
|
|
|
use Class::Struct;
|
|
|
|
use English qw/ $PROGRAM_NAME /;
|
2009-08-10 17:41:59 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
# What daemon are we going to graph? if none specified exit.
|
2012-06-25 19:15:50 +02:00
|
|
|
$PROGRAM_NAME =~ /flexlm_(.+)*$/;
|
|
|
|
our $DAEMON = $1;
|
|
|
|
exit 2 unless defined $DAEMON;
|
|
|
|
our $munincommand;
|
2009-08-10 17:41:59 +02:00
|
|
|
|
|
|
|
# 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
|
2012-06-25 19:15:50 +02:00
|
|
|
# This would also allow you to theoretically support multiple flexlmds
|
2009-08-10 17:41:59 +02:00
|
|
|
# via different license files.
|
2012-06-25 19:15:50 +02:00
|
|
|
our $LMSTAT = $ENV{'LMSTAT'} || '/opt/local/flexlm/bin/lmstat';
|
|
|
|
our $LMLICFILE = $ENV{'LMLICFILE'} || '/opt/local/flexlm/license/license.dat';;
|
2009-08-10 17:41:59 +02:00
|
|
|
|
2012-06-25 19:15:50 +02:00
|
|
|
&struct( feature => { name => '$', cleanname => '$', max => '$', used => '$' } );
|
2009-08-10 17:41:59 +02:00
|
|
|
|
2012-06-25 19:15:50 +02:00
|
|
|
sub lmstat {
|
|
|
|
my @feature;
|
|
|
|
open( my $ph, sprintf('%s -c %s -S %s|', $LMSTAT, $LMLICFILE, $DAEMON) ) or exit 2;
|
|
|
|
while( <$ph> ){
|
|
|
|
if( my( $name ) = m/\AUsers of ([^:]+):/ ){
|
|
|
|
my $x = feature->new( name => $name, max => 0, used => 0 );
|
|
|
|
$name =~ s/^[^A-Za-z_]+/_/;
|
|
|
|
$name =~ s/[^A-Za-z0-9_]/_/g;
|
|
|
|
$x->cleanname( $name );
|
|
|
|
m/Total of (\d+) licenses? issued/ and $x->max( $1 );
|
|
|
|
m/Total of (\d+) licenses? in use/ and $x->used( $1 );
|
|
|
|
push( @feature, $x );
|
2010-09-02 22:52:54 +02:00
|
|
|
}
|
2012-06-25 19:15:50 +02:00
|
|
|
elsif( m/\A\s+(\d+) RESERVATIONs? for / ){
|
|
|
|
$feature[-1]->used( $feature[-1]->used - $1 );
|
2010-09-02 22:52:54 +02:00
|
|
|
}
|
2012-06-25 19:15:50 +02:00
|
|
|
}
|
|
|
|
if( $ENV{'LMFEATURES'} ){
|
|
|
|
my %table;
|
|
|
|
for( split( /\s+/, $ENV{'LMFEATURES'} ) ){
|
|
|
|
$table{$_}++;
|
2009-08-10 17:41:59 +02:00
|
|
|
}
|
2012-06-25 19:15:50 +02:00
|
|
|
grep( $table{$_->name}, @feature );
|
|
|
|
} else {
|
|
|
|
@feature;
|
|
|
|
}
|
2009-08-10 17:41:59 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 19:15:50 +02:00
|
|
|
if ( $ARGV[0] ) {
|
|
|
|
$munincommand = $ARGV[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$munincommand = 'none';
|
|
|
|
}
|
2010-09-02 22:52:54 +02:00
|
|
|
|
2012-06-25 19:15:50 +02:00
|
|
|
if( $munincommand eq 'autoconf' ){
|
|
|
|
if( &lmstat > 0 ){
|
|
|
|
print "yes\n";
|
|
|
|
} else {
|
|
|
|
print "no\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif( $munincommand eq 'config' ){
|
|
|
|
printf "graph_title FlexLM License usage for %s\n", $ENV{'LMDISPLAYNAME'} || $DAEMON;
|
|
|
|
if( $ENV{'LMLOGARITHMIC'} ){
|
|
|
|
print "graph_args --base 1000 --vertical-label licenses --lower-limit 0.01 --logarithmic\n";
|
|
|
|
} else {
|
|
|
|
print "graph_args --base 1000 --vertical-label licenses -l 0\n";
|
|
|
|
}
|
2017-02-24 00:13:44 +01:00
|
|
|
print "graph_category other\n";
|
2012-06-25 19:15:50 +02:00
|
|
|
print "graph_period minute\n";
|
|
|
|
for my $x ( &lmstat ){
|
|
|
|
printf "%s.label %s\n", $x->cleanname, $x->name;
|
|
|
|
printf "%s.draw LINE2\n", $x->cleanname;
|
|
|
|
printf "%s.info The number of %s licenses checked out\n", $x->cleanname, $x->name;
|
|
|
|
if( $ENV{'LMGRAPHISSUED'} ){
|
|
|
|
printf "%smax.label %s max\n", $x->cleanname, $x->name;
|
|
|
|
printf "%smax.draw LINE3\n", $x->cleanname;
|
|
|
|
printf "%smax.info The total number of %s licenses available\n", $x->cleanname, $x->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for my $x ( &lmstat ){
|
|
|
|
printf "%s.value %d\n", $x->cleanname, $x->used;
|
|
|
|
if( $ENV{'LMGRAPHISSUED'} ){
|
|
|
|
printf "%smax.value %d\n", $x->cleanname, $x->max;
|
2009-08-10 17:41:59 +02:00
|
|
|
}
|
2012-06-25 19:15:50 +02:00
|
|
|
}
|
2009-08-10 17:41:59 +02:00
|
|
|
}
|
2012-06-25 19:15:50 +02:00
|
|
|
exit 0;
|