Page 1 of 1

[code] Mini-Monitor and allarm system

Posted: 05 Jul 2012 08:04
by einstein1969
I'm creating a system of monitoring and alarm system to control a PC.

I'm doing it via batch. I began studying the issue for a while and I'm trying to find any workaround for this to end.

Initially it was monitoring the trashing of the disc and take action to suspend certain processes too invasive.

I am trying to eliminate the independence of language, although it is difficult, and with many features yet to be implemented

I hope for your help to improve it and make it more functional and efficient.

mini-monitor.cmd

Code: Select all

@echo off & setlocal EnabledelayedExpansion & goto :multi_thread_dispatcher

Rem Mini-monitor and allarm-system
Rem
rem This use "typeperf", equivalent of grafical perfmon.

Rem Version History:
Rem
Rem 4-11-2013 version 0.03
Rem
Rem           - Revisioned for run in windows 7, not tested on xp
rem           - Add autoconfig
rem           - add rounding function
rem           - cpu usage now is less 1% (0% on my pc) vs 3-4% of version 0.02
rem           - colorize every minute.
rem
Rem 4-07-2012 Version 0.02
Rem
Rem           -Initial version. developed on xp Sp2

Rem Direct and indirect contributors:
Rem Many thanks to aGerman, Ed Dyreen, dbenham, jeb, orange_batch, !k, alan_b, Aacini, Liviu, neorobin and foxidrive.
Rem Initial work by Francesco Poscetti aka einstein1969

:Main

if not exist Mini-Monitor.counter_list.txt call :config

chcp 850 > NUL
mode con COLS=50 LINES=11

set "Color_map=0-0A;1-1B;2-2A;3-4C;4-5D;5-6E;6-8F;7-1E;8-3B"

call :colorize

set t0=%time%
:sync_sec
set tn=%time%
if "%tn:~7,1%"=="%t0:~7,1%" goto :sync_sec

set ID=%random%_%time:,=%_%random%

start "" /b typeperf -cf Mini-Monitor.counter_list.txt %ID% | start "" /b more +2 | start "" /b /HIGH cmd /c %0 read %ID%

rem to implement exit...
pause > nul

goto :eof

:Multi_Thread_dispatcher

  if not "%1"=="" goto %1

goto :Main

:read

call :init_plot

For /L %%c in (1 1 45) do call :plot "Now","0.000000"

For /L %%. in (1,1,1000000) do (

   set /p "ln="
   if errorlevel 1 set "ln=" & verify>nul

   if defined ln    (
            call :plot !ln!
            rem call :allarm_on_range
            set "ln="
         )
   set /a min="%%. %% 60"
   if !min! equ 0 call :colorize
)

goto :eof

:plot (gettime,val1,val2,...,valn)
(
Set Result1=%~2
Set "val=!Result1:~0,-5!"
set "val=!val:.=!"

set /a "val=(val+5)/10,  pos=11-val*10/scalai_max,  step=col %% 4,col=col+1,   step_scalai=scalai_max/10"

Title M.M.[!val!][!time!][%~2]

set "screen="

for /L %%# in (1 1 11) do (

   set /a "odd=%%# %% 2,scalai=scalai_max-(step_scalai*(%%#-1))"

   if !odd! equ 1    ( set "scala=    !scalai!" ) else ( set "scala=    " )

   if !pos! equ %%# ( set "linea%%#=!linea%%#:~1!Ü"
   ) else    (
      if !pos! LSS %%# ( set "linea%%#=!linea%%#:~1!±"
       ) else    (
         if %%# equ 1 (
               if !step! equ 0 (    set "linea%%#=!linea%%#:~1!Â"
               ) else (
                        set "linea%%#=!linea%%#:~1!Ä"
               )
         ) else    (
               set /a "index=!odd!*4+!step!"
               For %%c in ("print_char:~!index!,1") do set ch=!%%~c!
               set "linea%%#=!linea%%#:~1!!ch!"
         )
      )
   )

   if %%# equ 1     (       set "screen=!screen!!scala:~-4! Â!linea%%#!"
   ) else    (
      if %%# equ 11    (   set "screen=!screen!!scala:~-4! Ù!linea%%#!"
      ) else    (
         if !odd! equ 1 (set "screen=!screen!!scala:~-4! Ã!linea%%#!"
         ) else    (
               set "screen=!screen!!scala:~-4! ³!linea%%#!"
         )
      )
   )
)

