pall
pall

Reputation: 143

LogParser get results from last hour

I have cpu monitors constantly workning on my computer. I would like log parser to parse results only from the last hour. does anyone know how to do that?

SELECT TO_STRING(QUANTIZE(TO_TIMESTAMP(Field1, 'mm/dd/yyyy HH:mm:ss.ll'),10 ), 'hh:mm:ss') AS Time, AVG(TO_REAL(Field2)) AS Cpu
INTO .\output\cpu.csv
FROM .\logs\*.csv   
WHERE Time >= SUB( TO_LOCALTIME(SYSTEM_TIMESTAMP()), TIMESTAMP('0000-01-02', 'yyyy-MM-dd') )

the last line results with an error. does anyone know how can i do that? thanks!

Upvotes: 3

Views: 7389

Answers (1)

James Skemp
James Skemp

Reputation: 8581

Your WHERE clause is wrong; instead of pulling 1 hour, you're pulling 1 day.

The following worked on IIS logs:

SELECT TO_STRING(QUANTIZE(TO_TIMESTAMP(date, time),10 ), 'hh:mm:ss') AS Time
INTO asdf.csv
FROM W3SVC5\*ex*.log
WHERE TO_LOCALTIME(TO_TIMESTAMP(date, time)) >= SUB( TO_LOCALTIME(SYSTEM_TIMESTAMP()), TIMESTAMP('0000-01-01 01:00', 'yyyy-MM-dd HH:mm') )

For your particular case you should be safe just using this bit of the WHERE clause:

SUB( TO_LOCALTIME(SYSTEM_TIMESTAMP()), TIMESTAMP('0000-01-01 01:00', 'yyyy-MM-dd HH:mm') )

Upvotes: 8

Related Questions