martinh80
Goto Top

Dauerpingausgabe analysieren

Hallo zusammen,

Ich habe ein Logfile wo alle 5 Minuten, Datum und Uhrzeit und danach ein Ping abgesetzt wurde. Das Ganze eine Woche lang. Mein Problem ist nun wie ich es hinbekomme, dass Datum und Uhrzeit passend in dieselbe Zeile geschrieben wird wie der Ping Response um das ganze in ein Diagramm zu bringen.
So sieht das File aus:

C:\Temp>echo di 02-02-2016 10:52:13,58
di 02-02-2016 10:52:13,58

C:\Temp>ping -l 1472 -f -n 10 host.com

Pinging host.com [x.x.x.x] with 1472 bytes of data:
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=11ms TTL=121
Reply from x.x.x.x: bytes=1472 time=11ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121

Ping statistics for x.x.x.x:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 9ms, Maximum = 11ms, Average = 9ms

C:\Temp>ping -n 10 host.com

Pinging host.com [x.x.x.x] with 32 bytes of data:
Reply from x.x.x.x: bytes=32 time=8ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=19ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=25ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=13ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121

Ping statistics for x.x.x.x:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 8ms, Maximum = 25ms, Average = 11ms

C:\Temp>timeout /T 600 1>nul

C:\Temp>goto :start

C:\Temp>echo di 02-02-2016 10:58:52,79
di 02-02-2016 10:58:52,79

C:\Temp>ping -l 1472 -f -n 10 host.com

Pinging host.com [x.x.x.x] with 1472 bytes of data:
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=13ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
usw.

aussehen sollte das dann so:
di 02-02-2016 10:58:52,79; Reply from x.x.x.x: bytes=1472 time=10ms TTL=121

Ich hab echt keinen Plan wie ich das angehen könnte.

Danke schonmal für eure Hilfe

Content-Key: 297252

Url: https://administrator.de/contentid/297252

Printed on: April 19, 2024 at 12:04 o'clock

Member: Meierjo
Meierjo Feb 25, 2016 at 07:13:04 (UTC)
Goto Top
Hallo

Ich habe mal folgenden Batch verwendet, um verschiedene IP's anzupingen.
Mit Maxcount kannst du angeben, wieviel mal die Adresse gepingt werden soll (im Falle eines Timeouts)
Diesen Batch als zeitgesteuerten Task zb alle 5 Min laufen lassen

Dabei wird ein Logfile geschrieben
Dort drin kannst du einfach nach Ergebnis offline - Fehler oder
Online suchen

rem @echo off & setlocal 
set LogFile=C:\temp\Tools\IP_anpingen_%Date%.log

set IP1=192.168.100.101
set IP2=Host4
set IP3=192.168.100.102
set IP4=Host5
set IP5=192.168.100.103
set IP6=Host6

set Counter1=0
set Counter2=0
set Counter3=0
set Counter4=0
set Counter5=0
set Counter6=0
set Maxcount=3
echo **** %Date%-%Time% - - IP_Anpingen gestartet **** >>%Logfile%
echo. >>%Logfile%

:Start1
set /a Counter1=%Counter1% + 1
set "Ergebnis=offline - Fehler"  
for /f "tokens=7 delims==< " %%i in ('ping -n 1 %IP1%^|findstr "TTL"') do set "Ergebnis=online"  
echo %date%-%time% - %IP1% - %Ergebnis% >>%Logfile%
if "%Counter1%" EQU "%Maxcount%" echo. >>%Logfile% && goto Start2  
goto Start1

:Start2
set /a Counter2=%Counter2% + 1
set "Ergebnis=offline - Fehler"  
for /f "tokens=7 delims==< " %%i in ('ping -n 1 %IP2%^|findstr "TTL"') do set "Ergebnis=online"  
echo %date%-%time% - %IP2% - %Ergebnis% >>%Logfile%
if "%Counter2%" EQU "%Maxcount%" echo. >>%Logfile% && goto Start3  
goto Start2

