Access the diagnostic "data" in own code?

Hey all,
I really want to make calls to the sessions in the dashboard, anyknow know how to access this?

Hi @McAndersDK

If you do
$dash = get-uddashboard
I believe all the session stuff should be under there somewhere.
Care to elaborate the case? Iā€™m a curious man :open_mouth:

$Dash.DashboardService.EndpointService.SessionManager

1 Like

This dont seems to work.
the dashboard are running under IIS, and I want to access it from a scheduled endpoint.

(I use it for online counter :slight_smile: )

I use this atm:

New-UDEndpoint -Schedule (New-UDEndpointSchedule -Every 1 -Minute -consecutive) -id ā€˜OnlineUsersā€™ -Endpoint {

$StartTime = get-date

$ip = (Resolve-DnsName "$env:COMPUTERNAME.nclan.netcompany.dk" -Type a -DnsOnly).ipaddress

function Get-NetStat {

    <#

.SYNOPSIS

This function will get the output of netstat -n and parse the output

.DESCRIPTION

This function will get the output of netstat -n and parse the output

.LINK

http://www.lazywinadmin.com/2014/08/powershell-parse-this-netstatexe.html

.NOTES

Francois-Xavier Cat

www.lazywinadmin.com

@LazyWinAdm

#>

    PROCESS {

        # Get the output of netstat

        $data = netstat -ano

        # Keep only the line with the data (we remove the first lines)

        $data = $data[4..$data.count]

        # Each line need to be splitted and get rid of unnecessary spaces

        foreach ($line in $data) {

            # Get rid of the first whitespaces, at the beginning of the line

            $line = $line -replace '^\s+', ''

            # Split each property on whitespaces block

            $line = $line -split '\s+'

            # Define the properties

            $properties = @{

                Protocole          = $line[0]

                LocalAddressIP     = ($line[1] -split ":")[0]

                LocalAddressPort   = ($line[1] -split ":")[1]

                ForeignAddressIP   = ($line[2] -split ":")[0]

                ForeignAddressPort = ($line[2] -split ":")[1]

                State              = $line[3]

                PID                = $line[4]

            }

            # Output the current line

            New-Object -TypeName PSObject -Property $properties

        }

    }

}

$time = get-date

$newconnections = get-netstat | Where-Object { $_.LocalAddressPort -eq 443 -and $_.LocalAddressIP -eq $ip } | Select-Object foreignaddressip -Unique | Select-Object foreignaddressip, @{n = 'Timestamp'; e = { $time } }

$mergeConnections = $cache:OnlineUsers | Where-Object foreignaddressip -NotIn $newconnections.foreignaddressip | Where-Object Time -gt $time.AddMinutes(-5)

$mergeConnections += $newconnections

$cache:OnlineUsers = $mergeConnections

invoke-EndpointLogging -EndpointName 'onlineUsers' -StartTime $StartTime

}

as you can see itā€™s not pretty :stuck_out_tongue:
this would be much prettyer

New-UDEndpoint -Schedule (New-UDEndpointSchedule -Every 1 -Minute -consecutive) -id ā€˜OnlineUsersā€™ -Endpoint {
$dash = get-uddashboard
$cache:OnlineUsers = $Dash.DashboardService.EndpointService.SessionManager
}

Do this to get the list of sessions.

New-UDEndpoint -Schedule (New-UDEndpointSchedule -Every 1 -Minute -consecutive) -id ā€˜OnlineUsersā€™ -Endpoint {
$dash = get-uddashboard
$cache:OnlineUsers = $Dash.DashboardService.EndpointService.SessionManager.Sessions
}

Hereā€™s the SessionManager class for reference.

1 Like

nope nothing is returned at all for any ā€œpathā€ of that variable.
get-uddashboard return nothing.

Oh. Thatā€™s weird. Letā€™s try this. This is just the internal class that Get-UDDashboard cmdlet is accessing.

[UniversalDashboard.Server]::Servers.DashboardService.EndpointService.SessionManager.Sessions

Nope, dont return anything.

Hereā€™s a full example thatā€™s working for me.



$Dashboard = New-UDDashboard -Title 'hey' -Content {

   $Cache:SessionCount = 0

   New-UDCounter -Title Sessions -Endpoint {
      $Cache:SessionCount
   }
}

$Schedule = New-UDEndpointSchedule -Consecutive -Every 5 -Second

$Endpoint = New-UDEndpoint -Endpoint {
   $Cache:SessionCount = ([UniversalDashboard.Server]::Servers.DashboardService.EndpointService.SessionManager.Sessions | Measure-Object).Count
} -Schedule $Schedule

Start-UDDashboard -Dashboard $Dashboard -Port 10000 -Endpoint $Endpoint -FOrce

image

yeah it seems to works standalone, but it dont work under IIS.

not sure why

Iā€™m also interested in accessing the same info but can confirm, having the same issue under IIS, nothing is returned. It seems that the class / get-uddashboard itself doesnt return anything, let alone itā€™s sub properties. I can access the $session variable but obviously this is only for the current users session, not all.

Iā€™m running UD 2.8.0, not had chance to test on 2.8.1 but Iā€™ve not seen anything related under the open/closed issues within git. Adam, should I log a new issue for this?

I just realized the issue here. In IIS, using the -Wait parameter on Start-UDDashboard happens before the UD server object is added to that collection of servers so it never gets added to that list. Iā€™ve put in a PR to fix this. 2.8.2 is going out the door today and this fix will be included.

3 Likes

Legend. As always, quick to the mark and super helpful. Thank You!

Related GitHub PR https://github.com/ironmansoftware/universal-dashboard/pull/1459

This is now working (in version 2.8.2) BUT we need to use it like this:

else it just count 1. (And fixed for only returning Active sessions :))
Thanks for the fix @adam

1 Like