sexta-feira, novembro 30, 2012

IIS Recycle automático


Como configurar limites de memória nas APP Pools do IIS

Sempre que se configura um site de IIS é conveniente proceder à limitação da memória em uso por essa AppPool de forma a que sempre que ultrapassar esse limite vai forçar a matar os processos pendentes desse site, ou seja, matará falhas derivadas de erros de programação como processos que não têm o kill correpondente e ou não é feito o recycle dentro da própria aplicação/site.

========================================================

The same setting hasn't been changed since IIS 6.0.

In IIS mmc, click Application Pools. Right-click a pool and select Advanced
Settings. In Recycling section, you will see there are two settings:
Private Memory Limit (KB) and Virtual Memory Limit (KB) .

When any of these 2 settings are set, if the worker process exceeds the
private or virtual memory quota, IIS will recycle that pool which limits
the memory usage.


========================================================

Dificuldades já conhecidas:

All the limits in the application pool are for bad behaving apps. And more specifically:
  1. To prevent the bad app from disturbing to good apps.
  2. To try and keep the bad app running as much as possible.
In that light, the answer is off course: It depends.
If your application is leaking then without a limit it will crash around 1.2 - 1.6 Gb (if memory serves). So 1 Gb is sensible. If during normal operation your application consume not more the 100 Mb and you have many app pool on the server, than you should set the limit lower to prevent one app from damaging other apps.
To conclude. 1 Gb is sensible. Hitting the limits should be treated as application crash and debugged and fixed.

Want to learn more:

http://blogs.msdn.com/b/pfedev/archive/2009/01/22/memory-based-recycling-in-iis-6-0.aspx


segunda-feira, novembro 19, 2012

How to use IIS Logs with LOGPARSER

Exemplo de pesquisa do logparser para logs de iis

LogParser -i:IISW3C "SELECT * FROM \\servername\LogsConsolidation\Repository\W3C3\*.log WHERE cs-uri-stem  '/imagesSite/cover.jpg' " -o:CSV > C:\HitsCovers.csv
Resultado:

 
 
Outro exemplo agora com datas:
 
LogParser -i:IISW3C "SELECT * FROM \\ServerName\LogsConsolidation\Repository\W3C3\*.log WHERE cs-uri-stem = '/imagesServerName/imgCovers.jpg' AND (DATE >= '2012-11-16' AND DATE <= '2012-11-23')  " -o:CSV > C:\HitsCovers_Nov16_23.csv

How to use LogParser for Windows

O LogParser é uma tool potente de utilização em Windows para fazer pesquisa em Logs de IIS ou outros.
Tem parametrizações especificas para vários tipos de Logs.

Sites com info:

http://technet.microsoft.com/pt-br/library/cc779255(v=ws.10).aspx
http://technet.microsoft.com/en-us/scriptcenter/dd919274.aspx
http://support.microsoft.com/kb/910447
http://en.wikipedia.org/wiki/Logparser

Exemplos vários para LogParser:

Comando LOG PARSER
==> CSV
logparser "SELECT Count(EventID) AS Contador, ComputerName, EventID, EventTypeName, to_string(TimeGenerated,'yyyy-MM-dd hh:mm') AS DateEvent, Strings  from *.evt to EventViewerVDFAPPs_v2.csv WHERE TimeGenerated > timestamp('01-03-2011', 'dd-MM-yyyy') AND Strings
like'%Fail to obtain widget menu%' GROUP BY ComputerName, EventID, EventTypeName, DateEvent, Strings ORDER BY DateEvent Desc" -o:CSV
==> XML
logparser "SELECT Count(EventID) AS Contador, ComputerName, EventID, EventTypeName, to_string(TimeGenerated,'yyyy-MM-dd hh:mm') AS DateEvent, Strings  from *.evt to EventViewerVDFAPPs_v2.xml WHERE TimeGenerated > timestamp('01-03-2011', 'dd-MM-yyyy') AND Strings
like'%exception%' GROUP BY ComputerName, EventID, EventTypeName, DateEvent,Strings ORDER BY DateEvent Desc" -o:XML


