<?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>ASP.NET MSSQL Webhosting Blog &#187; Web Server</title>
	<atom:link href="http://www.mywebhostingblog.net/tag/web-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mywebhostingblog.net</link>
	<description>ASP.NET, MSSQL and Windows dedicated server articles</description>
	<lastBuildDate>Thu, 16 Sep 2010 19:53:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Monitoring IIS Web Server with Logparser and the RRDtool</title>
		<link>http://www.mywebhostingblog.net/hosting-security/monitoring-iis-web-server-with-logparser-and-the-rrdtool/</link>
		<comments>http://www.mywebhostingblog.net/hosting-security/monitoring-iis-web-server-with-logparser-and-the-rrdtool/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:03:04 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Hosting Security]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Window Hosting]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Graph]]></category>
		<category><![CDATA[IIS Web Server]]></category>
		<category><![CDATA[logparser]]></category>
		<category><![CDATA[MRTG]]></category>
		<category><![CDATA[MRTGbundle]]></category>
		<category><![CDATA[RRDTool]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Web Server]]></category>

		<guid isPermaLink="false">http://www.mywebhostingblog.net/?p=67</guid>
		<description><![CDATA[Introduction We read allot of articles on how one can use MRTG as an Intrusion detection tool or to creating traffic graph for a particular network subnet or a single IP address on Linux platform with Apache web server. But we find very few that allow us to have graphs on Windows Dedicated server with [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>We read allot of articles on how one can use <strong>MRTG</strong> as an Intrusion detection <strong>tool </strong>or to creating<strong> traffic graph </strong>for a particular network subnet or a single IP address on<strong> Linux platform</strong> with <strong>Apache web server</strong>. But we find very few that allow us to have graphs on<strong> Windows</strong> <strong>Dedicated server </strong>with <strong>IIS Web Server</strong>.</p>
<p>Here are some steps that can be used to create graphs on <strong>Windows Dedicated server</strong> with <strong>IIS </strong>as the <strong>web servers</strong>. And there is no need to take all the efforts to configure <strong>MRTG </strong>as we can simply have graphs with the use of <strong>logparser </strong>and the <strong>RRDtool </strong>from Tobias Oetiker and you can use the <strong>RRDtool </strong>perfectly without the rest of <strong>MRTG</strong>.</p>
<p><span id="more-67"></span></p>
<p><strong>Logparser</strong></p>
<p><strong>Logparser </strong>is a great free tool from <strong>Microsoft</strong>. It is written by Gabriele Giuseppini a Software Design Engineer from the test department. The first version of <strong>logparser </strong>was an internal testing tool inside <strong>Microsoft</strong>. Version 2 was made publicly available at the website, version 2.1 was a part of the <strong>IIS resource tools kit </strong>and version 2.2 was made available in January 2005.</p>
<p><strong>Here is a brief introduction how logparser works:</strong></p>
<p>Logparser need three things, an input format, an output format and a sort of <strong>SQL query</strong>. The <strong>SQL query</strong> is a dialect of <strong>SQL</strong>.</p>
<p>There are few very interesting articles on Microsoft’s website, one written by the Author himself:<br />
<a title="Details on how to use LogParser" href="http://www.microsoft.com/technet/community/columns/profwin/pw0505.mspx"><strong>How to use Logparser</strong></a><br />
<a title="Another link on &quot;How to use Logparser&quot;" href="http://www.microsoft.com/technet/community/columns/scripts/sg0105.mspx"><strong>Another one from Scripting Guys:</strong></a></p>
<p>The article from the scripting guys shows you how to use the logparser directly in a script with a com object.</p>
<p>You can download Logparser from the link below:<br />
<a title="Download LogParser" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&amp;displaylang=en"><strong>DOWNLOAD LOAGPARSER</strong></a></p>
<p>The above download has portable help file in the application directory. This help file give you the parameters of all the properties of the <strong>logparser</strong>.<br />
There is also an unofficial website specially for logparser:<br />
www.logparser.com</p>
<p><strong>About RRDtool.</strong></p>
<p><strong>What is the RRDtool:</strong></p>
<p>The <strong>RRDtool </strong>or <strong>Round Robin Database tool</strong> is a tool that can store date in a <strong>database </strong>and create graphs with it. The really great thing about <strong>RDDTool </strong>is that the database does not growing. It will stay almost the same size as when it was created.</p>
<p>On the RRD website<br />
<a title="RRDTool Official Website" href="http://www.people.ee.ethz.ch/~oetiker/webtools/rrdtool/index.en.html"><strong>RRDTool Website</strong></a><br />
there are some really good <strong>tutorials</strong>, and it is recommended to read them before you use the <strong>RRDtool</strong>.<br />
From this website you can also download the <strong>RRDtool</strong>, the only problem is that you need to compile it but if you download it with the <strong>MRTGbundle </strong>from the link below, it has a completed version of the <strong>RRDtool </strong>in the packet. If you unpack the MRTGbundle, you can copy the RRDtool directory to your scripting directory or your application directory and start using it.<br />
<a title="Compiled version of RRDTool" href="http://www.openinnovations.com/mrtgbundle.html"><strong>DOWNLOAD RDDTool Compiled Version</strong></a></p>
<p><strong>Create Database.</strong></p>
<p>Before you can use the <strong>RRDtool </strong>you need to create the database.<br />
The link below has all the information on how and why to create a database along with the parameters.<br />
<a title="How and why to create a database" href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/tut/rrdtutorial.en.html"><strong>How to create a database</strong></a><br />
<strong><a title="This link defines its parameters." href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/doc/rrdcreate.en.html">Parameters</a></strong></p>
<p>You can also use a script to do that.</p>
<p><code><br />
‘#start script.<br />
Set WshShell = WScript.CreateObject("WScript.Shell")<br />
strCMD = ".binrrdtool.exe create Eservicing.rrd"<br />
strCMD = strCMD &amp; " --start N "<br />
strCMD = strCMD &amp; " -s 300"<br />
strCMD = strCMD &amp; " DS:Hits:GAUGE:600:0:2000000"<br />
strCMD = strCMD &amp; " DS:Error400:GAUGE:600:0:2000000"<br />
strCMD = strCMD &amp; " DS:Error500:GAUGE:600:0:2000000"<br />
strCMD = strCMD &amp; " RRA:AVERAGE:0.5:1:288"<br />
strCMD = strCMD &amp; " RRA:AVERAGE:0.5:2:2016"<br />
strCMD = strCMD &amp; " RRA:AVERAGE:0.5:4:2232"<br />
strCMD = strCMD &amp; " RRA:AVERAGE:0.5:12:8760"</code></p>
<p>WshShell.Run strCMD<br />
‘#end script.</p>
<p>Here is an explanation of every command in the script:</p>
<p><code>Set WshShell = WScript.CreateObject("WScript.Shell")</code><br />
This line create a shell object you need to run the RRDtool .<br />
In the next 10 lines I create the command line that I run in the last line.</p>
<p><code>strCMD = ".binrrdtool.exe create Eservicing.rrd"</code><br />
this starts the RRDtool with the create function and give the name of the database.</p>
<p><code>strCMD = strCMD &amp; " --start N "</code><br />
&#8211;start set the start time of the database and N is the current time. The RRDtool works with Unixtime, this are the seconds from 1 January 1970.</p>
<p><code>strCMD = strCMD &amp; " -s 300"</code><br />
-s is the seconds between a database update.</p>
<p><code>strCMD = strCMD &amp; " DS:Hits:GAUGE:600:0:2000000"<br />
strCMD = strCMD &amp; " DS:Error400:GAUGE:600:0:2000000"<br />
strCMD = strCMD &amp; " DS:Error500:GAUGE:600:0:2000000"</code><br />
with this three lines I create three data sources. DS stands for data source, Hits is the name of the data source GAUGE is one of the four type’s of data sources, 600 are the seconds between the records if there is no input after 600 the value is NULL, 0 is the minimum value of the record and 200000 is the maximum value.</p>
<p><code>strCMD = strCMD &amp; " RRA:AVERAGE:0.5:1:288"<br />
strCMD = strCMD &amp; " RRA:AVERAGE:0.5:2:2016"<br />
strCMD = strCMD &amp; " RRA:AVERAGE:0.5:4:2232"<br />
strCMD = strCMD &amp; " RRA:AVERAGE:0.5:12:8760"</code><br />
this four lines create four Round Robin Archives. RRA stands for Round Robin Archive, AVERAGE is one of the four consolidation functions, 0.5 is the consolidation interval, 1 is the number of data sources that are consolidate in one record in the Round Robin Archive. If every 600 seconds a DS is created and the value is 4 instead of 1 every 2400 seconds there will be a record add to the archive, the last value is the number of records the archive contains.<br />
The first line create a Round Robin Archive with a consolidation interval of 0.5. every data source gets a record in the archive and the archive is 288 records long.</p>
<p><code>WshShell.Run strCMD</code><br />
And with this line the command is executed.</p>
<p><strong>Update database.</strong></p>
<p>With the next script we use logparser to evaluate the logfile from a IIS server. We can run this script every 5 minutes. To write the results in RRD database.</p>
<p><code>‘#start script<br />
Const ForReading = 1, ForWriting = 2, ForAppending = 8<br />
'-------------------------------------------------------------------------<br />
LogDir = "serverd$logsyswwwsiteW3SVC1"<br />
Set WSHShell = CreateObject("Wscript.Shell")<br />
Set fso = CreateObject("Scripting.FileSystemObject")<br />
Set objLogParser = CreateObject("MSUtil.LogQuery")<br />
Set objDictIISlogslist = CreateObject("Scripting.Dictionary")</code></p>
<p>Dim strDate<br />
Dim count<br />
Error400 = 0<br />
Error500 = 0<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Main<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Sub Main<br />
Call MakeStrDate<br />
Call GetUniqueHits<br />
Call GetStatus<br />
Call UpdateRRD<br />
End Sub<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Sub MakeStrDate<br />
strMonth = Month(Now)<br />
If Len(strMonth) = 1 Then<br />
strMonth = &#8220;0&#8243; &amp; CStr(strMonth)<br />
End If<br />
strDay = Day(Now)<br />
If Len(strDay) = 1 Then<br />
strDay = &#8220;0&#8243; &amp; CStr(strDay)<br />
End If<br />
strYear =Right(Year(Now),2)<br />
strDate = strYear &amp; strMonth &amp; strDay<br />
End Sub<br />
&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Sub GetUniqueHits<br />
Set objInputFormat = CreateObject(&#8220;MSUtil.LogQuery.IISW3CInputFormat&#8221;)<br />
objInputFormat.recurse = -1<br />
objInputFormat.iCheckPoint = strDate &amp; &#8220;.lpc&#8221;<br />
strQuery = &#8220;SELECT count(*) as UniqueHits FROM &#8216;&#8221; &amp; _<br />
LogDir &amp; &#8220;ex&#8221; &amp; strDate &amp; &#8220;.log&#8217;&#8221;<br />
Set objRecordSet = objLogParser.Execute(strQuery, objInputFormat)<br />
Do While Not objRecordSet.AtEnd<br />
Set objRecord = objRecordSet.GetRecord<br />
count = objRecord.GetValue(&#8220;UniqueHits&#8221;)<br />
objRecordSet.MoveNext<br />
Loop<br />
End Sub<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Sub GetStatus<br />
Set objInputFormat = CreateObject(&#8220;MSUtil.LogQuery.IISW3CInputFormat&#8221;)<br />
objInputFormat.recurse = -1<br />
objInputFormat.iCheckPoint = strDate &amp; &#8220;Error.lpc&#8221;<br />
strQuery = &#8220;SELECT sc-status , COUNT(*) as Hits FROM &#8216;&#8221; &amp; LogDir &amp; &#8220;ex&#8221; &amp; strDate &amp; &#8220;.log&#8217; WHERE sc-status &gt; 399 GROUP BY sc-status ORDER BY Hits DESC&#8221;<br />
Set objRecordSet = objLogParser.Execute(strQuery, objInputFormat)<br />
Do While Not objRecordSet.AtEnd<br />
Set objRecord = objRecordSet.GetRecord<br />
If  objRecord.GetValue(&#8220;sc-status&#8221;) &gt; 399 And objRecord.GetValue(&#8220;sc-status&#8221;) &lt; 500  Then<br />
Error400 = Error400 + objRecord.GetValue(&#8220;Hits&#8221;)<br />
End If<br />
If  objRecord.GetValue(&#8220;sc-status&#8221;) &gt; 499 And objRecord.GetValue(&#8220;sc-status&#8221;) &lt; 600  Then<br />
Error500 = Error500 + objRecord.GetValue(&#8220;Hits&#8221;)<br />
End If<br />
objRecordSet.MoveNext<br />
Loop</p>
<p>End Sub<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Sub UpdateRRD<br />
strRun = &#8220;.binrrdtool update Eservicing.rrd N:&#8221; &amp; count &amp; &#8220;:&#8221; &amp; Error400 &amp; &#8220;:&#8221; &amp; Error500<br />
X = WshShell.Run(strRun,0,True)<br />
End Sub<br />
&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
‘#end script</p>
<p>We will not explain this script line by line as it is a pretty simple script.</p>
<p><strong>Creating a Graphic with the RRDtool.</strong></p>
<p>With the next script I create a graphic with the RRDtool.</p>
<p><code>Set WshShell = WScript.CreateObject("WScript.Shell")</code></p>
<p>strCMD = &#8220;.binrrdtool graph .graphintranetNLweek.gif&#8221;<br />
strCMD = strCMD &amp; &#8221; &#8211;start N-1w &#8211;end N&#8221;<br />
strCMD = strCMD &amp; &#8221; &#8211;vertical-label &#8221; &amp; Chr(34) &amp; &#8220;Hits &#8221; &amp; Chr(34)<br />
strCMD = strCMD &amp; &#8221; &#8211;title INTRANET&#8221;<br />
strCMD = strCMD &amp; &#8221; DEF:Xhits=.databaseintranetNL.rrd:Hits:AVERAGE&#8221;<br />
strCMD = strCMD &amp; &#8221; DEF:Xerror400=.databaseintranetNL.rrd:Error400:AVERAGE&#8221;<br />
strCMD = strCMD &amp; &#8221; DEF:Xerror500=.databaseintranetNL.rrd:Error500:AVERAGE&#8221;<br />
strCMD = strCMD &amp; &#8221; LINE2:Xhits#FF0000:&#8221; &amp; Chr(34) &amp; &#8220;Hits&#8221; &amp; Chr(34)<br />
strCMD = strCMD &amp; &#8221; LINE2:Xerror400#00FF00:&#8221; &amp; Chr(34) &amp; &#8220;400 Errors&#8221; &amp; Chr(34)<br />
strCMD = strCMD &amp; &#8221; LINE2:Xerror500#0000FF:&#8221; &amp; Chr(34) &amp; &#8220;500 Errors&#8221; &amp; Chr(34)</p>
<p>WshShell.Run strCMD</p>
<p>You will make a note of 2 important thing in this script:<br />
1.    The DEF line: this line defines the Data Sources you use.<br />
2.    The LINE2: This defines the line in the graphic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mywebhostingblog.net/hosting-security/monitoring-iis-web-server-with-logparser-and-the-rrdtool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