:Start3
set /a Counter3=%Counter3% + 1
set "Ergebnis=offline - Fehler"  
for /f "tokens=7 delims==< " %%i in ('ping -n 1 %IP3%^|findstr "TTL"') do set "Ergebnis=online"  
echo %date%-%time% - %IP3% - %Ergebnis% >>%Logfile%
if "%Counter3%" EQU "%Maxcount%" echo. >>%Logfile% && goto Start4  
goto Start3

:Start4
set /a Counter4=%Counter4% + 1
set "Ergebnis=offline - Fehler"  
for /f "tokens=7 delims==< " %%i in ('ping -n 1 %IP4%^|findstr "TTL"') do set "Ergebnis=online"  
echo %date%-%time% - %IP4% - %Ergebnis% >>%Logfile%
if "%Counter4%" EQU "%Maxcount%" echo. >>%Logfile% && goto Start5  
goto Start4

:Start5
set /a Counter5=%Counter5% + 1
set "Ergebnis=offline - Fehler"  
for /f "tokens=7 delims==< " %%i in ('ping -n 1 %IP5%^|findstr "TTL"') do set "Ergebnis=online"  
echo %date%-%time% - %IP5% - %Ergebnis% >>%Logfile%
if "%Counter5%" EQU "%Maxcount%" echo. >>%Logfile% && goto Start6  
goto Start5

:Start6
set /a Counter6=%Counter6% + 1
set "Ergebnis=offline - Fehler"  
for /f "tokens=7 delims==< " %%i in ('ping -n 1 %IP6%^|findstr "TTL"') do set "Ergebnis=online"  
echo %date%-%time% - %IP6% - %Ergebnis% >>%Logfile%
if "%Counter6%" EQU "%Maxcount%" echo. >>%Logfile% && goto Ende  
goto Start6

:Ende

echo.
echo **** %Date%-%Time% - - IP_Anpingen beendet **** >>%Logfile%
echo. >>%Logfile%
echo. >>%Logfile%

set Counter1=
set Counter2=
set Counter3=
set Counter4=
set Counter5=
set Counter6=
set MaxCount=
set IP1=
set IP2=
set IP3=
set IP4=
set IP5=
set IP6=
set Ergebnis=
set Logfile=


Gruss Urs
Member: Martinh80
Martinh80 Feb 25, 2016 at 10:11:51 (UTC)
Goto Top
Danke Urs, aber die Pings sind schon gelaufen und jetzt hab ich das Problem die vorhandenen Files zu analysieren und aufzubereiten.
Was ich brauche ist im Prinzip ne CSV wo nur noch Uhrzeit und die Antwortzeit der Pings in einer Zeile stehen.
Member: Meierjo
Meierjo Feb 25, 2016 at 10:18:54 (UTC)
Goto Top
Hallo

Was ich brauche ist im Prinzip ne CSV wo nur noch Uhrzeit und die Antwortzeit der Pings in einer Zeile stehen.

Sorry, da hab ich auch keinen Plan.
Mein Batch von oben würde dir die Sache erleichtern, indem nur die Sachen geloggt werden, die du wirklich brauchst.

a9d11af8fd242dcabb144621601d7173
So sieht die Ausgabe des Logfiles aus. Mit ein wenig Anpassungen erhältst du dein Wunschergebnis.

Sorry

Grus
Mitglied: 114757
114757 Feb 25, 2016 updated at 19:03:37 (UTC)
Goto Top
Moin,
kannst du den Inhalt deines Textfiles mal in Code-Tags posten. Da steht doch bestimmt nicht immer der Prompt (C:\Temp>) mit drin oder doch ???? Wer macht denn so einen Blödsinn ?

Und welche Response-Time der zige Versuche willst du jeweils übernehmen?

Mit einem Powershell-Einzeiler und etwas Regex ist das schnell ausgewertet.