-- PPI: Comando para ficheiros log de IIS e apanhar webservices e erros 500logparser "SELECT * FROM *.log to pires500.csv WHERE TEXT LIKE '%GETGROUPGRANTEDKEYS%' AND TEXT LIKE '% 500 %' " -o:csv
logparser ComputerName, EventId, EventType, SourceName, count(*) From 'STG-ASVR-*.Application.evt' to 'EventLogResult.csv' group by computername, eventId, EventType, SourceName Order By computername, eventtype, eventid" -o:CSV
logparser "Select ComputerName,to_string(TimeGenerated,'yyyy-MM-dd') as Day, EventTypeName, count(*) From 'STG-ASVR-*.Application.evt' to 'EventLogResult.csv' group by computername, Day, EventTypeName Order By computername, Day, eventtypeName" -o:CSV

-- PPI: Obtem os dados do EventViewer para um CSV do Evento 16571 (CCSKIPS)logparser "SELECT Count(EventID) AS Contador, ComputerName, EventID, EventTypeName, to_string(TimeGenerated,'yyyy-MM-dd hh:mm') AS DateEvent from mon-asvr-*_App.evt to EventViewerMON_ASVR.csv WHERE EventID = 16571 GROUP BY ComputerName, EventID, EventTypeName,
DateEvent ORDER BY DateEvent Desc" -o:CSV
-- PPI: Obtem dados dentro de um determinado período
logparser "SELECT ComputerName, EventID, EventTypeName, Strings, to_string(TimeGenerated,'yyyy-MM-dd hh:mm') AS DateEvent from CAX-DSVR-02_App.evt WHERE TimeGenerated < timestamp('30-09-2008','dd-MM-yyyy')  AND TimeGenerated > timestamp('20-09-2008', 'dd-MM-yyyy') 
GROUP BY ComputerName, EventID, EventTypeName, Strings, DateEvent ORDER BY DateEvent Desc"
logparser "SELECT ComputerName, EventID, EventTypeName, Strings, to_string(TimeGenerated,'yyyy-MM-dd hh:mm') AS DateEvent from CAX-DSVR-02_App.evt WHERE TimeGenerated < timestamp('30-09-2008','dd-MM-yyyy')  AND TimeGenerated > timestamp('20-09-2008', 'dd-MM-yyyy') 
GROUP BY ComputerName, EventID, EventTypeName, Strings, DateEvent ORDER BY DateEvent Desc"

-- PPI: Obter dados do Strings também (sem o Enter > falta descobrir o char)logparser "SELECT ComputerName, EventID, EventTypeName, to_string(TimeGenerated,'yyyy-MM-dd hh:mm') AS DateEvent, REPLACE_CHR(Message, '£', '') AS Message from CAX-DSVR-02_App.evt to Pesquisa.csv WHERE TimeGenerated < timestamp('30-09-2008','dd-MM-yyyy')  AND
TimeGenerated > timestamp('20-09-2008', 'dd-MM-yyyy')  GROUP BY ComputerName, EventID, EventTypeName, Message, DateEvent ORDER BY DateEvent Desc" -o:CSV

-- PPI: Obter dados de servidoreslogparser "SELECT ComputerName, EventId, EventTypeName, to_string(TimeGenerated, 'yyyy-MM-dd hh:mm') AS EventDate, Count(1) as CountEvents FROM EventLog_20081015.evt where EventId = 14206 GROUP BY ComputerName, EventID, EventTypeName, EventDate ORDER BY
EventDate DESC"

-- PPI: Looking for IP
logparser "SELECT ComputerName, EventId, EventTypeName, to_string(TimeGenerated, 'yyyy-MM-dd hh:mm') AS EventDate, Count(1) as CountEvents FROM EventLog_20081015.evt where EventId = 14206 and Strings like '%10.193.219.107%' GROUP BY ComputerName, EventID,
EventTypeName, EventDate ORDER BY EventDate DESC"
logparser "SELECT ComputerName, EventId, EventTypeName, to_string(TimeGenerated, 'yyyy-MM-dd hh:mm') AS EventDate, Count(1) as CountEvents FROM EventLog_20081015.evt where EventId = 14206 and Strings not like '%10.193.219.107%' GROUP BY ComputerName, EventID,
EventTypeName, EventDate ORDER BY EventDate DESC"

