Graphing Citrix Session use with open source tools

In a previous article, I explained the steps taken to configure a Linux Syslog server for collecting and processing Citrix logs for weekly reporting. This article will explain how I enhance the weekly reports with graphs using MRTG (Multi Router Traffic Grapher).

In a previous article, I explained the steps taken to configure a Linux Syslog server for collecting and processing Citrix logs for weekly reporting. This article will explain how I enhance the weekly reports with graphs using MRTG (Multi Router Traffic Grapher).

MRTG is a great tool for graphing network activity and has been adapted for graphing statistics from various server platforms, email traffic, and just about anything else you care to graph.  It is easy to use and is included with several Linux distributions. MRTG is also available for Windows platforms.

Collecting the Data for the Graph

Collecting data from the Citrix servers has been an ever evolving process. WMI and SNMP are not viable options for our organization because we do not run the Enterprise Edition of Citrix.  Since I also wanted to run the reporting tools on a Linux platform, I had to create my own method. 

Initially I used a Perl script to login to the Citrix Web Console and pull the session count from the page. This method was viable when we had only one Metaframe XP server. When we upgraded to Presentation Server 4 and added a few more servers, I needed to develop a new method. 

The second method involved a Perl script and OpenSSH. I installed OpenSSH on my dedicated Zone Data Collector. The Perl script would login to the ZDC via SSH and run the ‘qwinsta’ command against each of the servers in the farm. The output of the ‘qwinsta’ command was parsed and the result was printed for use with MRTG. While this method worked well, it had a couple of downsides: it required an identical account on each Citrix server, and the account needed administrator privileges in order to run ‘qwinsta’ on the remote servers. Ultimately, I needed a better solution.

My current method is a Windows service and a corresponding client script, both written in Python. The client script loops through a list of user specified servers collecting the current session count from the Windows service running on each server. It then totals the session count and outputs it for MRTG. With this method there is no need for special accounts and the data collection process is much faster.

Configuring MRTG

Below is a sample MRTG configuration file. The configuration file tells MRTG where to write the graphs, how the graphs should look, and where to get the data (which in this case is a Python program).

## MRTG config file for Citrix sessions: citrix.cfg
## Path to output files
WorkDir: <webroot>/citrix
## Citrix session count
Title[citrix.sessions]: Citrix Sessions
## Path to data collection script
Target[citrix.sessions]:`python <path>/`
Options[citrix.sessions]: gauge,growright
kMG[citrix.sessions]: ,M,G,T,P
## MaxBytes should be concurrent connection limit (license limit)
YLegend[citrix.sessions]: Citrix Sessions
ShortLEgend[citrix.sessions]: Citrix Sessions
Legend1[citrix.sessions]: Citrx Sessions
Legend3[citrix.sessions]: Citrix Sessions
LegendI[citrix.sessions]: &nbsp;Citrix Sessions
PageTop[citrix.sessions]: <h1>Citrix Sessions</h1>
## Make graphs a bit bigger, default is 400x100
XSize[citrix.sessions]: 600
YSize[citrix.sessions]: 200

The important parameters are ‘WorkDir’ (the path to the graphs, normally a directory within the webroot), ‘Target’ (the path to the Python script), and ‘MaxBytes’ (maximum concurrent sessions).

Note: Be sure to create the ‘WorkDir’ path before running the MRTG command.

Running MRTG

MRTG is run from the command line, using the configuration file as an argument.
<path>/bin/mrtg <path>/citrixSession.cfg

I found that I needed to prepend ‘env LANG=C’ to the command to resolve a LANG environment variable error on my system.

env LANG=C <path>/bin/mrtg <path>/citrixSession.cfg

The first few times I ran the command I received a “rateup warning.” This is normal because the MRTG data files have not yet been created.  Running the command a few more times eliminates the error message. To automate the process I added an entry to the /etc/crontab file so the graphs would be updated every five minutes.

0-59/5 * * * * root  env LANG=C <path>/bin/mrtg <path>/citrixSession.cfg
After 20 minutes or so you can access your MRTG graphs using your favorite web browser.  This page includes daily, weekly, monthly, and yearly average graphs.


Optionally, you can create an index page for the graphs.

<path>/bin/indexmaker <path>/citrix.cfg --output=<webroot>/citrix/index.html

The index page displays only the five minute average graph.  Clicking on the graph will take you to a page with all the graphs.  An example of the four graphs can be found here.


I include a link to the graphs in my weekly report to management. Additionally, in the event that we need an emergency maintenance window, the graphs are useful for determining when the least number of users will be impacted.
You can download a zip of all the files from the attachment at the top of this article. Included in the zip are installation notes, the source code, a compiled version of the Windows service, and the client side script.  If you have any comments or questions, please send me an email.

Dig Deeper on Citrix virtual desktops