Quantcast
Viewing all articles
Browse latest Browse all 28

Monitoring Citrix Licenses usage – Graphs using WMI, Powershell and RRDtool

Have you ever wandered how Citrix License usage looks like? You can open License Server console and check it. But what about some graphs or proactive informations? You can use EdgeSight – there is License Server monitoring tool. But what can you do, if you don’t want to install this tool. EdgeSigth is dedicated to old XenApp – based on IMA – and is no longer supported. So it rather pointless to use it. Mayby we can export informations from server and create graphs in Excel. Or, if we want to have “online” monitoring, we can use greate tool called – RRDtool. Information from official website:

What RRDtool does
RRDtool is the OpenSource industry standard, high performance data logging and graphing system for time series data. RRDtool can be easily integrated in shell scripts, perl, python, ruby, lua or tcl applications.

Image may be NSFW.
Clik here to view.
rrdtool-stream-pop

So I decided to write simple mechanism to create nice usage graphs:

Image may be NSFW.
Clik here to view.
CtxLicUsage-1d_

We will use:

  • PowerShell and CMD – to write all scripts
  • WMI – to get information from Citrix License Server
  • RRDtool – to save data in Round Robin Database and to generate nice graphs

All script will be executed on Citrix License Server. You can modify update script to call WMI remotly.

Create new directory called CTX. Inside this directory we will have:

Image may be NSFW.
Clik here to view.
CtxLicUsage_dir

  • graphs – folder contain generated graphs
  • RRDtool – windows binaries
  • CtxLicUsage.rrd – our Round Robin Database
  • CtxLicUsage_Graph.bat – script with commands to generate graphs  – this batch is run using Task Scheduler
  • CtxLicUsage_Update.bat – script to execute PowerShell script- CtxLicUsage_Update.ps1 – this batch is run using Task Scheduler (every 5 minutes)
  • CtxLicUsage_Update.ps1 – script to update RRD file

So let’s start. At the beginning let’s create new RRD file – we will do this only once:

c:\CTX\RRDtool\rrdtool.exe create CtxLicUsage.rrd \
--start now-10m --step 300 \
DS:total:GAUGE:450:0:U \
DS:used:GAUGE:450:0:U \
DS:avail:GAUGE:450:0:U \
DS:overdraft:GAUGE:450:0:U \
RRA:AVERAGE:0.5:1:2880 \
RRA:AVERAGE:0.5:3:2880 \
RRA:AVERAGE:0.5:9:2880 \
RRA:AVERAGE:0.5:54:2880

We created one RRD file with 4 Data Sources (DS). These DS will collect informations about license usage – total, used, available and overdraft (these overdraft exists only in User/Device license type, so if you want to monitor CCU type you can make simple modifications). We will be collecting data every 300 seconds (5 minutes) – I think it’s enough for U/D licenses, but you can change it to 1 minute (for CCU). We will collect all data in 4 Round Robin Archives (RRA). 1st for 10 days (2880 samples every 300 seconds is 864000 seconds / 60 seconds = 14400 hours / 60 minutes = 240 hours / 24 hour = 10 days), 2nd for 30 days, 3rd for 3 months and the last one for 18 months.

CtxLicUsage_Update.ps1

$licensePool = gwmi -class "Citrix_GT_License_Pool" -Namespace "ROOT\CitrixLicensing"
$usage = $licensePool | where-object {$_.PLD -like "XDT_ENT_UD"} | select Count,InUseCount,PooledAvailable,Overdraft
# Write-Host $usage.Count $usage.InUseCount $usage.PooledAvailable
$unixtime = [int][double]::Parse($(Get-date -date (Get-Date).ToUniversalTime()-uformat %s))

$cmd = "C:\CTX\RRDtool\rrdtool.exe update CtxLicUsage.rrd $($unixtime):$($usage.Count):$($usage.InUseCount):$($usage.PooledAvailable):$($usage.Overdraft)"
iex $cmd

