Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / licensing / flexlm_ @ bde6d7b9

Historique | Voir | Annoter | Télécharger (4,66 ko)

1
#!/usr/bin/perl
2
# -*- perl -*-
3
#
4
# Copyright 2009 by the Regents of the University of Minnesota
5
# Written by Munir Nassar <nassarmu@msi.umn.edu>
6
# Rewrite contribution by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
7
#    This program is free software: you can redistribute it and/or modify
8
#    it under the terms of the GNU General Public License as published by
9
#    the Free Software Foundation, either version 3 of the License, or
10
#    (at your option) any later version.
11
#
12
#    This program is distributed in the hope that it will be useful,
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
#    GNU General Public License for more details.
16
#
17
#    You should have received a copy of the GNU General Public License
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
#
20
# The Minnesota Supercomputing Institute http://www.msi.umn.edu sponsored
21
#	the development of this software.
22
#
23
# Requirements:
24
#	- lmstat
25
#
26
# Note:
27
#	- You must provide the daemon name as it is listed in the flexlm license
28
#    if you want it displayed differently use the LMDISPLAYNAME variable
29
#
30
# Parameters supported:
31
#  - config
32
#  - autoconf
33
#
34
# Configuration variables
35
#  - LMFEATURES:	The individual features of each vendor daemon to graph.
36
#			If no features are given, all features
37
#			reported by vendor daemon are treated to graph.
38
#  - LMDISPLAYNAME:	use the LMDISPLAYNAME instead of the daemon name when
39
#			generating graph names
40
#  - LMGRAPHISSUED:	If set generate a graph of the number of licenses issued for
41
#			each feature.
42
#  - LMSTAT:		The path to the lmstat binary
43
#  - LMLICFILE:		The path to the FlexLM License File
44
#  - LMLOGARITHMIC	If set then graph use a logarithmic scale
45
#  
46
# $Log$
47
# Revision 1.00	20090807	nassarmu
48
# Initial public release.
49
# 
50
# Revision 1.10 20120625 nassarmu@msi.umn.edu
51
# incorporate the rewrite by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
52
#
53
# Magic markers:
54
#%# family=licensing
55
#%# capabilities=autoconf
56

    
57
use Class::Struct;
58
use English qw/ $PROGRAM_NAME /;
59
use strict;
60
use warnings;
61

    
62
# What daemon are we going to graph? if none specified exit.
63
$PROGRAM_NAME =~ /flexlm_(.+)*$/;
64
our $DAEMON = $1;
65
exit 2 unless defined $DAEMON;
66
our $munincommand;
67

    
68
# This section is for some optional values, the defaults may work for you
69
# if not then i recommend setting these option via plugin-conf.d
70
# This would also allow you to theoretically support multiple flexlmds
71
# via different license files.
72
our $LMSTAT = $ENV{'LMSTAT'} || '/opt/local/flexlm/bin/lmstat';
73
our $LMLICFILE = $ENV{'LMLICFILE'} || '/opt/local/flexlm/license/license.dat';;
74

    
75
&struct( feature => { name => '$', cleanname => '$', max => '$', used => '$' } );
76

    
77
sub lmstat {
78
    my @feature;
79
    open( my $ph, sprintf('%s -c %s -S %s|', $LMSTAT, $LMLICFILE, $DAEMON) ) or exit 2;
80
    while( <$ph> ){
81
	if( my( $name ) = m/\AUsers of ([^:]+):/ ){
82
	    my $x = feature->new( name => $name, max => 0, used => 0 );
83
	    $name =~ s/^[^A-Za-z_]+/_/;
84
	    $name =~ s/[^A-Za-z0-9_]/_/g;
85
	    $x->cleanname( $name );
86
	    m/Total of (\d+) licenses? issued/ and $x->max( $1 );
87
	    m/Total of (\d+) licenses? in use/ and $x->used( $1 );
88
	    push( @feature, $x );
89
	}
90
	elsif( m/\A\s+(\d+) RESERVATIONs? for / ){
91
	    $feature[-1]->used( $feature[-1]->used - $1 );
92
	}
93
    }
94
    if( $ENV{'LMFEATURES'} ){
95
	my %table;
96
	for( split( /\s+/, $ENV{'LMFEATURES'} ) ){
97
	    $table{$_}++;
98
	}
99
	grep( $table{$_->name}, @feature );
100
    } else {
101
	@feature;
102
    }
103
}
104

    
105
if ( $ARGV[0] ) {
106
	$munincommand = $ARGV[0];
107
}
108
else {
109
	$munincommand = 'none';
110
}
111

    
112
if( $munincommand eq 'autoconf' ){
113
    if( &lmstat > 0 ){
114
	print "yes\n";
115
    } else {
116
	print "no\n";
117
    }
118
}
119
elsif( $munincommand eq 'config' ){
120
    printf "graph_title FlexLM License usage for %s\n", $ENV{'LMDISPLAYNAME'} || $DAEMON;
121
    if( $ENV{'LMLOGARITHMIC'} ){
122
	print "graph_args --base 1000 --vertical-label licenses --lower-limit 0.01 --logarithmic\n";
123
    } else {
124
	print "graph_args --base 1000 --vertical-label licenses -l 0\n";
125
    }
126
    print "graph_category licensing\n";
127
    print "graph_period minute\n";
128
    for my $x ( &lmstat ){
129
	printf "%s.label %s\n", $x->cleanname, $x->name;
130
	printf "%s.draw LINE2\n", $x->cleanname;
131
	printf "%s.info The number of %s licenses checked out\n", $x->cleanname, $x->name;
132
	if( $ENV{'LMGRAPHISSUED'} ){
133
	    printf "%smax.label %s max\n", $x->cleanname, $x->name;
134
	    printf "%smax.draw LINE3\n", $x->cleanname;
135
	    printf "%smax.info The total number of %s licenses available\n", $x->cleanname, $x->name;
136
	}
137
    }
138
}
139
else {
140
    for my $x ( &lmstat ){
141
	printf "%s.value %d\n", $x->cleanname, $x->used;
142
	if( $ENV{'LMGRAPHISSUED'} ){
143
	    printf "%smax.value %d\n", $x->cleanname, $x->max;
144
	}
145
    }
146
}
147
exit 0;