Brian Madden Logo
Your independent source for application and desktop virtualization.
Marketplace

advertisement
Guest Bloggers's Blog

Graphing Citrix Session use with open source tools

Written on Jan 31 2006 11,043 views, 51 comments


by John Ferrell

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>/CTXsvcClient.py`
Options[citrix.sessions]: gauge,growright
kMG[citrix.sessions]: ,M,G,T,P
## MaxBytes should be concurrent connection limit (license limit)
MaxBytes[citrix.sessions]:45
YLegend[citrix.sessions]: Citrix Sessions
ShortLEgend[citrix.sessions]: Citrix Sessions
Legend1[citrix.sessions]: Citrx Sessions
Legend2[citrix.sessions]:
Legend3[citrix.sessions]: Citrix Sessions
Legend4[citrix.sessions]:
LegendI[citrix.sessions]: &nbsp;Citrix Sessions
LegendO[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.

http://<servername>/citrix/citrix.sessions.html

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.

Conclusion

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.


RemoteSessions-1.01.zip


Comments

John Ferrell wrote Download corrupt
on 01-31-2006 12:30 PM
For some reason the attachment is corrupt.  Until a new one is posted you can download the zip [link=http:  
John
 
 
Guest wrote RE: Download corrupt
on 01-31-2006 4:44 PM
 
Something else that looks pretty neat is:
 
http://rrdtool.deliver3.com/gallery/jason-01.html
 
It seems like you could use many of the win32_ts* calls to get this information as well.  I'm not sure if there are any good, bad, or ugly concepts to the various methods.
Guest wrote another option
on 01-31-2006 5:55 PM
we use a great little free snmp extention agent snmp4ctx
http://www.wtcs.org/snmp4tpc/snmp4ctx.htm
 
and cacti for collecting the data into rrd
http://www.cacti.net/
 
works well
Guest wrote RE: another option
on 01-31-2006 9:55 PM
 
Is there any way to monitor normal RDP traffic for the non-Citrix environments?  (Sorry if that is an amateur question...)  I've been searching on the web trying to find related info.
 
Thanks
John Ferrell wrote RE: another option
on 01-31-2006 11:14 PM
If you want to graph RDP sessions, the code can be changed to do so.  It is a very simple change.  Send me an email; I will be glad to help.
 
John  
Guest wrote telnet Connection to 35000
on 02-01-2006 5:30 PM
I tried to use this tools but it seems like cannot telnet using port 35000. I get following error message. Citrix session services is running fine. 

"Connection to host lost".
 
Thanks for the help
 

 
 
 
 
Guest wrote RE: another option
on 02-01-2006 7:43 PM
I installed the tools but have problem telnet to the Citrix server using 35000 port. when i run "telnet localhost 35000" the server comes back with error.
 
connection lost to host.
 
Thanks
John Ferrell wrote RE: telnet Connection to 35000
on 02-01-2006 9:36 PM
Sounds like it is connecting.  If it was not connecting you would receive an error similar to the following:
 
Connecting To localhost...Could not open connection to the host, on port 35000: Connect failed
 
In the config file set 'debug' to true and check the qwinstaCMD path.  Try connecting a few times and then take a look at the event log.
 
Let me know what happens.
 
John
Guest wrote RE: telnet Connection to 35000
on 02-01-2006 11:11 PM
When I start the Citrix session services. I get following in application event viewer.
 
1. The CTXsvc service has started (CTXsvc).
2. Citrix session service - version: .07
Bind IP: 0.0.0.0
Port: 35000
Command path: u:\windows\system32\qwinsta.exe
Debug: true
 
When I run "telnet localhost 35000" from command prompt, I get following in application event viewer.
 

qwinsta:

 
Thanks for your help.
 
Beav wrote RE: telnet Connection to 35000
on 02-02-2006 12:24 AM
 
Are you using the telnet command at a DOS prompt or are you using a different application?
 
I believe that the connection lost statement is fine since that is what I receive as well.  But that message is displayed after it prints off the time and user count.
 
 
Guest wrote another nice tool based on RRDTool
on 02-02-2006 7:30 AM
http:
To implement the whole monitoring solution including the collector, data consolidation and graphing, the following system components are required: 
Windows XP, 2000 or 2003 Server for collection.
Microsoft .NET Framework 1.1
IIS 5.0 or 6.0 with ASP enabled to display results of consolidated data graphs
VBScript 5.6 to run the scripts supplied.
WMI 1.5 (only required on XP, 2000 or 2003) on target systems
Steve DV
Guest wrote RE: telnet Connection to 35000
on 02-02-2006 10:04 AM
I am using the telnet command at a DOS prompt. I also get message that displayed after it prints off the time and user count.
 
But when we run CTXsvcclient.py from Linux box, the ouput display two lines with zero. 
0
0
We also received E-mail stating "Could not connect (Citrix server) on port 35000.
 
Thanks for help.

 
John Ferrell wrote RE: telnet Connection to 35000
on 02-02-2006 11:02 AM
From your Linux box telnet to the Citrix server's port:
 
$ telnet <citrix_server> <port>
 
If it works, you should get the same output you get when you run telnet locally on the Citrix server.  If you cannot connect there may be something blocking traffic to the port (Windows firewall?).
 
John
 
 
John Ferrell wrote RE: telnet Connection to 35000
on 02-02-2006 11:18 AM
Hmmm, the service is working.  If you can connect you should atleast see the current time.
 
This weekend I will add some more debugging code.  Send me an email and I will send you an updated version.
 
John
Joseph Duncan wrote rrd is fun ;)
on 02-02-2006 12:49 PM
here is what i use on my test ts
http://mpk.lowone.org/cgi-bin/rrdcgi.cgi
(wraper/ui writen by me)

i have another one for my production servers but cant give it out per policy
Guest wrote No Graph
on 02-03-2006 8:07 AM
I did the installation just like you described it in your install.txt
The only thing is that I also got the "connection lost" message when i'm using the telnet localhost 35000 command.

When I run 'perl mrtg citrixsession.cfg' from the client it creates the html output but the mrtg graphs are empty.

Thnx
Greets,
Dennis
Guest wrote RE: No Graph
on 02-03-2006 10:00 AM
Is this script working on non-english 2003 terminal servers?
Guest wrote RE: telnet Connection to 35000
on 02-03-2006 10:27 AM
Finally it's working fine now. The problem was that we had Debugging enabled on Citrix servers. Now we are trying to modify htlm (citrix.sessions.html file) to insert the company's logo and other information. We noticed that the file update every time. How can me modify this default behavior.
 
Thank for all the help.
 
Guest wrote RE: No Graph
on 02-03-2006 10:30 AM
Make sure debugg is not enable on Citrix servers.
Guest wrote Modify Citrix.session.html file
on 02-05-2006 10:30 AM
We are trying to modify htlm (citrix.sessions.html file) to insert the company's logo and other information. We noticed that the file update every time. How can me modify this default behavior.
 
Thank for all the help.
Joe McGaugh wrote RE: Modify Citrix.session.html file
on 02-05-2006 6:47 PM
i'm assuming that your trying to modify the "citrix logo" at the top left of the WI page?  what version are you running?
Guest wrote RE: No Graph
on 02-06-2006 4:02 AM
debug is set to false in ctxscv.ini
I've installed the service on two citrix boxes. Telnet test is ok.
But the mrtg graph is still empty. Did I forget something?