Flexnet License Monitoring With rrdtool

Want to support HowtoForge? Become a subscriber!
 
Submitted by gbi (Contact Author) (Forums) on Tue, 2010-07-13 17:05. :: CentOS | Linux | Ubuntu | Monitoring

Flexnet License Monitoring With rrdtool

Intro

Some of you may know the commercial Flexnet Licencing Application (©Macrovision). It's a client-server based solution for managing the usage of socalled Flexnet-enabled applications. You can hold licenses of more than one product on one license-server. As you typically have to buy licenses and licenses can be expensive it would be nice to have a monitoring solution, to see the utilization of the precious licenses, wether they are underutilized (so money is wasted) or are always fully utilized (so that you can suspect that sometimes people can not do their work, or only delayed) which is also a waste of resources.

As far as I know there are commercial applications for performing such reports, but again you have to spent money. Why not build a simple system yourself, which shows the actual and past usage in an "MRTG style"?

 

Preliminary Note + Disclaimer

In this tutorial I'm going to use some scripts, namely Shell- and Python scripts. I think the whole application should run on every Linux, I did it on CentOS and Ubuntu. We need a webserversoftware which is able to run CGI scripts, I have used the wellknown Apache and also THTTPD, but I believe every webserversoftware should be able to run this application. It is also a perfect extension for my former Network Monitoring Appliance.

The following tutorial describes the way I realized my solution, it is written in a kind of cooking-recipe style. I can not issue any guarantee that you can realize a similar solution.

 

1. Architecture

The architecture of the solution is quite simple, see the picture below:

CGI-Script

We leave the licensing server untouched, but get the necessary information over the network. Therefore we use the lmutil program which belongs to the Flexnet software and not only exists in a Windoze version, but also in a Linux version. As far as I know older versions of lmutil have also been available for HP/UX, Solaris and AIX, so there are chances that also systems running one of those OS'es could be used to build the monitoring system, but I have not tried.

The output of lmutil is filtered the way, that all relevant info could be put into one or more rrd databases, I have used one database for every license. rrd is also used to produce the graphs, directly in a subdirectory of the webserversoftware, from where it could be shown comfortably in a webbrowser.

 

2. Polling the license server

I have copied a recent version of lmutil into /usr/local/bin, and checked wether it is executable:

# ls -l /usr/local/bin/lmutil

-rwxr-xr-x 1 root root 309168 2008-01-08 00:45 /usr/local/bin/lmutil

We can check wether all shared libraries lmutil is linked against, exist on our system:

# ldd /usr/local/bin/lmutil

        linux-gate.so.1 =>  (0xf7796000)
        libpthread.so.0 => /lib32/libpthread.so.0 (0xf7760000)
        libdl.so.2 => /lib32/libdl.so.2 (0xf775c000)
        libc.so.6 => /lib32/libc.so.6 (0xf7601000)
        /lib/ld-linux.so.2 (0xf7797000)

Being a commandline utility lmutil is not linked against a lot of shared libs, so chances are high that they are already installed.

Then I have built a small script for polling all licensing dæmons with licenses for several products running on the licensing server, it looks like:

#!/bin/dash
# Product1
/usr/local/bin/lmutil lmstat -c 27000@licserv -a | /usr/local/sbin/lmrrd.py
# Product2
/usr/local/bin/lmutil lmstat -c 27001@licserv -a | /usr/local/sbin/lmrrd.py

I have used /bin/dash as interpreter for this script, because dash is known to consume less resources than bash, but feel free to use bash if you like. The licensing dæmons for the various products are running on different ports. The output of lmstat is directly piped into a Python script, where all info which is needed is filtered out and put into the appropriate rrd database.

cron is used to establish a 5 minute pollcycle. Therefore an entry in /etc/cron.d/ named rrd is created which looks like:

*/5 8-16 * * 1-5 root LANG=C LC_ALL=C /usr/local/sbin/licenses.sh

We are only interested how the licenses are utilized from monday to friday and from 8am to 5pm.

But before this could be established we first have to create the lmrrd.py script.

 

3. The lmrrd.py script

rrdtool is used as database for this task. rrdtool has different scripting interfaces, namely from shell-, perl-, python- and tcl/tk scripts. I have used python because of it's clean language design and versatility.

This script is used to filter the output of lmutil and puts the relevant information directly into the assigned rrd database. It looks like:

#!/usr/bin/python
# Script to filter the output of lmstat to use it as input for rrd
import sys, string, rrdtool

# searchterm, position of actual value and position of max value in every line
# db is the name for the rrd dbfile
search = [ { 'term':"Users of CL:", 'val':10, 'max':5, 'db':'CL' },
           { 'term':"Users of xyzabc:", 'val':10, 'max':5, 'db':'xyzabc' },
           { 'term':"Users of qwerty:", 'val':10, 'max':5, 'db':'qwerty' } ]
rrddir='/var/rrd/'
# read all lines from stdin 
for line in sys.stdin.readlines():
  # search in every line for the searchterm out of the above array
  for x in search:
    if x[ 'term' ] in line:
      cols = line.split()
      if not cols[ x[ 'max' ] ].isdigit() or not cols[ x[ 'val' ] ].isdigit():
        print "0\n0\n0\n", x[ 'term' ]
      
      # put the values in the assigned rrd dbfile
      rrdtool.update( rrddir + x[ 'db' ] + '.rrd', \
        '--template=value:total', \
        'N:' + cols[ x [ 'val' ] ] + ':' + cols[ x[ 'max' ] ] )

The search terms in the array could be extracted of the output of "lmutil", also the positions of the actual and the maximum possible values of the number of licenses.

You need the python bindings of rrdtool, which can either be found in the package repository of your OS, or on the website of the maintainer of rrdtool.

As implemented this script is run with root permission. The originating rrd files should be world readable, because the following scripts which generate the graphs run only under permission of the owner of the http-server processes, usually www-data or similar.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.