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>/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

Join the conversation

51 comments

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

For some reason the attachment is corrupt.  Until a new one is posted you can download the zip [link=http:  
John
 
 
Cancel
 
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.
Cancel
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
Cancel
 
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
Cancel
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  
Cancel
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
 

 
 
 
 
Cancel
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
Cancel
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
Cancel
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.
 
Cancel
 
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.
 
 
Cancel
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
Cancel
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.

 
Cancel
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
 
 
Cancel
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
Cancel
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
Cancel
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
Cancel
Is this script working on non-english 2003 terminal servers?
Cancel
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.
 
Cancel
Make sure debugg is not enable on Citrix servers.
Cancel
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.
Cancel
i'm assuming that your trying to modify the "citrix logo" at the top left of the WI page?  what version are you running?
Cancel
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?
Cancel
Ok it's almost working 
When I use the telnet command the output is:

The current time: 11:44:23
                        Sessions: 0

It looks like it does not count the sessions because there are for sure around the 20 users connected right now.
Is it possible it has anything to do with the language of the operating system??? We are using non-english Windows 2003 servers with
citrix metaframe XP FR3.
Cancel
I have everything working now with the expection of session count. It is reporting 0 sessions. But the graphs are pretty...
Any thoughts?
Cancel
It might be the non-english version of Windows that is causing the problem.  The service runs qwinsta.exe and parses the output to determine the number of sessions.  Here is the code:
 
sessions = 0
qwinstaOut = os.popen(qwinstaCmd).readlines()
for line in qwinstaOut:
     ## Look for active ICA sessions 
     if (((re.search("ICA", line, re.IGNORECASE)) and (re.search("ACTIVE", line, re.IGNORECASE)))):
          sessions = sessions + 1
 
Basically it is looking at each line for the strings "ICA" and "ACTIVE".  Run 'qwinsta.exe' from the command line and take a look at the output.  If the above strings are found within the output it *should* work. 
 
Also, check the qwinstaCmd variable in the config file.  If it is pointing to the wrong location the output will be 0. 
 
I am working on an updated version that offers more error checking and debugging information.  After I test it out for a few more days I will post it.
 
John
Cancel
Rudy,
 
Check the qwinstaCmd variable in the config file.  If it is pointing to the wrong location the output will be 0 (qwinsta.exe probably never ran). 
 
I am working on an updated version that offers more error checking and debugging information.  I will post the new version after a few more days of testing.  (If you are interested in helping to test it send me an email).
 
John
Cancel
The html is updated every 5 minutes by design.  When MRTG updates the graphs it also updated the html files.
 
One way to work around this would be to create your own page with the graphs, bypassing the MRTG generated version all together.  Although, by doing so you would loose the Max and Min session values printed at the bottom of the graph.
 
Another option would be to modify the MRTG code; it is written in Perl.  Just remove the code that prints out the html header and footer.
 
John
Cancel
Thanks. Here's the output of the qwinsta.exe:

C:\Documents and Settings\Administrator>c:\windows\system32\qwinsta.exe
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 console                                                0  Conn     wdcon
 rdp-tcp                                          65536  Listen    rdpwd
 ica-tcp                                          65537  Listen    wdica
>rdp-tcp#34       Administrator                  3  Active   rdpwd
 ica-tcp#37        rudytst1                        2  Active   wdica
 ica-tcp#38        rudytst2                        4  Active   wdica
Cancel
Alright, I restarted the service on the test server and now it's working.

Thanks!
Cancel
I have installed everything and have MRTG running but no stats displayed on the graphs.
telnet command to server locally and remotely shows time and 0 sessions.
qwinsta path is fine. when you run it it shows all the correct details. I have tried adding /counter parameter and still does not display the session details locally or remotely.
Any ideas?
 
M
 
Cancel
In your zip file there is a directory called WindowsSource with a file ctxsvc.py
What about this file? Does it need to be copied to %program files%\CTXsvc\ on the server?


Cancel
ORIGINAL: Guest

In your zip file there is a directory called WindowsSource with a file ctxsvc.py
What about this file? Does it need to be copied to %program files%\CTXsvc\ on the server?

 
The ctxsvc.py file is the source code for the Windows service.  You only need that file if you modify the code and want to recompile.
 
John
Cancel
When you enable debugging, does the event log show the output from 'qwinsta.exe'?
 
John
Cancel
Yes, event log has the details.
I reset all rdp sessions and re-connected, qwinsta shows the session details but when you query remotely it shows time ans active sessions none!
any thoughts?
Cancel
Can you please give me the commands I have to run to recompile the script?
I made a change in this part:

sessions = 0
qwinstaOut = os.popen(qwinstaCmd).readlines()
for line in qwinstaOut:
     ## Look for active ICA sessions 
     if (((re.search("ICA", line, re.IGNORECASE)) and (re.search("ACTIVE", line, re.IGNORECASE)))):
          sessions = sessions + 1

I renamed ACTIVE to Actief. That's dutch
I have no experience in python so can you give me some advice?
Thnx!!!
Cancel
Are you using Citrix?  In its current form the service only looks for ICA sessions, not RDP.  However, I have a new version that will work with either ICA or RDP sessions.  You can download it from here:
 
http://www.glue.umd.edu/~jferrell/download/RemoteSessions-1.0.zip
 
The new version has better logging and debugging features.
 
Please try it and let me know what happens.
 
John
Cancel
To recompile you will need to install Python and Py2exe on your Windows system.
 
http://www.python.org/2.4.2/
http://www.py2exe.org/
 
Once you both are installed you will need to create a setup.py file that looks like this:

# setup.py
from distutils.core import setup
import py2exe
setup(service=)

 
You can then compile it using the following command:
<path>\python.exe setup.py py2exe
 
This will create a folder in the current directory, 'dist', that will contain the compiled version.
 
I will also create a new version in which the word "ACTIVE" can be specified as an option in the config file.
Cancel
Run the client script from the command line:
<path>/python <path>/CTXsvcClient.py
 
The first number is the total session count from the servers polled.  Is that number correct?  If not, check the 'servers' variable within the script.
 
I am working on a new version with improved debugging.  I hope to past it later today.
 
John
Cancel
Thnx for the support and i'm looking forward to your new config file!
Cancel
Please try this new version.  In the config file you can change the way 'active' is spelled.  I also added better debugging features and support for RDP sessions, hence the name change.
 
http://www.glue.umd.edu/~jferrell/download/RemoteSessions-1.01.zip
 
Let me know if it works for you.
 
Thanks,
John
Cancel
John, it's working now! Thnx for your support.
So it was after all the word active that was messing things up over here

The new version is much better, great work!
Greets,
Dennis
Cancel
Sorry for the delayed reponse.
 
When MRTG updates the database, it also updates the the HTML file.  You might try modifying the MRTG code (it is written in Perl) to output your logo and the other information you want. 
 
Some people on this forum have mentioned using RRDtool instead of MRTG.  RRDtool does not create the HTML pages (it only collects data and generates graphs), so you could completely customize the HTML pages to you liking.  I haven't had much time to play with RRDtool, but it seems a bit more complicated to use.  I found some information on using MRTG and RRDtool together--MRTG collects the data and feeds it to RRDtool.  Using that method you could use RRDtool to generate the graphs and then create your own custom pages.
 
http://www.geocities.com/paulcwilliamson/mrtg/rateup2rrd.html
 
Another option would be to just use the MRTG graphs (the png files in the web directory) and then create your own pages.  Although you will loose some of the MRTG specific information such as Max and Min values.
 
John
 
 
Cancel
I have created a new version of the service and client based on the feedback I have received.
 
The new version adds RDP support, better error checking and debugging features, and support for non-english versions of Windows.
 
File can be downloaded from here:
http://www.glue.umd.edu/~jferrell/download/RemoteSessions-1.01.zip
Cancel
Is there any easy way, we can also get graphing citix sessions by servers.
 
Thanks for the help.
Cancel
Using my tools, the easist way would be to create multiple MRTG config files, one for each server.
 
Then in your crontab run each server seperately:
 
*/5 * * * * mrtg <path>/server1.cfg
*/5 * * * * mrtg <path>/server2.cfg
 
Another post in the forum suggested using RRDtool to color coordintate the graphs by server.  That would also be an option.  I have been experimenting with RRDtool.  If/When I make some progress I will post the information.
 
John
Cancel
John
 
In server.cfg file, there is no option to put IP address. Do you mean to add IP address of the server in .Py file and create crontab for each server?
 
We also noticed that we can't put only one server's IP address in .Py file. If we put only one server's IP in .py file, it give the error message. But if we add two server's IP address, it runs fine.
 
Thanks for the help.
Cancel
using the PRTG ( mrtg for windows ) what would the syntax of the config file be?
Cancel
Sorry for the delayed response.  I forgot to check "Notify me via e-mail when someone replies" when I posted.
 
Are you using the new version, 1.01 (You can download it from the link at the top of the article)?  In the new version I moved the servers to poll out of the .py to a config file.
 
So what you would do is create multiple config files for each server.  The file only contains the servers FQDN or IP address.
 
server1.cfg
server2.cfg
 
If you were to run it from the command line, it would only output information from server1.
 
$ RemoteSessionsClient.py server1.cfg
 
Then create an MRTG config file for each server: 
 
## server1 MRTG config file
WorkDir: /var/www/html/mrtg2/server1
## Citrix session count
Title: Citrix Sessions
Target:`python /usr/local/scripts/citrix/RemoteSessionsClient.py server1.cfg`
Options: gauge,growright

 
Then add a crontab entry for each server:
 
*/5 * * * * mrtg <path>/server1.cfg
*/5 * * * * mrtg <path>/server2.cfg

Utilmately, you will have a client config file (for RemoteSessionsClient.py), an MRTG config file, and a crontab entry for each server.
 
Do this make sense?
 
John

 
Cancel
I just downloaded PRTG.  From what I can tell, PRTG does not have the ability to run external scripts to collect data.  It only offers SNMP, Packet Sniffing, and Cisco Netflow as data collection options. 
 
MRTG will run on Windows, however the installation process is not as simple as PRTG. 
 
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/doc/mrtg-nt-guide.en.html
 
John
Cancel
We have this working in our environment,  but,  it shows the sessions of only one server.  We want to show the number of connections, per server graphically.
 
How can this be accomplished using the method discussed here?
Cancel

Hello,

If you have a running server using mrtg, I only use snmp to get my connected users. (and listening sockets) No further scripts needed.

 

Hope this helps for some people 

 ######################################################################
## Description statistics 1.3.6.1.4.1.3845.3.1.1.1.0 and 1.3.6.1.4.1.3845.3.1.1.3.0
## WFlisten: Winstation listening for connection (ICA)
######################################################################
Target[deimos_ica]: 1.3.6.1.4.1.3845.3.1.1.1.0&1.3.6.1.4.1.3845.3.1.1.3.0:public@deimos:
SetEnv[deimos_ica]: MRTG_INT_IP="144.128.168.101" MRTG_INT_DESCR="3Com EtherLink PCI"
Options[deimos_ica]: gauge,nopercent,growright
MaxBytes[deimos_ica]: 200
YLegend[deimos_ica]: Users
ShortLegend[deimos_ica]: Users
Legend1[deimos_ica]: Number of Users
Legend2[deimos_ica]: Number of Users
LegendI[deimos_ica]: &nbsp;Max:
LegendO[deimos_ica]: &nbsp;Min:

Title[deimos_ica]: Winstation listening for connection on deimos
PageTop[deimos_ica]: <H1>Winstation listening for connection on deimos</H1>
 <TABLE>
   <TR><TD>System:</TD>     <TD>deimos</TD></TR>
   <TR><TD>Maintainer:</TD> <TD>Ge Janssen</TD></TR>
   <TR><TD>Description:</TD><TD>Winstation listening for connection</TD></TR>
 </TABLE>

 

Cancel

-ADS BY GOOGLE

SearchVirtualDesktop

SearchEnterpriseDesktop

SearchServerVirtualization

SearchVMware

Close