What we do in this script. We are using WMI to get information about licenses. Then we are creating update command. Remember, rrdtool update accept only unix timestamps, and command syntax is:

rrdtool.exe update database.rrd unix_timestamp:value1:value2:value3:value4

So in my case it was:

rrdtool.exe update CtxLicUsage.rrd 1429608601:660:537:123:60
rrdtool.exe update CtxLicUsage.rrd 1429608901:660:537:123:60
rrdtool.exe update CtxLicUsage.rrd 1429609201:660:537:123:60
rrdtool.exe update CtxLicUsage.rrd 1429609501:660:537:123:60
rrdtool.exe update CtxLicUsage.rrd 1429611301:660:538:122:60
rrdtool.exe update CtxLicUsage.rrd 1429611601:660:539:121:60
rrdtool.exe update CtxLicUsage.rrd 1429611901:660:540:120:60
rrdtool.exe update CtxLicUsage.rrd 1429612201:660:541:119:60
rrdtool.exe update CtxLicUsage.rrd 1429612501:660:540:120:60

OK, updating PowerShell script is done. Now we have to execute it every 5 minutes. So let’s use Windows Task Scheduler for this. Create file CtxLicUsage_Update.bat:

PowerShell.exe -command ". C:\CTX\CtxLicUsage_Update.ps1"
C:\CTX\CtxLicUsage_Graph.bat

We will call PoSH update commands and after that we will generate graphs. Now set Task Scheduler, to execute this CtxLicUsage_Update.bat script every 5 minutes (infinitely). So right now our RRD database will be filled with data every 300 seconds.

The last and most spectacular step – graph generating.

CtxLicUsage_Graph.bat

c:\CTX\RRDtool\rrdtool.exe graph graphs\CtxLicUsage-1d.png -w 600 -h 200 --slope-mode \
--vertical-label "Licenses Checked Out" --title "Citrix license usage - XDT_ENT_UD - User/Device" \
DEF:Total=CtxLicUsage.rrd:total:AVERAGE \
DEF:Used=CtxLicUsage.rrd:used:AVERAGE \
DEF:Avail=CtxLicUsage.rrd:avail:AVERAGE \
DEF:Overdraft=CtxLicUsage.rrd:overdraft:AVERAGE \
CDEF:LineUsed=Used,1,* \
CDEF:LineAvail=Avail,1,* \
CDEF:LineTotal=Total,1,* \
CDEF:LineOverdraft=Total,Overdraft,- \
COMMENT:" " COMMENT:"Last    " COMMENT:"Maximum " COMMENT:"Average " COMMENT:"Minimum\l" \
AREA:LineUsed#fe3562:"Used ":STACK GPRINT:Used:LAST:"%%6.3lf %%S" GPRINT:Used:MAX:"%%6.3lf %%S" GPRINT:Used:AVERAGE:"%%6.3lf %%S" GPRINT:Used:MIN:"%%6.3lf %%S\l" \
AREA:LineAvail#cfe694:"Available ":STACK GPRINT:Avail:LAST:"%%6.3lf %%S" GPRINT:Avail:MAX:"%%6.3lf %%S" GPRINT:Avail:AVERAGE:"%%6.3lf %%S" GPRINT:Avail:MIN:"%%6.3lf %%S\l" \
LINE2:LineTotal#3b73fc:"Total " GPRINT:Total:LAST:"%%6.3lf %%S" GPRINT:Total:MAX:"%%6.3lf %%S" GPRINT:Total:AVERAGE:"%%6.3lf %%S" GPRINT:Total:MIN:"%%6.3lf %%S\l" \
LINE1:LineOverdraft#9e0b0f:"Overdraft " GPRINT:Overdraft:LAST:"%%6.3lf %%S" GPRINT:Overdraft:MAX:"%%6.3lf %%S" GPRINT:Overdraft:AVERAGE:"%%6.3lf %%S" GPRINT:Overdraft:MIN:"%%6.3lf %%S\l"

