Advanced Log Parser Charts Part 1 - Working With Configuration Scripts
来源:互联网 发布:mac 删除文件找回 编辑:程序博客网 时间:2024/05/17 18:01
http://blogs.msdn.com/b/carloc/archive/2008/08/07/charting-with-logparser.aspx
I recently had a situation where I wanted to customize the chart output from Log Parser, and after a bunch of research I eventually arrived at the conclusion that configuration scripts for create customized charts are probably the least-documented feature of Log Parser. After a lot of experimentation, (and a bit of frustration), I finally managed to achieve the results that I wanted. With that in mind, I thought that it would make a great blog series if I documented some of the settings that I used.
Log Parser and Chart Configuration Scripts
When you look in the Log Parser help file, it makes mention of using configuration scripts to customize charts, and it provides the following small JavaScript sample:
// Add a captionchartSpace.HasChartSpaceTitle = true;chartSpace.ChartSpaceTitle.Caption = "Generated by Log Parser 2.2";chartSpace.ChartSpaceTitle.Font.Size = 6;chartSpace.ChartSpaceTitle.Position = chartSpace.Constants.chTitlePositionBottom;// Change the background colorchart.PlotArea.Interior.Color = chartSpace.Constants.chColorNone;
Unfortunately, this sample isn't very useful, although I found dozens of forum posts that quote this sample as a way to do things - but it's the only sample that most people cite. The Log Parser help file mentions looking at the MSDN ChartSpace Object Model documentation, but that documentation is only slightly more useful. These two references are what led me to my earlier conclusion that chart configuration scripts are not well-documented, and especially when you are trying to do something with Log Parser.
What I found to be particularly helpful was to use the Log Parser COM interface and write scripts by using Adersoft's VbsEdit and JsEdit. In case you haven't used either of those applications, they are great IDEs for writing scripts; they both give you a great debugging environment, and they have a great object browser that I used to discover what options were available to me. In the end, these two editors made it possible to create the chart configuration scripts that I will discuss in this blog series.
By the way, chart configuration scripts can be written in VBScript or JavaScript, but for this blog I will use VBScript for the Log Parser COM samples and JavaScript for the configuration script samples. I didn't have to do it that way, but it seemed like a good idea to help differentiate between the samples.
Using COM versus the Command-Line
For the samples in this blog series, I will use Log Parser's COM interface and VBScript to create my charts, but this is not necessary; everything that I am documenting can be done from the command-line version of Log parser, and I'll give you some quick examples to see the differences.
The following examples generate some simple area charts that plot the total number of hits by day, and both examples do exactly the same thing:
Command-Line:
logparser.exe "
COM Interface:
Option ExplicitDim objLogQuery, strSQLDim objInputW3CFormat, objOutputChartFormatSet objLogQuery = WScript.CreateObject("MSUtil.LogQuery")Set objInputW3CFormat = WScript.CreateObject("MSUtil.LogQuery.W3CInputFormat")Set objOutputChartFormat = WScript.CreateObject("MSUtil.LogQuery.ChartOutputFormat")strSQL = "SELECT Date, COUNT(*) AS Hits " & _ " INTO HitsByDay.gif " & _ " FROM *.log " & _ " GROUP BY Date " & _ " ORDER BY Date"objOutputChartFormat.groupSize = "800x600"objOutputChartFormat.fileType = "GIF"objOutputChartFormat.chartType = "Area"objOutputChartFormat.categories = "ON"objOutputChartFormat.values = "ON"objOutputChartFormat.legend = "OFF"objLogQuery.ExecuteBatch strSQL, objInputW3CFormat, objOutputChartFormat
Ugly Charts
Using some of the log files from one of my websites, the above samples created the following basic chart:
Taking a look at this chart makes it easy to see why you would want to customize your output; that light blue is pretty awful, and those values are pretty hard to read.
Specifying Configuration Scripts
If you remember the incredibly basic configuration script from earlier, you only need to add one parameter to each example in order to specify the configuration script:
Command-Line:
logparser.exe "
COM Interface:
Option ExplicitDim objLogQuery, strSQLDim objInputW3CFormat, objOutputChartFormatSet objLogQuery = WScript.CreateObject("MSUtil.LogQuery")Set objInputW3CFormat = WScript.CreateObject("MSUtil.LogQuery.W3CInputFormat")Set objOutputChartFormat = WScript.CreateObject("MSUtil.LogQuery.ChartOutputFormat")strSQL = "SELECT Date, COUNT(*) AS Hits " & _ " INTO HitsByDay.gif " & _ " FROM *.log " & _ " GROUP BY Date " & _ " ORDER BY Date"objOutputChartFormat.groupSize = "800x600"objOutputChartFormat.fileType = "GIF"objOutputChartFormat.chartType = "Area"objOutputChartFormat.categories = "ON"objOutputChartFormat.values = "ON"objOutputChartFormat.legend = "OFF"objOutputChartFormat.config = "HitsByDay.js"objLogQuery.ExecuteBatch strSQL, objInputW3CFormat, objOutputChartFormat
Simple Output
Taking a look at the resulting chart, you can see why I mentioned earlier that the configuration script wasn't very useful; all it does is add a centered title to the bottom of the chart:
Yup - that's a pretty useless sample configuration script for chart customization.
Next...
In my subsequent posts, I'll show how to make this chart (and several other types of charts) look a lot better.
- Advanced Log Parser Charts Part 1 - Working With Configuration Scripts
- Working with Events, part 1
- Working with Events, part 2
- Groovy Goodness: Using ConfigSlurper with Configuration Scripts Groovy读取配置文件
- Working with Configuration Files (app.config) in C++/CLI
- Working with Configuration Files (app.config) in C++/CLI
- Oracle BPM: Working with Tasks Programmatically (Part II)
- Asp.net Configuration Part(1)
- Chapter 1: Working with strings
- Working with FBX SDK (1)
- VNC configuration scripts
- Advanced Memory Management: Dynamic Allocation, Part 1
- Log Parser 2.2
- Log Parser 2.2
- Microsoft Log Parser Toolkit
- Log Parser 脚本实例
- OCP_052_51 automate this configuration for the memory components with change in mode of working
- ConfigParser — Configuration file parser
- 分布式系统的事务处理
- MVC中如何将后台封装好的Web控件发到前台视图显示
- 应用程序服务器Application Server
- ctags的常用方法
- Max-age、Expires与Cache-control
- Advanced Log Parser Charts Part 1 - Working With Configuration Scripts
- Java如何获取系统信息(包括操作系统、jvm、cpu、内存、硬盘、网络、io等)
- Hibernate学习_020_一级缓存+二级缓存+三级缓存(查询缓存)
- android之无返回结果跳转intent
- 第五章思维导图
- servlet中的一些小细节
- 一种基于构造测量矩阵的称球问题求解方法
- LinQ To Objects 高级查询方法
- Unable to start service Intent问题解决