Projet

Général

Profil

Révision bde6d7b9

IDbde6d7b9cbcd7b13c8afd1f842f5d12c40ff44f9
Parent 868fab52
Enfant 10fbfe9a

Ajouté par Munir Nassar il y a plus de 13 ans

incorporate rewrite provided by TSUCHIYA Masatoshi <>

Voir les différences:

plugins/licensing/flexlm_
1 1
#!/usr/bin/perl
2 2
# -*- perl -*-
3
# 
3
#
4 4
# Copyright 2009 by the Regents of the University of Minnesota
5 5
# Written by Munir Nassar <nassarmu@msi.umn.edu>
6
#
6
# Rewrite contribution by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
7 7
#    This program is free software: you can redistribute it and/or modify
8 8
#    it under the terms of the GNU General Public License as published by
9 9
#    the Free Software Foundation, either version 3 of the License, or
......
19 19
#
20 20
# The Minnesota Supercomputing Institute http://www.msi.umn.edu sponsored
21 21
#	the development of this software.
22
# 
22
#
23 23
# Requirements:
24 24
#	- lmstat
25 25
#
26 26
# Note:
27 27
#	- You must provide the daemon name as it is listed in the flexlm license
28 28
#    if you want it displayed differently use the LMDISPLAYNAME variable
29
# 
29
#
30 30
# Parameters supported:
31 31
#  - config
32 32
#  - autoconf
33
# 
33
#
34 34
# Configuration variables
35
#  - LMFEATURES:		The individual features of each vendor daemon to graph
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.
36 38
#  - LMDISPLAYNAME:	use the LMDISPLAYNAME instead of the daemon name when
37
#							generating graph names
38
#	- LMGRAPHISSUED:	If set generate a graph of the number of licenses issued for 
39
#							each feature.
40
#  - LMSTAT:			The path to the lmstat binary
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
41 43
#  - LMLICFILE:		The path to the FlexLM License File
42 44
#  - LMLOGARITHMIC	If set then graph use a logarithmic scale
43 45
#  
44 46
# $Log$
45 47
# Revision 1.00	20090807	nassarmu
46 48
# Initial public release.
49
# 
50
# Revision 1.10 20120625 nassarmu@msi.umn.edu
51
# incorporate the rewrite by TSUCHIYA Masatoshi <tsuchiya@namazu.org>
47 52
#
48 53
# Magic markers:
49 54
#%# family=licensing
50 55
#%# capabilities=autoconf
51 56

  
57
use Class::Struct;
58
use English qw/ $PROGRAM_NAME /;
52 59
use strict;
53 60
use warnings;
54
use Munin::Plugin;
55

  
56 61

  
57 62
# What daemon are we going to graph? if none specified exit.
58
$0 =~ /flexlm_(.+)*$/;   
59
my $daemon = $1;
60
exit 2 unless defined $daemon;
61

  
62
# LMFEATURES should be provided by plugin-conf.d space delimited 
63
if ( ! $ENV{'LMFEATURES'} ) {
64
	print "You must provide a list of FlexLM features to monitor via the LMFEATURES variable.\n";
65
	exit 1
66
}
63
$PROGRAM_NAME =~ /flexlm_(.+)*$/;
64
our $DAEMON = $1;
65
exit 2 unless defined $DAEMON;
66
our $munincommand;
67 67

  
68 68
# This section is for some optional values, the defaults may work for you
69 69
# if not then i recommend setting these option via plugin-conf.d
70
# This would also allow you to theoretically support multiple flexlmds 
70
# This would also allow you to theoretically support multiple flexlmds
71 71
# via different license files.
72
our $lmstat;
73
our $lmlicfile;
74
our $lmdisplayname;
75
if ( $ENV{'LMSTAT'} ) {
76
	$lmstat = $ENV{'LMSTAT'};
77
} else {
78
	$lmstat = "/opt/local/flexlm/bin/lmstat";
79
}
80
if ( $ENV{'LMLICFILE'} ) {
81
	$lmlicfile = $ENV{'LMLICFILE'};
82
} else {
83
	$lmlicfile = "/opt/local/flexlm/license/license.dat";
84
}
85
if ( $ENV{'LMDISPLAYNAME'} ) {
86
	$lmdisplayname = $ENV{'LMDISPLAYNAME'};
87
} else {
88
	$lmdisplayname = $daemon;
89
}
72
our $LMSTAT = $ENV{'LMSTAT'} || '/opt/local/flexlm/bin/lmstat';
73
our $LMLICFILE = $ENV{'LMLICFILE'} || '/opt/local/flexlm/license/license.dat';;
90 74

  
91
# Parse LMFEATURES
92
my @features = split(/\s+/, $ENV{'LMFEATURES'});
93

  
94
# try and recommend autoconf (this will most likely result in a yes)
95
if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) {
96
	if ( scalar @features >= 1 ) {
97
		print "yes\n";
98
		exit 0;
99
	}
100
	else {
101
		print "no\n";
102
		exit 1;
103
	}
104
}
75
&struct( feature => { name => '$', cleanname => '$', max => '$', used => '$' } );
105 76

  
106
# print out a config screen when asked.
107
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
108
	print "graph_title FlexLM License usage for $lmdisplayname\n";
109
	if ( $ENV{'LMLOGARITHMIC'} ) {
110
		print "graph_args --base 1000 --vertical-label licenses --lower-limit 0.01 --logarithmic\n";
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 );
111 89
	}
112
	else {
113
		print "graph_args --base 1000 --vertical-label licenses -l 0\n";
90
	elsif( m/\A\s+(\d+) RESERVATIONs? for / ){
91
	    $feature[-1]->used( $feature[-1]->used - $1 );
114 92
	}
115
	print "graph_category licensing\n";
116
	print "graph_period minute\n";
117
	foreach my $feature (@features) {
118
		my $clean_feature = clean_fieldname($feature);
119
		print "$clean_feature".".label $feature\n";
120
		print "$clean_feature".".draw LINE2\n";
121
		print "$clean_feature".".info The number of $feature licenses checked out\n";
122
		if ( $ENV{'LMGRAPHISSUED'} ) {
123
			print "$clean_feature"."max.label $feature max\n";
124
			print "$clean_feature"."max.draw LINE3\n";
125
			print "$clean_feature"."max.info The total number of $feature licenses available\n";
126
		}
93
    }
94
    if( $ENV{'LMFEATURES'} ){
95
	my %table;
96
	for( split( /\s+/, $ENV{'LMFEATURES'} ) ){
97
	    $table{$_}++;
127 98
	}
128
	exit 0
99
	grep( $table{$_->name}, @feature );
100
    } else {
101
	@feature;
102
    }
129 103
}
130 104

  
131
my @results = `$lmstat -c $lmlicfile -S $daemon`;
105
if ( $ARGV[0] ) {
106
	$munincommand = $ARGV[0];
107
}
108
else {
109
	$munincommand = 'none';
110
}
132 111

  
133
# pull the info from lmstat and print the results
134
foreach my $feature (@features) {
135
	my @results = grep(/Users of $feature/, @results);
136
	
137
	foreach my $result (@results) {
138
		if ($result =~ m/Users of $feature\:/ ) {
139
			chomp ($result);
140
			my (@fields) = split( m/\s+/, $result);
141
	
142
			my $clean_feature = clean_fieldname($feature);
143
			print "$clean_feature".".value $fields[10]\n";
144
			if ( $ENV{'LMGRAPHISSUED'} ) {
145
				print "$clean_feature"."max.value $fields[5]\n";
146
			}
147
		}
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;
148 144
	}
145
    }
149 146
}
147
exit 0;

Formats disponibles : Unified diff