my program is controlling a few performance counter and then on alarm execute an action.
I realized it in batch.
The monitor portion use typeperf.
I tried the otpion with "Performance Log and Alert" on XP sp2 but the alert are send with little control.
I initially tried with a "lock"
Code: Select all
@echo off&Setlocal EnableDelayedExpansion
rem ECHO
rem echo %time%
2>NUL (
> C:\PerfLogs\suspend.lock.log (
echo [!TIME!] B %* >> C:\PerfLogs\suspend.counter.log
C:\PerfLogs\pssuspend.exe emule.exe >NUL
ping 192.0.2.0 -n 1 -w 500 >nul 2>&1
C:\PerfLogs\pssuspend.exe -r emule.exe >NUL
echo [!TIME!] E >> C:\PerfLogs\suspend.counter.log
verify >nul
)
)
rem Echo %time%
this work but there are limitation on this method.
I then tried typeperf but there is a problem with catch data and analyze in real time.
I tried this code found in internet
Code: Select all
...
for /f "skip=1 tokens=3 delims=, " %%i in ('typeperf "\ASP.NET State Service\State Server Sessions Active" -sc 1 -s %COMP% ^| find ","') do (set RESULT=%%~i)
...
that capture a single line but every time this is run use a lot of CPU.
then I read this viewtopic.php?f=3&t=2128&start=0
and then i tried .....
Process 1:
Code: Select all
...
typeperf -sc 600 "\Disco fisico(_Total)\%% Tempo disco" "\Processore(_Total)\%% Tempo processore" | more +2 > %name_windows%.typeperf_a.log
...
EDIT: This out 600 Line and then leave the lock on log for LOG clean. I use log ROTATE for problem of concurrent access with process 2.
i launch with
Code: Select all
...
Start "%name_windows%.monitor" /min /High cmd /v:on /c "%0 monitor"
...
Process 2:
Code: Select all
...
setlocal enableDelayedExpansion
:continua.allarm_sched
set file="%name_windows%.typeperf_a.log"
set start=%time%
for /f %%n in ('type %file%^|find /c /v ""') do set /a lines=%%n
set stop=%time%
call :difftime "%start%" "%stop%" 1000 "Carica linee [%lines%]"
echo(
set /a seek=lines
rem echo linee = %lines%
Rem Risincronizzazione. 64 Normale, 8-16 Debug
<%file% (
for /l %%l in (1 1 %seek%) do ( set /p "=" )
for /l %%l in (1 1 64) do (
set /p "ln="
rem echo [!time!] %%l = !ln!
if defined ln call :_typeperf !ln! Val1 Val2 Val3
echo [!time!] %%l ^(!ln:~12,11!^) HDD:!val1! CPU:!val2!
call :ritardo_1sec
)
)
echo(
rem echo [!time!] Ultima Letta =!ln!
goto :continua.allarm_sched
...
The process 2 read the log of process 1 with a difference of few seconds 1, 2 or 3 (LATENCY?)
Actually:
PROCESS 1 (out 1 line/SEC) ------> LOGS <------ PROCESS 2 (in 1 line/(SEC minus X)
process 2 read faster than process 1
I read 64 lines or 16 or 1000 and then i exit from the loop for eventually resincronize.
When resincronize i count number of lines of log for SEEK and position for read
But i try to eliminating this fase for use less CPU and minimize blind spots.
There is a methos for minimize latency and AUTO-sincronyze ?
I can send entire code if necessary. Sorry for my bad english!
Einstein1969