I wanted to be able to monitor usage on my FlexLM based license server, but was unable to find much to help out. Instead, I wrote my very first external script and figured I'd share it here for anybody else that may be interested.
You first need to have lmutil working on your system. I was able to download it for my CentOS 6 system place it in /usr/local/bin. If you place the utility in another directory, you'll need to update the script below.
This is not a LLD based script in any way, shape or form. Once you have the script in your externalscripts directory, you'll need to manually create two items for each license you want to monitor:
(Make sure you change the port, if necessary, and the feature.)
You can then setup a trigger for the --issued item (.last(0)=0) if you desire to get an alert when it doesn't detect any issued licenses. You can also set up graphs if you so desire.
lmstat.pl:
You first need to have lmutil working on your system. I was able to download it for my CentOS 6 system place it in /usr/local/bin. If you place the utility in another directory, you'll need to update the script below.
This is not a LLD based script in any way, shape or form. Once you have the script in your externalscripts directory, you'll need to manually create two items for each license you want to monitor:
- lmstat.pl[-H,{HOST.CONN},-p,27000,-f,feature,--issued]
- lmstat.pl[-H,{HOST.CONN},-p,27000,-f,feature,--used]
(Make sure you change the port, if necessary, and the feature.)
You can then setup a trigger for the --issued item (.last(0)=0) if you desire to get an alert when it doesn't detect any issued licenses. You can also set up graphs if you so desire.
lmstat.pl:
PHP Code:
#!/usr/bin/perl
use strict;
use Switch;
my $lmutil = '/usr/local/bin/lmutil';
sub usage {
print <<_END_USAGE_;
This utility uses the 'lmutil' application to gather information from FlexLM.
You must have 'lmutil' installed and accessible. This utility only returns
either the number of issued licenses or the number of licenses in use.
Usage:
lmstat.pl -H <hostname> -p <port> -f <feature> (--issued|--used)
-H <hostname>
The hostname or IP address of the license server
-p <port>
The port number for the license you want to gather information for.
-f <feature>
Feature name
(--issued|--used)
Specify which statistic you want want information for.
_END_USAGE_
exit;
}
if ($ARGV[0] eq '--help') {
usage();
}
# Get configuration information for the running of this script
my ($hostname, $port, $feature, $stat);
while (my $s = shift(@ARGV)) {
switch($s) {
case "-H" { $hostname = shift(@ARGV); }
case "-p" { $port = shift(@ARGV); }
case "-f" { $feature = shift(@ARGV); }
case "--issued" { $stat = 'issued'; }
case "--used" { $stat = 'used'; }
else { print "INVALID SYNTAX\n\n"; usage(); }
}
}
my $lmstat_out = `$lmutil lmstat -f $feature -c $port\@$hostname`;
my $value = "";
foreach my $line (split("\n", $lmstat_out)) {
if ($line =~ /Users of \Q$feature\E:.+Total of ([0-9]+) licenses? issued;\s+Total of ([0-9]+) licenses? in use/) {
switch ($stat) {
case "issued" { $value = $1; }
case "used" { $value = $2; }
}
}
}
# We do this because we can't seem to trigger on 'nodata'
if ($stat eq 'issued' && $value eq '') {
# If we're looking for how many licenses are issued and we got nothing,
# then return a value of '0'. Keep the blank (error) for used licenses.
$value = 0;
}
print "$value\n";
Comment