By default graph command generate image for 1 day time period. First graph (at the beginning of this post) was generated using this command. If you want to create image for 10 days period you can add

--end now --start end-10d

so the first line will be:

c:\CTX\RRDtool\rrdtool.exe graph graphs\CtxLicUsage-10d.png -w 600 -h 200 –end now –start end-10d –slope-mode

Image may be NSFW.
Clik here to view.
CtxLicUsage-10d_

At the beginning I wrote, that we can do some predictions. Let’s generate trend line (we will show 10 days prediction using 10 days data from the past):

c:\CTX\RRDtool\rrdtool.exe graph graphs\CtxLicUsage-trend.png -w 600 -h 200 --end now+10d --start now-10d --slope-mode \
--vertical-label "Licenses Checked Out" --title "Citrix license usage - XDT_ENT_UD - User/Device" \
DEF:Total=CtxLicUsage.rrd:total:AVERAGE \
DEF:Used=CtxLicUsage.rrd:used:AVERAGE \
DEF:Avail=CtxLicUsage.rrd:avail:AVERAGE \
DEF:Overdraft=CtxLicUsage.rrd:overdraft:AVERAGE \
CDEF:LineUsed=Used,1,* \
CDEF:LineAvail=Avail,1,* \
CDEF:LineTotal=Total,1,* \
CDEF:LineOverdraft=Total,Overdraft,- \
VDEF:slope=LineUsed,LSLSLOPE \
VDEF:cons=LineUsed,LSLINT \
CDEF:leastsquareline=LineUsed,POP,slope,COUNT,*,cons,+ \
COMMENT:" " COMMENT:"Last    " COMMENT:"Maximum " COMMENT:"Average " COMMENT:"Minimum\l" \
AREA:LineUsed#fe3562:"Used ":STACK GPRINT:Used:LAST:"%%6.3lf %%S" GPRINT:Used:MAX:"%%6.3lf %%S" GPRINT:Used:AVERAGE:"%%6.3lf %%S" GPRINT:Used:MIN:"%%6.3lf %%S\l" \
AREA:LineAvail#cfe694:"Available ":STACK GPRINT:Avail:LAST:"%%6.3lf %%S" GPRINT:Avail:MAX:"%%6.3lf %%S" GPRINT:Avail:AVERAGE:"%%6.3lf %%S" GPRINT:Avail:MIN:"%%6.3lf %%S\l" \
LINE2:LineTotal#3b73fc:"Total " GPRINT:Total:LAST:"%%6.3lf %%S" GPRINT:Total:MAX:"%%6.3lf %%S" GPRINT:Total:AVERAGE:"%%6.3lf %%S" GPRINT:Total:MIN:"%%6.3lf %%S\l" \
LINE1:LineOverdraft#9e0b0f:"Overdraft " GPRINT:Overdraft:LAST:"%%6.3lf %%S" GPRINT:Overdraft:MAX:"%%6.3lf %%S" GPRINT:Overdraft:AVERAGE:"%%6.3lf %%S" GPRINT:Overdraft:MIN:"%%6.3lf %%S\l" \
LINE1:leastsquareline#FF9900:"Trend"

Image may be NSFW.
Clik here to view.
CtxLicUsage-trend_

Windows binaries are here and all downloads. I’m using 1.3.8 RRDtool version.

Right now I’m also working on other monitoring scripts.

Graphs, that will show user session for each published apps or desktops (or all):

Image may be NSFW.
Clik here to view.
ctx_stats_1

Graphs, that will show server count for each load range (some kind of map of server “heat”):

Image may be NSFW.
Clik here to view.
ctx_stats_2

 

If you think, that this license monitoring tool is usefull please let me know using comments below. If you are interested in other usage of RRDtool (in Citrix environment) please let me know.


Viewing all articles
Browse latest Browse all 28

Trending Articles