Creating a Green Dashboard – Part 1

Using tools to gather external logins to the Citrix Farm

There are a variety of ways to distinguish internal and external users of your Citrix farm.  The method we employ is to utilize the logging that’s part of any Citrix Secure Ticket Authority (STA) in your Citrix Farm.  You can turn logging on your designated STA’s by following the information in this Citrix article: CTX101997.  Turning this on gives us the following data in logs (located in %PROGRAMFILES%\Citrix\Logs\)

INFORMATION 2009/05/20:00:13:22 CSG1305 Request Ticket - Successful. A995AD36B87524A208BB23A804AC3110 V1 CSGTestData Thisistheextendeddata
INFORMATION 2009/05/20:00:13:22 CSG1303 Ticket timed out. A8478127C7971E4CD95C28FFD2B85BBE
INFORMATION 2009/05/20:00:13:23 CSG1305 Request Ticket - Successful. FF985D4B11DA3AE7B6CBBAA9CA833415 V1 CSGTestData Thisistheextendeddata
INFORMATION 2009/05/20:00:13:23 CSG1303 Ticket timed out. CDE1751C367B45506481C26727C3E6C1
INFORMATION 2009/05/20:00:13:23 CSG1305 Request Ticket - Successful. 19078A551F501BCC0F77E7361EE76CAD V1 CSGTestData Thisistheextendeddata
INFORMATION 2009/05/20:00:13:23 CSG1303 Ticket timed out. 414CB490647B8A2FCE023D66E7D0850E
and so on.
You will need to parse for a line like the following:
INFORMATION 2009/05/20:00:13:24 CSG1305 Request Ticket - Successful. 5C6C67EB127CFDB0821DC88CA1C10972 V4 CGPAddress = XXX.XXX.XX.XXX:2598:localhost:1494 Refreshable = false XData = <!--DOCTYPE CtxConnInfoProtocol SYSTEM "CtxConnInfo.dtd"-->XXX.XXX.XX.XXX:1494USER@DOM.COMRemote Desktop AccessICA ICAAddress = XXX.XXX

From the above line we can get the ticket status, the username, the published application, and the target server that hosts the application. When this is parsed and placed in a database, we can associate a time and date with the ticket creation and determine how long the user is logged in and what applications they are running.

To accomplish the data gathering, we use tools from InterSect Alliance like Epilog Agent for Windows to tail the stalog files.  This raw data is then sent to a server running Kiwi SysLog.  Kiwi parses the data (using a script) and then inserts it into a database table.  We’ve found these tools to be inexpensive and have a low resource utilization.

So, to sum up we have external users connecting to our Citrix farm and STA logs generating when they connect, what they run, and what server they connect to.  We parse the logs into a database and that gives us a real-time/historical record of the user’s use of our Citrix farm.    Next post will cover gathering average telecommuting statistics from the Internet.


PowerShell: Auto logoff Citrix users

NOTE: Have XenApp 6.x and PowerShell? I revisited this problem in XenApp 6.5 with a new PowerShell script. Read about it here.

I recently came across a situation where I needed to clear users off a server in production for testing.  Typically, we assign a load evaluator to keep new users from connecting to it and watch the server.  When a user’s session becomes disconnected, we log the user off.  This can take a while depending on how busy the server is and is about as exciting as watching grass grow.  So, I thought “PowerShell can fix this problem!”  Here’s the result.

# ==============================================================================================
# NAME: CheckXenAppIsFree.ps1
# AUTHOR: Alain Assaf
# DATE : 05/21/2009
# COMMENT: Script that will run on a locked down server and automatically disconnect users
# until there are no more sessions.
# USAGE: .\CheckXenAppIsFree.ps1
# ==============================================================================================

# Prompt for server to watch
if (($citrixserver -eq $null) -or ($citrixserver -eq "")){
$citrixserver=$(Read-Host "Enter Server to watch until no sessions exist.")

# Setup Farm object
$MetaFrameWinAppObject = 3
$MetaFrameWinFarmObject = 1
$myFarm = New-Object -com MetaFrameCOM.MetaFrameFarm

# Checking if user is a Citrix administrator
If ($myFarm.WinFarmObject.IsCitrixAdministrator -eq 0) {
Write-Output "You must be a Citrix admin to run this script`n"

# Checking that the Citrix server exists
$MetaframeServers = $myFarm.Servers | Sort-Object -property ServerName | ? { $_.ServerName -like $citrixserver}
If ($MetaframeServers -eq $null) {
Write-Host "Invalid Citrix server" -ForegroundColor Red
Write-Host "Exiting CheckXenAppIsFree" -ForegroundColor Red

# Getting the currently assigned load evaluator
$le = $MetaframeServers.AttachedLE
$LEName = $le.LEName
$XenAppServerName = $citrixserver.ToUpper()

# If the LE isn't set to Lockdown, then this script will exit
If ($LEName -eq 'Lockdown') {
Write-Host "$XenAppServerName has '$LEName' attached." -ForegroundColor White
} else {
Write-Host "$XenAppServerName does not have a Lockdown LE attached. It has '$LEName' attached." -ForegroundColor White
Write-Host "Exiting CheckXenAppIsFree" -ForegroundColor Red

# Get the current session count
$sessCount = $MetaframeServers.SessionCount

# Check for disconnected users. If none, wait 10 minutes and check again
# If there are disconnected users. Log them off. Continue until there are no more logged in sessions.
while ($sessCount -ge 0) {
$MetaframeServers = $myFarm.Servers | Sort-Object -property ServerName | ? { $_.ServerName -like $citrixserver}
$sessCount = $MetaframeServers.SessionCount
Write-Host "Current session Count = $sessCount on $XenAppServerName" -ForegroundColor White
if ($sessCount -eq 0) { Write-Host "$XenAppServerName is free of users" -ForegroundColor White
} else {
$disconnected = @()
Write-Host "Checking for disconnected users on $XenAppServername" -ForegroundColor White
$disconnected = @($myfarm.Sessions | Where-Object {$_.SessionState -eq 5 -and $_.ServerName -eq $citrixserver})
if ($disconnected[0] -eq $null) {
Write-Host "There are no currently disconnected sessions on $XenAppServerName" -ForegroundColor White
Write-Host "Waiting 10 minutes" -ForegroundColor Red
Start-Sleep -Seconds 600
} else {
Write-host "Logging off disconnected users from $XenAppServerName" -ForegroundColor White
$i = 0
foreach ($user in $disconnected) {
$namedUser = $disconnected[$i].Username
write-host "Logging off $namedUser" -ForegroundColor White


Creating a Green Dashboard – Introduction

Green, the Green Economy, Green-collar jobs…

Green is in the news a lot lately.  Its importance has risen as the economy has slowed and the promise of various virtualization technologies to be “green” or allow a company to be greener has fired up the marketing wings of the companies that sell these technologies.  There are also a lot of ROI and savings reports that come along touting the economic advantages of virtualization.  A recent article by Virtualization Rock Star Brian Madden notes the hidden costs of VDI, which can be applied to any virtualization endeavor. 

So, you run a Citrix farm and provide access to remote users.  Did you know that you’re contributing to the green economy and saving your users and company money?  I intend on showing you how to mesh your user login information along with average costs and savings for telecommuting and displaying the results in a dashboard in real-time.

I’m planning on covering this series in 5 posts:

  • Part 1 – Using scripts to gather external logins to the Citrix Farm
  • Part 2 – Gathering average telecomuting statistics
  • Part 3 – Calculating savings and costs
  • Part 4- Displaying how Green your Citrix farm is in real-time.
  • Part 5 – Results and Conclusion