Генерация последовательных date_time за минуту в MySQL

Этот метод использует Workflow для параллельного пинга. Он также учитывает, что тайм-аут System.Net.NetworkInformation.Ping не является точным, когда дело доходит до использования в миллисекундах. Я предлагаю работать с Boxzogs Answer, так как он является самым встроенным в стандарты powershell. Но я хотел присоединиться к веселью и обучению.

workflow AdvPing([string[]]$Servers, [timespan]$RunTimeLength, [timespan]$Freqency, [timespan]$PingTimeout){
    foreach -parallel ($Server in $Servers)
    {
        $Runtime = (get-date).Add($RunTimeLength)
        $CurrentDate = get-date
        $Timeout = $PingTimeout
        $Ping = New-Object System.Net.NetworkInformation.Ping

        while($CurrentDate -le $RunTime){
            $Response = ""
            $ResponseMessage = ""
            $CurrentFreqency = (Get-Date).add($Freqency)
            try{
                $Response = $Ping.Send($Server,$Timeout.TotalMilliseconds)
                if(($Response.RoundtripTime -gt $PingTimeout.Milliseconds) -and ($Response.Status -like "Success")){
                    $ResponseMessage = "TimeOut"
                }else{
                    $ResponseMessage = $Response.Status
                }
                $Reply = New-Object psobject -Property @{
                    Server = $Server
                    Response = $ResponseMessage
                    Date = $(get-date).DateTime
                    Time = $Response.RoundtripTime
                    Exception = $null
                }
            }catch{
                $Reply = New-Object psobject -Property @{
                    Server = $Server
                    Response = "No Host"
                    Date = $(get-date).DateTime
                    Time = $null
                    Exception = $_
                }
            }
            $Reply

            $CurrentDate = Get-Date
            [timespan]$Wait = $CurrentFreqency - $CurrentDate
            try{
                sleep -Milliseconds $Wait.TotalMilliseconds
            }catch{}
        }
    }
}

$Servers = @("8.8.8.8", "8.8.4.4", "StackOverflow.com","243.42.432.44")
advping -Servers $Servers -RunTimeLength ([TimeSpan]::FromSeconds(60)) -Freqency ([TimeSpan]::FromSeconds(1)) -PingTimeout ([TimeSpan]::FromMilliseconds(5)) | format-table Date,Server,Response,Time

Выход будет выглядеть как

Date                             Server            Response Time
----                             ------            -------- ----
Friday, July 13, 2018 2:53:37 PM 243.42.432.44     No Host      
Friday, July 13, 2018 2:53:37 PM StackOverflow.com TimeOut  15  
Friday, July 13, 2018 2:53:37 PM 8.8.4.4           Success  2   
Friday, July 13, 2018 2:53:37 PM 8.8.8.8           Success  2   
Friday, July 13, 2018 2:53:38 PM 243.42.432.44     No Host      
Friday, July 13, 2018 2:53:38 PM StackOverflow.com TimeOut  15  
Friday, July 13, 2018 2:53:38 PM 8.8.4.4           Success  2   
Friday, July 13, 2018 2:53:38 PM 8.8.8.8           Success  2   
0
задан Daniel 19 January 2019 в 10:57
поделиться