PS-Beispiel mit deinen jetzigen gesposteten Daten
$file = @'  
C:\Temp>echo di 02-02-2016 10:52:13,58
di 02-02-2016 10:52:13,58

C:\Temp>ping -l 1472 -f -n 10 host.com

Pinging host.com [x.x.x.x] with 1472 bytes of data:
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=11ms TTL=121
Reply from x.x.x.x: bytes=1472 time=11ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121

Ping statistics for x.x.x.x:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 9ms, Maximum = 11ms, Average = 9ms

C:\Temp>ping -n 10 host.com

Pinging host.com [x.x.x.x] with 32 bytes of data:
Reply from x.x.x.x: bytes=32 time=8ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=19ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=25ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=13ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121
Reply from x.x.x.x: bytes=32 time=9ms TTL=121

Ping statistics for x.x.x.x:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 8ms, Maximum = 25ms, Average = 11ms

C:\Temp>timeout /T 600 1>nul

C:\Temp>goto :start

C:\Temp>echo di 02-02-2016 10:58:52,79
di 02-02-2016 10:58:52,79

C:\Temp>ping -l 1472 -f -n 10 host.com

Pinging host.com [x.x.x.x] with 1472 bytes of data:
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=13ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
'@  

[regex]::matches($file,'(?is)(\w{2} \d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2},\d*).*?data:[\r\n]*([^\r\n]+)').Captures | %{new-object PSObject -Property @{Time=$_.Groups[1].Value;Response=$_.Groups[2].Value}}  
Das ganze als CSV zu exportieren ist eine Kleinigkeit, da braucht man nur noch ein export-csv in der Pipe dranhängen...

Gruß jodel32
Member: Martinh80
Martinh80 Feb 25, 2016 at 11:14:09 (UTC)
Goto Top
Hi Jodel32,

doch das steht leider genau so drin :S Ich weiß ist grausam.
Übernehmen will ich alle Response Times. Also der Output sollte dann möglichst so aussehen:

di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121 
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=11ms TTL=121 
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=11ms TTL=121
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
di 02-02-2016 10:52:13,58; Reply from x.x.x.x bytes=1472 time=10ms TTL=121
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
di 02-02-2016 10:52:13,58; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121

di 02-02-2016 10:58:52,79; Reply  from x.x.x.x: bytes=1472 time=10ms TTL=121
di 02-02-2016 10:58:52,79; Reply from x.x.x.x: bytes=1472 time=13ms TTL=121
di 02-02-2016 10:58:52,79; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
di 02-02-2016 10:58:52,79; Reply from x.x.x.x: bytes=1472 time=10ms TTL=121
di 02-02-2016 10:58:52,79; Reply from x.x.x.x: bytes=1472 time=9ms TTL=121
di 02-02-2016 10:58:52,79; Reply from x.x.x.x: bytes=1472 time=10ms TTL=121

Grüsse
martinh80
Mitglied: 114757
Solution 114757 Feb 25, 2016 updated at 19:03:44 (UTC)
Goto Top
Kein Problem ....
# Dateiname der Logdatei
$filename = 'C:\logfile.txt'  
# Dateiname der CSV-Datei
$csv = 'C:\auswertung.csv'  

[regex]::matches((gc $filename | out-String),'(?ism)(\w{2} \d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2},\d*).*?data:[\r\n]*((Reply from.*?$[\r\n]*)*)').Captures | %{  
    $time = $_.Groups[1].Value
    $_.Groups[2].Value -split "`n" | ?{$_ -match 'Reply'} | %{  
       new-object PSObject -Property @{Time=$time;Response=($_ -replace "[\r\n]",'')}  
    }
} | export-csv $csv -NoType -Delimiter ";" -Encoding UTF8  
Member: Martinh80
Martinh80 Feb 25, 2016 at 19:02:46 (UTC)
Goto Top
jodel32, super Sache. Vielen Dank!