mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Merge pull request #136 from nassarmu/master
Updated flexlm license watcher plugin
This commit is contained in:
commit
10fbfe9a1c
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# -*- perl -*-
|
# -*- perl -*-
|
||||||
#
|
#
|
||||||
# Copyright 2009 by the Regents of the University of Minnesota
|
# Copyright 2009 by the Regents of the University of Minnesota
|
||||||
# Written by Munir Nassar <nassarmu@msi.umn.edu>
|
# Written by Munir Nassar <nassarmu@msi.umn.edu>
|
||||||
#
|
# Rewrite contribution by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -19,131 +19,129 @@
|
|||||||
#
|
#
|
||||||
# The Minnesota Supercomputing Institute http://www.msi.umn.edu sponsored
|
# The Minnesota Supercomputing Institute http://www.msi.umn.edu sponsored
|
||||||
# the development of this software.
|
# the development of this software.
|
||||||
#
|
#
|
||||||
# Requirements:
|
# Requirements:
|
||||||
# - lmstat
|
# - lmstat
|
||||||
#
|
#
|
||||||
# Note:
|
# Note:
|
||||||
# - You must provide the daemon name as it is listed in the flexlm license
|
# - You must provide the daemon name as it is listed in the flexlm license
|
||||||
# if you want it displayed differently use the LMDISPLAYNAME variable
|
# if you want it displayed differently use the LMDISPLAYNAME variable
|
||||||
#
|
#
|
||||||
# Parameters supported:
|
# Parameters supported:
|
||||||
# - config
|
# - config
|
||||||
# - autoconf
|
# - autoconf
|
||||||
#
|
#
|
||||||
# Configuration variables
|
# Configuration variables
|
||||||
# - LMFEATURES: The individual features of each vendor daemon to graph
|
# - 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.
|
||||||
# - LMDISPLAYNAME: use the LMDISPLAYNAME instead of the daemon name when
|
# - LMDISPLAYNAME: use the LMDISPLAYNAME instead of the daemon name when
|
||||||
# generating graph names
|
# generating graph names
|
||||||
# - LMGRAPHISSUED: If set generate a graph of the number of licenses issued for
|
# - LMGRAPHISSUED: If set generate a graph of the number of licenses issued for
|
||||||
# each feature.
|
# each feature.
|
||||||
# - LMSTAT: The path to the lmstat binary
|
# - LMSTAT: The path to the lmstat binary
|
||||||
# - LMLICFILE: The path to the FlexLM License File
|
# - LMLICFILE: The path to the FlexLM License File
|
||||||
# - LMLOGARITHMIC If set then graph use a logarithmic scale
|
# - LMLOGARITHMIC If set then graph use a logarithmic scale
|
||||||
#
|
#
|
||||||
# $Log$
|
# $Log$
|
||||||
# Revision 1.00 20090807 nassarmu
|
# Revision 1.00 20090807 nassarmu
|
||||||
# Initial public release.
|
# Initial public release.
|
||||||
|
#
|
||||||
|
# Revision 1.10 20120625 nassarmu@msi.umn.edu
|
||||||
|
# incorporate the rewrite by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
|
||||||
#
|
#
|
||||||
# Magic markers:
|
# Magic markers:
|
||||||
#%# family=licensing
|
#%# family=licensing
|
||||||
#%# capabilities=autoconf
|
#%# capabilities=autoconf
|
||||||
|
|
||||||
|
use Class::Struct;
|
||||||
|
use English qw/ $PROGRAM_NAME /;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Munin::Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
# What daemon are we going to graph? if none specified exit.
|
# What daemon are we going to graph? if none specified exit.
|
||||||
$0 =~ /flexlm_(.+)*$/;
|
$PROGRAM_NAME =~ /flexlm_(.+)*$/;
|
||||||
my $daemon = $1;
|
our $DAEMON = $1;
|
||||||
exit 2 unless defined $daemon;
|
exit 2 unless defined $DAEMON;
|
||||||
|
our $munincommand;
|
||||||
# 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
|
# 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
|
# if not then i recommend setting these option via plugin-conf.d
|
||||||
# This would also allow you to theoretically support multiple flexlmds
|
# This would also allow you to theoretically support multiple flexlmds
|
||||||
# via different license files.
|
# via different license files.
|
||||||
our $lmstat;
|
our $LMSTAT = $ENV{'LMSTAT'} || '/opt/local/flexlm/bin/lmstat';
|
||||||
our $lmlicfile;
|
our $LMLICFILE = $ENV{'LMLICFILE'} || '/opt/local/flexlm/license/license.dat';;
|
||||||
our $lmdisplayname;
|
|
||||||
if ( $ENV{'LMSTAT'} ) {
|
&struct( feature => { name => '$', cleanname => '$', max => '$', used => '$' } );
|
||||||
$lmstat = $ENV{'LMSTAT'};
|
|
||||||
} else {
|
sub lmstat {
|
||||||
$lmstat = "/opt/local/flexlm/bin/lmstat";
|
my @feature;
|
||||||
}
|
open( my $ph, sprintf('%s -c %s -S %s|', $LMSTAT, $LMLICFILE, $DAEMON) ) or exit 2;
|
||||||
if ( $ENV{'LMLICFILE'} ) {
|
while( <$ph> ){
|
||||||
$lmlicfile = $ENV{'LMLICFILE'};
|
if( my( $name ) = m/\AUsers of ([^:]+):/ ){
|
||||||
} else {
|
my $x = feature->new( name => $name, max => 0, used => 0 );
|
||||||
$lmlicfile = "/opt/local/flexlm/license/license.dat";
|
$name =~ s/^[^A-Za-z_]+/_/;
|
||||||
}
|
$name =~ s/[^A-Za-z0-9_]/_/g;
|
||||||
if ( $ENV{'LMDISPLAYNAME'} ) {
|
$x->cleanname( $name );
|
||||||
$lmdisplayname = $ENV{'LMDISPLAYNAME'};
|
m/Total of (\d+) licenses? issued/ and $x->max( $1 );
|
||||||
} else {
|
m/Total of (\d+) licenses? in use/ and $x->used( $1 );
|
||||||
$lmdisplayname = $daemon;
|
push( @feature, $x );
|
||||||
|
}
|
||||||
|
elsif( m/\A\s+(\d+) RESERVATIONs? for / ){
|
||||||
|
$feature[-1]->used( $feature[-1]->used - $1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( $ENV{'LMFEATURES'} ){
|
||||||
|
my %table;
|
||||||
|
for( split( /\s+/, $ENV{'LMFEATURES'} ) ){
|
||||||
|
$table{$_}++;
|
||||||
|
}
|
||||||
|
grep( $table{$_->name}, @feature );
|
||||||
|
} else {
|
||||||
|
@feature;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse LMFEATURES
|
if ( $ARGV[0] ) {
|
||||||
my @features = split(/\s+/, $ENV{'LMFEATURES'});
|
$munincommand = $ARGV[0];
|
||||||
|
}
|
||||||
# try and recommend autoconf (this will most likely result in a yes)
|
else {
|
||||||
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
$munincommand = 'none';
|
||||||
if ( scalar @features >= 1 ) {
|
|
||||||
print "yes\n";
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print "no\n";
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# print out a config screen when asked.
|
if( $munincommand eq 'autoconf' ){
|
||||||
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
if( &lmstat > 0 ){
|
||||||
print "graph_title FlexLM License usage for $lmdisplayname\n";
|
print "yes\n";
|
||||||
if ( $ENV{'LMLOGARITHMIC'} ) {
|
} else {
|
||||||
print "graph_args --base 1000 --vertical-label licenses --lower-limit 0.01 --logarithmic\n";
|
print "no\n";
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
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\n";
|
|
||||||
print "$clean_feature".".draw LINE2\n";
|
|
||||||
print "$clean_feature".".info The number of $feature licenses checked out\n";
|
|
||||||
if ( $ENV{'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
|
|
||||||
}
|
}
|
||||||
|
elsif( $munincommand eq 'config' ){
|
||||||
my @results = `$lmstat -c $lmlicfile -S $daemon`;
|
printf "graph_title FlexLM License usage for %s\n", $ENV{'LMDISPLAYNAME'} || $DAEMON;
|
||||||
|
if( $ENV{'LMLOGARITHMIC'} ){
|
||||||
# pull the info from lmstat and print the results
|
print "graph_args --base 1000 --vertical-label licenses --lower-limit 0.01 --logarithmic\n";
|
||||||
foreach my $feature (@features) {
|
} else {
|
||||||
my @results = grep(/Users of $feature/, @results);
|
print "graph_args --base 1000 --vertical-label licenses -l 0\n";
|
||||||
|
}
|
||||||
foreach my $result (@results) {
|
print "graph_category licensing\n";
|
||||||
if ($result =~ m/Users of $feature\:/ ) {
|
print "graph_period minute\n";
|
||||||
chomp ($result);
|
for my $x ( &lmstat ){
|
||||||
my (@fields) = split( m/\s+/, $result);
|
printf "%s.label %s\n", $x->cleanname, $x->name;
|
||||||
|
printf "%s.draw LINE2\n", $x->cleanname;
|
||||||
my $clean_feature = clean_fieldname($feature);
|
printf "%s.info The number of %s licenses checked out\n", $x->cleanname, $x->name;
|
||||||
print "$clean_feature".".value $fields[10]\n";
|
if( $ENV{'LMGRAPHISSUED'} ){
|
||||||
if ( $ENV{'LMGRAPHISSUED'} ) {
|
printf "%smax.label %s max\n", $x->cleanname, $x->name;
|
||||||
print "$clean_feature"."max.value $fields[5]\n";
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user