Click here to monitor SSC

FatherJack

SQL Q+A forum at ask.sqlservercentral.com | Follow fatherjack on Twitter

Using LogParser - part 4

Published Monday, June 28, 2010 3:00 PM

Welcome to part 4 of this series of blog post about LogParser and apologies for the long gap since part 3, here we are are going to look at continuous data extraction. Previously we have covered starting with LogParser in part 1, how to query and filter data in part 2 and in part 3 we reviewed how to collect data from multiple locations in parallel and how to get that data into a database.

One really neat feature of LogParser is its ability to keep track of the files its importing and skip rows that have already been scanned and only return rows added to the source since the last time it ran. We use a checkpoint file for this and we activate it in a LogParser query with the -icheckpoint switch with a value that is the UNC of a file. We decide what the file is called - its created on the first run of the script - but it has to have a "lpc" file type. In the screen shots below you can see that I am first of all collecting the top 100 entries in the system, security and application event logs on a PC. In the screen captures below  you can see the first run scans almost 141,000 rows of data in about 8 seconds, importing 100 rows into a csv file. This is pretty impressive but we don't really want to repeat that process every time we want more data from the event logs. You can see that in order to achieve this I specify a checkpoint file called AllLogs.lpc in the root of my C:\ drive.

image LogParser "Select top 100 * into C:\AllLogs.csv from \\zoo-pc\system,\\zoo-pc\security,\\zoo-pc\application where eventtype = 4 order by timegenereated desc" -o:csv -icheckpoint:C:\AllLogs.lpc

Running the same query a second time, the checkpoint file is again used and there are 0 rows processed and 0 rows output in 0.08s. This means that the LogParser didn't go through all 141,000 rows again, it simply looked for new rows since the last run. There have been no new rows added to any of the event logs on my PC so, obviously, none were moved to my csv file. In the background the checkpoint file has been updated.

LogParser01

The third image, captured some time later, shows the results when I run the same LogParser query again. We see that 22 rows are processed and 10 are output, this means that the 3 event logs have been added to, with 22 events in total, and that 10 of the new rows qualify for my query and have been added to the AllLogs.csv file. Again, this only took 0.08s, a huge saving over the 8s in the first run. The checkpoint file will, again, have been updated.

LogParser02    

If we now turn our attention to the data we are collecting in the C:\AllLogs.csv file we can make a very quick analysis of the data from LogParser by using the CHART output option. Simply write a LogParser query that returns some aggregated data and choose where you want the image to be created.

LogParser03 LogParser "SELECT SourceName, count(*) as [Number of Events] INTO C:\Events.gif FROM C:\AllLogs.csv Group By Sourcename order by [Number of Events] Desc" -o:CHART -charttype:Column3d

 

 

The resulting file - C:\Events.gif

Chart image 

Other chart types such as Pie and 3D column charts are available and you can create either gif or jpg file types - the LogParser help has all the details and links you need.

Well, that's it for part 4 of this series and we are almost done. In the 5th, and final, part I am going to visit ways of automating LogParser and using it to run in the background to assist with routine data processing. Be sure to be wearing your PowerShell hat next time!

by fatherjack
Filed Under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Twitter Trackbacks for Jonathan Allen : Using LogParser - part 4 [simple-talk.com] on Topsy.com said:

June 29, 2010 2:46 AM
 

Responsibilities Played by a Best Web Hosting Company | Uncategorized | Information about Web Hosting, Web hosting service! said:

June 29, 2010 8:02 AM
 

Jonathan Allen said:

So here we are at the last of the series on using LogParser, before we start here is a list of what you...
July 5, 2010 5:49 PM
 

RAYAN said:

Hi ALL

i need your help.....

i have file as pcap fprmat and i want to converet it to CSV format, could you please tell me what is the command shall i write on the LOGPARSER.

many thanks
December 31, 2011 3:52 PM
 

fatherjack said:

Rayan - I am not aware of the pcap file format that you mention. I would recommend that you visit <a href="http://ask.sqlservercentral.com/">http://ask.sqlservercentral.com/</a> and post your question there, with an example of the format that the data is in and we will gladly help you work out a solution to your problem.
January 2, 2012 12:02 PM

What do you think?

(required) 
(optional)
(required) 

About fatherjack

DBA since 1999 working for not-for-profit company. http://twitter.com/fatherjack,
Latest articles
Checking Out SQL Backup Pro 7’s New Automatic Backup Verification
 Wouldn't it be great to offload the daily chore of checking the integrity of your production... Read more...

Chuck Lathrope: DBA of the Day
 Chuck Lathrope was a finalist for the Exceptional DBA of the Year award in 2009. We contacted him to... Read more...

Backups, What Are They Good For?
 Pixar recently confessed, in an engaging video, that Toy Story 2 was almost lost due to a bad backup,... Read more...

C# Async: What is it, and how does it work?
 The biggest new feature in C#5 is Async, and its associated Await (contextual) keyword. Anybody who is... Read more...

SQL Server 2012 AlwaysOn
 SQL Server AlwaysOn provides a high-availability and Disaster-recovery solution for SQL Server 2012. It... Read more...