cls & <nul set/p"=!screen:~0,-1!"

goto :eof
)

:init_plot

   for /L %%# in (1 1 11) do set "linea%%#=                                            "
   set "print_char=³   ÅÄÄı±±±±±±±"
   set /a "scalai_max=100,col=0"

goto :eof

:colorize
  set /a "index=%random% %% 9"
  set ret=!color_map:*%index%-=!
  set ret=%ret:;=&:%
  color %ret%
goto :eof

:config

mode con COLS=100 LINES=45
cls
(
echo The counter is language dependent! If a counter family is not active use the exctrlst.exe ^(extensible counter list^) from resource kit to activate.
echo(
echo There are two step for choice a counter. First choice a counter type and second choice counter instance.
echo(
echo Select a number from follow list to choice a counter type. Press "q" for quicly exit from more or "space" from next page.
echo(
) >%temp%\counter_list_pre.tmp.txt

typeperf -q | find /N /V "." >> %temp%\counter_list_pre.tmp.txt

type %temp%\counter_list_pre.tmp.txt 2>nul | more
echo(

set "counter_num="
set /P "counter_num=Which line number? "

for /F "tokens=1,2 delims=](" %%g in ('type %temp%\counter_list_pre.tmp.txt ^| find "[%counter_num%]"') do set obj=%%h

cls
(
echo For each counter installed and active there is one or more istances. The istance name is beetwen "()". The "_Total" instance is the sum of all instances of the counter.
echo Select a number from follow list to choice a counter instance. Press "q" for quicly exit from more or "space" from next page.
echo(
) >%temp%\counter_list_pre.tmp.txt

typeperf -qx %obj% | find /v "." | find /N "\" >> %temp%\counter_list_pre.tmp.txt

type %temp%\counter_list_pre.tmp.txt 2>nul | more
echo(

set "counter_num="
set /P "counter_num=Which line number? "

for /F "tokens=1,* delims=]" %%g in ('type %temp%\counter_list_pre.tmp.txt ^| find "[%counter_num%]"') do set obj=%%h

echo %obj% > Mini-Monitor.counter_list.txt

Echo Configuration terminated.

pause

goto :eof


For now work for one counter at time... and there aren't action or allarm. First start mini-monitor.config.cmd which help to select counter for your language. Then start mini-monitor.cmd

EDIT: 4/nov/2013 Version 0.03 out . Look in the code for changes.

einstein1969

Re: Mini-Monitor and allarm system

Posted: 05 Jul 2012 10:26
by e4nd
Not working?
Image
Windows XP sp3 Polish version

Re: Mini-Monitor and allarm system

Posted: 05 Jul 2012 16:28
by einstein1969
You could try if it works typeperf?

Start mini-monitor.config.cmd

Output from mini-monitor.config.cmd (italian):

Code: Select all

For each counter installed and active there is one or more istances. The istance
 name is beetwen "()". The "_Total" instance is the sum of all instances of the
counter.
Select a number from follow list to choice a counter instance. Press "q" for qui
cly exit from more or "space" from next page.

[1]\Processore(0)\% Tempo processore
[2]\Processore(_Total)\% Tempo processore
[3]\Processore(0)\% Tempo utente
[4]\Processore(_Total)\% Tempo utente
...


copy the counter instance _Total of Processor counter with name "% Processor Time"

Open a DOS window and type

example in italian:

Code: Select all

typeperf "\Processore(_Total)\% Tempo processore"


post output...

Re: Mini-Monitor and allarm system

Posted: 06 Jul 2012 09:44
by e4nd
everything OK :D
Image

Mini-Monitor.counter_list.txt

Code: Select all

"Procesor(_Total)\Czas procesora (%)"

There is better to use wmic

Code: Select all

@echo off 
for /f "delims=" %%$ in ('
   wmic cpu get loadpercentage ^| find /v "LoadPercentage"') do (
   echo %%$
   )
pause

Re: Mini-Monitor and allarm system

Posted: 04 Nov 2013 11:36
by einstein1969
Hi to all

I worked on this old work.

Version 0.03 is out.
- More efficience (minus of 1% of cpu usage)
- Colorize every minute
- autoconfig (non completed)

Its possible using this how perfmon (wich is grafical equivalent tools)

Thanks to all

Einstein1969