<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tim laqua dot com &#187; performance counters</title>
	<atom:link href="http://timlaqua.com/tag/performance-counters/feed/" rel="self" type="application/rss+xml" />
	<link>http://timlaqua.com</link>
	<description>Thoughts and Code from Tim Laqua</description>
	<lastBuildDate>Fri, 16 Mar 2012 16:48:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Monitoring, Starting, and Stopping Perfmon Performance Counter Logs using VBScript</title>
		<link>http://timlaqua.com/2008/11/monitoring-starting-and-stopping-perfmon-performance-counter-logs-using-vbscript/</link>
		<comments>http://timlaqua.com/2008/11/monitoring-starting-and-stopping-perfmon-performance-counter-logs-using-vbscript/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 20:52:09 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[counter log]]></category>
		<category><![CDATA[counters]]></category>
		<category><![CDATA[logman]]></category>
		<category><![CDATA[perfmon]]></category>
		<category><![CDATA[performance counters]]></category>
		<category><![CDATA[registry]]></category>
		<category><![CDATA[syslog]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=53</guid>
		<description><![CDATA[Performance counters are great - unless they're not running. So this script illustrates one approach to monitoring the Performance Counter Logs on a given machine, starting them when they stop (for whatever reason) and letting someone know about it. UPDATE For 2008+ Data Collector Sets: Monitoring and Starting Data Collector Sets with Powershell I check [...]]]></description>
			<content:encoded><![CDATA[<p>Performance counters are great - unless they're not running.  <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   So this script illustrates one approach to monitoring the Performance Counter Logs on a given machine, starting them when they stop (for whatever reason) and letting someone know about it.</p>
<p><strong>UPDATE For 2008+ Data Collector Sets: <a href="http://timlaqua.com/2011/10/monitoring-and-starting-data-collector-sets-with-powershell/" title="Monitoring and Starting Data Collector Sets with Powershell">Monitoring and Starting Data Collector Sets with Powershell</a></strong></p>
<p>I check the registry to determine the current state of a counter log, and use the <strong>logman</strong> command line utility to start the log when needed.  Logman can also tell you the state of the counters, but it's crazy slow.  I've been unable to locate a way to do all of this using WMI and the interweb has been less helpful than usual on this issue.  So here's my solution:<br />
<span id="more-53"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Const</span> HKLM = &amp;H80000002
<span style="color: #000080;">Set</span> arrRunningCounterLogs = CreateObject( &quot;System.Collections.ArrayList&quot; )
<span style="color: #000080;">Set</span> arrStoppedCounterLogs = CreateObject( &quot;System.Collections.ArrayList&quot; )
<span style="color: #000080;">Set</span> dictCounterLogs = CreateObject( &quot;Scripting.Dictionary&quot; )
&nbsp;
<span style="color: #008000;">' ================= START Configuration Settings
</span>
strComputer = &quot;.&quot;
arrCounterLogExclusionList = Array(&quot;System Overview&quot;,&quot;PerfWiz&quot;)
strExchangeServer = &quot;smtpServer&quot;
strScriptEmailIdentity = &quot;&quot;&quot;PerfMonMon.vbs&quot;&quot; &lt;tim@timlaqua.com&gt;&quot;
strLogStartEmailRecipients = &quot;tim@timlaqua.com&quot;
&nbsp;
<span style="color: #008000;">' ================= END Configuration Settings
</span>
strBasePath =&quot;SYSTEM\CurrentControlSet\Services\SysmonLog\Log Queries&quot;
<span style="color: #000080;">Set</span> oReg=GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; _ 
    strComputer &amp; &quot;\root\default:StdRegProv&quot;)
&nbsp;
oReg.EnumKey HKLM, strBasePath, arrSubKeys
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> subkey <span style="color: #000080;">In</span> arrSubKeys
	strLogKeyPath = strBasePath &amp; &quot;\&quot; &amp; subkey
	oReg.GetStringValue HKLM, strLogKeyPath, &quot;Collection Name&quot;, strCollectionName
&nbsp;
	<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> InArray(strCollectionName, arrCounterLogExclusionList) <span style="color: #000080;">Then</span>
		dictCounterLogs.Add strCollectionName, strLogKeyPath
		<span style="color: #000080;">If</span> IsLogRunning(strCollectionName) <span style="color: #000080;">Then</span>
			arrRunningCounterLogs.Add(strCollectionName)
		<span style="color: #000080;">Else</span>
			arrStoppedCounterLogs.Add(strCollectionName)
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">Next</span>
&nbsp;
<span style="color: #000080;">If</span> arrStoppedCounterLogs.Count &gt; 0 <span style="color: #000080;">Then</span>
	<span style="color: #000080;">Set</span> oShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
	boolErrors = <span style="color: #000080;">False</span>
&nbsp;
	<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> strCounterLog <span style="color: #000080;">in</span> arrStoppedCounterLogs
		oShell.Run &quot;logman start &quot;&quot;&quot; &amp; strCounterLog &amp; &quot;&quot;&quot; -s &quot; &amp; strComputer, 0, <span style="color: #000080;">True</span>
&nbsp;
		<span style="color: #000080;">If</span> IsLogRunning(strCounterLog) <span style="color: #000080;">Then</span>
			strMessage = strMessage &amp; &quot;  &quot; &amp; strCounterLog &amp; _
						 &quot; was stopped - started log at &quot; &amp; Now &amp; vbCrLf
		<span style="color: #000080;">Else</span>
			strMessage = strMessage &amp; _
						 &quot;  <span style="color: #000080;">ERROR</span>: Unable <span style="color: #000080;">to</span> start &quot; &amp; strCounterLog &amp; vbCrLf
			boolErrors = <span style="color: #000080;">True</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #000080;">If</span> boolErrors <span style="color: #000080;">Then</span>
		strSubject = &quot;Stopped Counter Log Alert - Some counters could <span style="color: #000080;">not</span> be started&quot;
	<span style="color: #000080;">Else</span>
		strSubject = &quot;Stopped Counter Logs Detected - Counter Logs Started&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	SendEmail strExchangeServer, strScriptEmailIdentity, strLogStartEmailRecipients, strSubject, strMessage
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
<span style="color: #000080;">Function</span> InArray(needle, haystack) <span style="color: #008000;">'As Boolean
</span>	InArray = <span style="color: #000080;">False</span>
	<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> item <span style="color: #000080;">In</span> haystack
		<span style="color: #000080;">If</span> needle = item <span style="color: #000080;">Then</span> : InArray = <span style="color: #000080;">True</span> : <span style="color: #000080;">Exit</span> <span style="color: #000080;">Function</span> : <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">Next</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">Function</span> IsLogRunning(logName) <span style="color: #008000;">'As Boolean
</span>	IsLogRunning = <span style="color: #000080;">False</span>
	oReg.GetDWORDValue HKLM, dictCounterLogs(logName), &quot;Current State&quot;, dwCurrentState
	<span style="color: #000080;">If</span> dwCurrentState <span style="color: #000080;">Then</span>
		IsLogRunning = <span style="color: #000080;">True</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">Sub</span> SendEmail(server, sender, recipient, subject, textbody)
	<span style="color: #000080;">Set</span> objMessage = CreateObject(&quot;CDO.Message&quot;) 
	objMessage.Subject = subject 
	objMessage.From = sender 
	objMessage.<span style="color: #000080;">To</span> = recipient 
	objMessage.TextBody = textbody
&nbsp;
	objMessage.Configuration.Fields.Item _
		(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = 2 
	objMessage.Configuration.Fields.Item _
		(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) = server
	objMessage.Configuration.Fields.Item _
		(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = 25 
	objMessage.Configuration.Fields.Update
&nbsp;
	objMessage.Send 
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/11/monitoring-starting-and-stopping-perfmon-performance-counter-logs-using-vbscript/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

