用Excel创建SQL server性能报告

Posted 小御

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用Excel创建SQL server性能报告相关的知识,希望对你有一定的参考价值。

转载自Kun Lee “Creating SQL Server performance based reports using Excel”

性能测试调优中对数据库的监控十分重要,使用Excel方便地生成report对我们的工作效率提高也很重要。本文用到的Excel数据在另一篇博文“怎样获取Windows平台下SQL server的性能计数器值”里有详细描写。或者进到本文中给出的博客链接“Setting up Performance Monitor to always collect performance statistics”(下一段中),按照文中方法得到。

Problem

In a previous tip, "Setting up Performance Monitor to always collect performance statistics" I wrote about how to collect performance monitor data,  but once you have the data then what do you do with it.  In this tip I will show you how I use Excel to analyze the data to help determine where your bottlenecks may be and also an easy way to create quick reports and charts for your SQL Servers.

Solution

Before we get started here are a couple of things you will need for this tip.

  • Microsoft Excel 2007 - you also can use Excel 2003 or earlier version but for this tip, I used the latest version.
  • Perfmon trace files at least one day in "csv" format. - if you have a file in "blg" format, you can easily convert it by using the "relog" tool. When I get a chance, I will write another tip about the relog tool and other tools that work well with Perfmon.  To collect data using Perfmon you can review this tip Setting up Performance Monitor to always collect performance statistics

Step 1: Open the csv file

Once you have collected the performance data you can open the csv file using Excel and you should see data similar to the following.

技术分享

Step 2: Adjust the format

To allow easy reporting of the data there are a few things that I do to adjust the data.

  • Replace server name with an empty string - it helps to make reading the counter names easier. In this case I am replacing "\\AREA51\" the name of my server to nothing. (This is optional, but recommended)
技术分享
  • Cell - A1: Replace "(PDH-CSV 4.0) (Eastern Standard Time)(300)" with "Time" (Optional, but recommended)
  • Delete the second row - very often, the first data row has bad data
  • Change COLUMN A cell format to "date time"
技术分享

Final look before we start using it the data.

技术分享

Step 3: Create PivotTable with PivotChart

  • From the Insert menu select PivotTable and then select PivotChart as shown below
技术分享
  • Take the default settings and click "OK"

技术分享
  • After you select the above you will get a screen similar to the following. (to get a bigger workspace area you can close the "PivotChart Filter Pane")

技术分享

Step 4: Let‘s generate our first graph

For this example we will look at CPU

  • From the "PivotTable Field List" select "Time" and drag it into the "Axis Fields (Categories)" area
  • From the "PivotTable Field List" select "Process(_Total)\% Process Time" and drag it into the "Values" area
  • At this point you will have a graph similar to the one shown below
技术分享
  • You can now just select the chart and copy and paste it into a report, an email, Word document etc... as shown below

技术分享
  • If you want to change it from processor time to batch requests you can remove "Process(_Total)\% Process Time" and select "SQLServer:SQL Statistics\Batch Requests/sec" and you will get a chart like below

技术分享

 


Next Steps
  • There are many ways to extend this reporting to make it more useful for both short term and long term needs. In order to do that, it is easier to load the Perfmon data into SQL Server and use the power of SQL Server along with Excel to generate the reports.
  • By using the "relog" tool, you can load the Perfmon data directly into SQL Server
  • By using the "logman" tool, you can setup Perfmon to store the performance data directly to SQL Server
  • To get you started you can download a sample CSV file here with a lot of performance counters
  • Here are a few more examples of reports and charts you can create

Sample 1

技术分享

Sample 2

技术分享

Sample 3

技术分享

 

以上是关于用Excel创建SQL server性能报告的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server 查询性能优化——创建索引原则

如何从 SQL Server Express 中的动态查询创建 RDLC 报告

SQL Server 存储过程性能测试

使用 VB.NET 表单从 SQL Server 到 Excel 的日期数据检索

自定义 SQL Server 性能计数器

从Excel vba中的SQL Server数据中检索/创建记录集