-- PPI: Para um determinado EventIDlogparser "SELECT UserName, ComputerName, EventId, EventTypeName, to_string(TimeGenerated, 'yyyy-MM-dd hh:mm') AS EventDate FROM *.evt to 'EventsSFB01_12994' where EventId = 12994 ORDER BY EventDate DESC" -o:csv
logparser "SELECT ComputerName, EventId, EventTypeName, to_string(TimeGenerated, 'yyyy-MM-dd hh:mm') AS EventDate, Count(1) as CountEvents FROM *.evt to 'EventsSFB01_12994' where EventId = 12994 GROUP BY ComputerName, EventID, EventTypeName, EventDate ORDER BY
EventDate DESC" -o:csv

-- PPI: Para obter uma lista em XML de uma determinada string em Logs de IISLogParser -i:TEXTLINE "SELECT * FROM \\Alfr-log-01\LogsConsolidation\Repository\W3C3\*.log WHERE Text like '%PromoFriends.jpg%'" -o:xml > C:\Oper\LogParser\WIDGETS\PromoFriends2.xml

quarta-feira, novembro 14, 2012

Most Common FTP errors

CodeDescription
100 CodesThe requested action is being taken. Expect a reply before proceeding with a new command.
110Restart marker reply.
120Service ready in (n) minutes.
125Data connection already open, transfer starting.
150File status okay, about to open data connection.
200 CodesThe requested action has been successfully completed.
200Command okay.
202Command not implemented
211System status, or system help reply.
212Directory status.
213File status.
214Help message.
215NAME system type. (NAME is an official system name from the list in the Assigned Numbers document.)
220Service ready for new user.
221Service closing control connection. (Logged out if appropriate.)
225Data connection open, no transfer in progress.
226Closing data connection. Requested file action successful (file transfer, abort, etc.).
227Entering Passive Mode
230User logged in, proceed.
250Requested file action okay, completed.
257"PATHNAME" created.
300 CodesThe command has been accepted, but the requested action is being held pending receipt of further information.
331User name okay, need password.
332Need account for login.
350Requested file action pending further information.
400 CodesThe command was not accepted and the requested action did not take place.
The error condition is temporary, however, and the action may be requested again.
421Service not available, closing control connection. (May be a reply to any command if the service knows it must shut down.)`
425Can't open data connection.
426Connection closed, transfer aborted.
450Requested file action not taken. File unavailable (e.g., file busy).
451Requested action aborted, local error in processing.
452Requested action not taken. Insufficient storage space in system.
500 CodesThe command was not accepted and the requested action did not take place.
500Syntax error, command unrecognized. This may include errors such as command line too long.
501Syntax error in parameters or arguments.
502Command not implemented.
503Bad sequence of commands.
504Command not implemented for that parameter.
530User not logged in.
532Need account for storing files.
550Requested action not taken. File unavailable (e.g., file not found, no access).
552Requested file action aborted, storage allocation exceeded
553Requested action not taken. Illegal file name.

http://www.theegglestongroup.com/writing/ftp_error_codes.php

segunda-feira, novembro 12, 2012

Lista de ocupação por diretorias

Quando em DOS temos problemas em obter uma lista da ocupação de diretorias, poder-se-á usar o seguinte script e comando:

diskusage.bat [dir] /L > ficOutput.txt

=============================================
@ECHO OFF
CLS
:: Use local variables
IF "%OS%"=="Windows_NT" SETLOCAL
:: Check command line arguments and Windows version
ECHO.%1 | FIND "/" >NUL
IF NOT ERRORLEVEL 1 IF /I NOT "%~1"=="/L" GOTO Syntax
ECHO.%1 | FIND "?" >NUL
IF NOT ERRORLEVEL 1 GOTO Syntax
ECHO.%1 | FIND "*" >NUL
IF NOT ERRORLEVEL 1 GOTO Syntax
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
IF NOT "%~1"=="" IF /I NOT "%~1"=="/L" IF NOT EXIST "%~1" GOTO Syntax
SET LongFormat=1
IF /I NOT "%~1"=="/L" IF /I NOT "%~2"=="/L" SET LongFormat=0
:: Go to start directory
SET StartDir=%CD%
IF NOT "%~1"=="" IF /I NOT "%~1"=="/L" SET StartDir=%~1
PUSHD "%StartDir%"
IF ERRORLEVEL 1 GOTO Syntax
:: Display header
ECHO Directory Space used (MB)
ECHO.========= ===============
:: Display disk usage for start directory
IF NOT EXIST *.* GOTO SubDirs
FOR /F "tokens=3,4*" %%A IN ('DIR %1 /A-D /-C ^| FIND /I "File(s)"') DO SET ListDir=%%A
:: Different procedures depending on /L switch
IF "%LongFormat%"=="1" GOTO LongFormat
SET /A ListDir=%ListDir%+524288
SET /A ListDir=%ListDir%/1048576
ECHO..\ %ListDir%
SET ListDir=
GOTO SubDirs
:LongFormat
:: Strip last 6 digits from value
SET ListDir=%ListDir:~0,-6%
IF NOT DEFINED ListDir SET ListDir=0
:: Display resulting value in MB
ECHO..\ %ListDir%
:: Clear variable
SET ListDir=

:: Display disk usage for every subdirectory
:SubDirs
FOR /D %%A IN (*.*) DO CALL :List%LongFormat% "%%~A"
:: Done
POPD
GOTO End

:List0
:: Set variable value to bytes used by directory
FOR /F "tokens=3,4*" %%B IN ('DIR /A /-C /S "%~1" ^| FIND /I "File(s)"') DO SET ListDir=%%~B
:: Add 0.5MB in order to properly round the value when integer divided by 1MB
SET /A ListDir=%ListDir%+524288
:: Integer divide by 1MB
SET /A ListDir=%ListDir%/1048576
:: Display resulting value in MB
ECHO.%~1 %ListDir%
:: Clear variable
SET ListDir=
GOTO:EOF

:List1
:: Set variable value to bytes used by directory
FOR /F "tokens=3,4*" %%B IN ('DIR /A /-C /S "%~1" ^| FIND /I "File(s)"') DO SET ListDir=%%~B
:: Strip last 6 digits from value
SET ListDir=%ListDir:~0,-6%
IF NOT DEFINED ListDir SET ListDir=0
:: Display resulting value in MB
ECHO.%~1 %ListDir%
:: Clear variable
SET ListDir=
GOTO:EOF

:Syntax
ECHO.
ECHO DiskUse, Version 5.01 for Windows 2000 / XP
ECHO Display disk space used by subdirectories (tab delimited)
ECHO.
ECHO Usage:  DISKUSE  [ startdir ]  [ /L ]
ECHO.
ECHO Where:  "startdir"  is the directory containing subdirectories to be
ECHO                     inventoried (default is the current directory)
ECHO         "/L"        is used for large numbers, over 2GB, to prevent return
ECHO                     of negative numbers due to batch math limitations
ECHO                     (integer division by 1000000 instead of properly
ECHO                     rounded mathematical division by 1048576)
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
:End
IF "%OS%"=="Windows_NT" ENDLOCAL


=============================================
Resultado:

Directory Space used (MB)
========= ===============
.\ 0
Dir1 8893
Dir2 29
Dir3 29
Dir4 1334
Dir5 1333
Dir6 1463
Dir7 1326
Dir8 1546

Link Original:
http://www.tomshardware.co.uk/forum/117561-35-folder-size-command

Script Original:
http://www.robvanderwoude.com/files/diskuse_2k.txt