Citrix Monitoring ODATA API

Function Get-LocalTime($UTCTime)
{
$strCurrentTimeZone = "Eastern Standard Time"
$TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
Return $LocalTime
}
$datescope = (get-date).AddHours(-3).ToUniversalTime()
$datescope = get-date($datescope) -Format s
$filename = "SessionActivitySummariesByMinute-" + (get-date ($datescope) -f "MM-yyyy") + ".csv"
$uri = "http://localhost/Citrix/Monitor/OData/v3/Data/SessionActivitySummaries()?`$filter=Granularity eq 1 and SummaryDate gt DateTime`'$datescope`' &`$select=DesktopGroup/Name,SummaryDate,ConcurrentSessionCount,ConnectedSessionCount,DisconnectedSessionCount&`$orderby=SummaryDate asc&`$expand=DesktopGroup&`$format=json"
$records = Invoke-RestMethod -Uri $uri -UseDefaultCredentials
$records.value | Select-Object @{Name='SummaryDateEST';Expression={Get-LocalTime($_.SummaryDate)}},ConcurrentSessionCount,ConnectedSessionCount,DisconnectedSessionCount,@{Name='DesktopGroupName';Expression={$_.DesktopGroup.Name}} | Export-csv .\$filename -NoTypeInformation -Append

Citrix provides access to Monitoring Data via ODATA API, I find it useful to extract session info to a very granular level [eg: by mintue]. This is the same data Citrix Director uses to present the fancy usage graphs but as you expand to longer time series it averages it and you might not get the accurate insights for capacity planning. The PS code shown above extracts and exports the SessionActivitySummary by minute to a csv file. the reason for the export is Citrix purges the ByMinute data, by default it only retains it for last 3 days. you could override this default retention value using Set-MonitoringConfiguration . I find it easy to export and generate graphs using pivot tables in excel.

The PS script above could you used to set up as scheduled tasks on a controller and set to run every 3 hours. This provides a way to archive the data as well as leaving the default retention values in Citrix.

Download code from https://github.com/Siva-Github/PS-Scripts-Repo/blob/main/SessionActivitySummariesByMinute-ODATA.ps1

Join the Conversation

2 Comments

  1. I copied this query into our environment, it didn’t work. Firstly, JSON formating was not picked i need to alter it a bit and finally it doesn’t shows DesktopGroup Name as field selected in the values output.

    Your input will be helpful and thank you for sharing this

    Id :
    SummaryDate :
    DesktopGroupId
    ConnectedSessionCount :
    DisconnectedSessionCount :
    ConcurrentSessionCount :
    TotalLogOnDuration :
    TotalLogOnCount :
    Granularity : 1440
    CreatedDate
    ModifiedDate

Leave a comment

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux