Continuously/stream data to UDGrid?

Hey guys, wondering if anyone has ever continuously streamed data to a grid? For instance, trying to capture performance data and send to a grid + keep the time-series data. Getting the data their is not a biggy but keeping the grid going until x time thats my challenge.

You might want to check out scheduled endpoints https://adamdriscoll.gitbooks.io/powershell-universal-dashboard/endpoints/scheduled-endpoints.html - I was having some trouble in my example but basically you can “Populate” a cached variable that is being updated with your “live data”

Then your grid would be set to READ that cached object and autorefresh

Here’s my poor example, you’ll still have to do a better job than I did here about handling the cacheddata but it might be a good option. You could also temporarily store the live data to disk as well.

$Cache:PingCounts = @()
$5SecSchedule = New-UDEndpointSchedule -Every 5 -Second

$ServerHealthScheculedEndpoint = New-UDEndpoint -Schedule $5SecSchedule -Endpoint {
    
    $TestConnectionResult = Test-Connection 'www.google.com' -Count 1
    $TestConnectionResult | ForEach-Object {
        $PingTest = [PSCustomObject]@{
                TimeStamp = ((Get-Date).ToLongDateString() + " " + (Get-Date).ToLongTimeString())
                PingTime = $_.ResponseTime
        } 
        
        # Couldn't seem to op addition Cache Variables :( This is dumb.
        $NewPingCounts = @()
        $Cache:PingCounts | ForEach-Object{
            $NewPingCounts = $NewPingCounts + $_
        }
        $NewPingCounts = $NewPingCounts + $PingTest
        $Cache:PingCounts = $NewPingCounts
        
        
    }
   

}

$HomePage = New-UDPage -Name "Home" -Icon home -Endpoint {

    New-UDGrid -Id "PingTime" -Title "Ping Grid with Updates" -Headers @("TimeStamp","PingTime") -Properties @("TimeStamp", "PingTime") -AutoRefresh -RefreshInterval 1 -Endpoint {
        $Cache:PingCounts | Out-UDGridData
    }
   
}

$Pages = @($HomePage)

$Dashboard = New-UDDashboard -Title "PingBuddy" -Pages $Pages 

Get-UDDashboard | Stop-UDDashboard

Start-UDDashboard -Dashboard $Dashboard -Port 10000 -Endpoint @($ServerHealthScheculedEndpoint)

Thanks @leeberg, I usually would do a scheduled endpoint with $cache combination but my code will fire after udselect is submitted and is designed for multiple users so I’ve gone with $session, this is the code I’m playing with @ the moment:

New-UDPage -Name "HomePage" -Content {
New-UDLayout -Columns 6 -Content {

    New-UDSelect -Label "Select Env" -Option {
        New-UDSelectOption -Selected -Name "DEV" -value "DEV"
        New-UDSelectOption -Selected -Name "QA" -value "QA"
        New-UDSelectOption -Selected -Name "STG" -value "STG"
        New-UDSelectOption -Selected -Name "PRD" -value "PRD"

    } -OnChange {
        $session:SelectedEnv = $EventData
        Show-UDToast -Message "$session:SelectedEnv selected"
        ; Sync-UDElement -id 'Message'
    }

    New-UDRow -Columns {
        New-UDColumn -SmallSize 12 -Content {
            New-UDElement -Tag 'div' -Id 'Message' -Endpoint {
                New-UDCard -Content {
                    "Enviornment: $session:SelectedEnv"
                }
            }

            New-UDButton -Text "Get it..." -OnClick {

                Show-UDModal -FontColor "#FFFFFFFF" -BackgroundColor "#FF252525" -Persistent -Content {

                    New-UDElement -Tag 'div' -Id 'OtherStuff' -Endpoint {
                        New-UDChart -Title "PerData" -AutoRefresh -Type Line -Height 450px -Width Auto -Endpoint {
                            $session:WebCounts = Invoke-Command -ScriptBlock { #icm will be eventually be targeting multiple machines based on input env

                                $Date = get-date -Format t
                                $Computername = $($env:computername)
                                $CPU = [decimal](" {0:N0}" -f (Get-Counter -Counter "\Processor(_Total)\% Processor Time" | select -ExpandProperty CounterSamples).cookedvalue)#.Tostring("#.#")
                                $MEM = [decimal](" {0:N0}" -f (Get-Counter -Counter "\memory\% committed bytes in use" | select -ExpandProperty CounterSamples).cookedvalue)

                                [PSCustomObject]@{
                                    DATE     = $Date
                                    COMPUTER = $Computername
                                    CPU      = $CPU
                                    Memory   = $MEM
                                }
                            }

                            $session:WebCounts | Sort-Object -Property "ComputerName" | Out-UDChartData -LabelProperty "ComputerName" -Dataset @(

                                New-UDChartDataset -DataProperty "CPU" -Label "CPU" -BackgroundColor $ColorCPU -HoverBackgroundColor $barColorCPU -BorderColor $ColorBorder
                                New-UDChartDataset -DataProperty "Memory" -Label "Memory" -BackgroundColor $ColorCPU -HoverBackgroundColor $barColorCPU -BorderColor $ColorBorder

                            )
                        }

                    }

                    New-UDRow -Endpoint {
                        New-UDGrid  -AutoRefresh -FontColor "#FFFFFFFF" -BackgroundColor "#FF252525" -DefaultSortColumn 'DATE' -endpoint {
                            $session:WebCounts | Out-UDGridData
                        }
                    }

                    New-UDButton -Text 'Hide Modal' -OnClick {
                        Hide-UDModal
                    }

                } #endshowmodal
            }#endofbuttonOnClick
        }
    }#endofrow


}
}

Was also thinking op_addition but doing this inside the chart just nulls the variable as it re-fires, you will have $var = @() at the top of it, cant figure out another method?

Another thing I thought about was having a jobid and sending it all to a sql table, then call a storedproc to have the grid populate (but didn’t want to go down that hole just yet :wink: )

This opens up a few other questions maybe for @adamdriscoll, when closing the modal, will the charts stop polling for data? (dont want to run into a resource issue and want to handle the exit of the modal properly)

thanks,