IT:AD:Performance Counters:HowTo:Trace To SQL Server
Summary
There are two ways of tracing Performance Counters to a Database.
Process
Using PerfMon and a Data Collector
One way is to use Perfmon, * Create a SqlServer Database * Create an system ODBC Data Source pointing to the above SqlServer database, * create a Data Collector Set, * create a Create a Data collector that collects data and outputs it the ODBC
…but I'd recommend against it. There's an easier way.
Use TypePerf
C:\VC>TYPEPERF -f SQL "\Process(*)\ID Process" -si 5 -o SQL:perfstuffDSN!log ... The command completed successfully.
The above statement outputs information about all processes to the given table.
Database schema
CREATE TABLE [dbo].[CounterData]( [GUID] [uniqueidentifier] NOT NULL, [CounterID] [int] NOT NULL, [RecordIndex] [int] NOT NULL, [CounterDateTime] [char](24) NOT NULL, [CounterValue] [float] NOT NULL, [FirstValueA] [int] NULL, [FirstValueB] [int] NULL, [SecondValueA] [int] NULL, [SecondValueB] [int] NULL, [MultiCount] [int] NULL, PRIMARY KEY CLUSTERED ( [GUID] ASC, [CounterID] ASC, [RecordIndex] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO CREATE TABLE [dbo].[CounterDetails]( [CounterID] [int] IDENTITY(1,1) NOT NULL, [MachineName] [varchar](1024) NOT NULL, [ObjectName] [varchar](1024) NOT NULL, [CounterName] [varchar](1024) NOT NULL, [CounterType] [int] NOT NULL, [DefaultScale] [int] NOT NULL, [InstanceName] [varchar](1024) NULL, [InstanceIndex] [int] NULL, [ParentName] [varchar](1024) NULL, [ParentObjectID] [int] NULL, [TimeBaseA] [int] NULL, [TimeBaseB] [int] NULL, PRIMARY KEY CLUSTERED ( [CounterID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[DisplayToID]( [GUID] [uniqueidentifier] NOT NULL, [RunID] [int] NULL, [DisplayString] [varchar](1024) NOT NULL, [LogStartTime] [char](24) NULL, [LogStopTime] [char](24) NULL, [NumberOfRecords] [int] NULL, [MinutesToUTC] [int] NULL, [TimeZoneName] [char](32) NULL, PRIMARY KEY CLUSTERED ( [GUID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY], UNIQUE NONCLUSTERED ( [DisplayString] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO
Querying the Data
SELECT LEFT(dbo.CounterData.CounterDateTime, 10) AS Date, SUBSTRING(dbo.CounterData.CounterDateTime, 12, 8) AS Time, dbo.CounterData.CounterValue,dbo.CounterDetails.MachineName, dbo.CounterDetails.ObjectName, dbo.CounterDetails.CounterName, dbo.CounterDetails.InstanceName FROM dbo.CounterData INNER JOIN dbo.CounterDetails ON dbo.CounterData.CounterID = dbo.CounterDetails.CounterID -- WHERE CounterName = 'Bytes Received/sec' ORDER BY Date ASC, TIME ASC
Resources
* http://technet.microsoft.com/en-us/library/bb490960.aspx * http://www.sepago.de/e/nicholas/2009/11/02/performance-monitoring-part-7-using-performance-monitor-with-a-database * https://www.simple-talk.com/sql/performance/collecting-performance-data-into-a-sql-server-table/ * https://social.technet.microsoft.com/wiki/contents/articles/12457.pushing-the-performance-monitor-data-into-a-database.aspx