Collecting Stats by Batch Processing Log Files

As described in the Working with Statistics section, the Enterprise Edition of CountryHawk automatically tracks and tabulates statistics on hits by country each time the component is used to process a lookup request.

This makes it very simple, fast, and convenient to parse through a web log file and produce statistics on the number of hits per country and region.

ActiveX/COM Example:

The following pseudo-code demonstrates the approach to automatically tallying the statistics for all hits in a log file:

'First let's create a single instance of the component we will use to

'get the country information for each IP address in the log file.

'We could recreate this object over and over in the loop, but this is more

'efficient.

ChObj = CreateObject("cyScape.countryObj")

for each ipAddress in log file

chObj.Initialize(ipAddress)

'At this point the hit count for the matching country/region

'for this IP address is automatically incremented

next

'At this point we have collected stats for all IP addresses in our log.

'Now let's display the results by country.

set statsObj = CreateObject("cyScape.CountryStats")

foreach country in statsObj

response.write country & ": " & statsObj.Total(country) & "<br>"

next

 

Native .NET Example (C#):

The following pseudo-code demonstrates the approach to automatically tallying the statistics for all hits in a log file using VB.NET:

 

<%@ Import Namespace="cyScape.CountryHawk" %>

for each ipAddress in log file

CountryObj chObj = CountryObj.GetCountry(ipAddress)

'At this point the hit count for the matching country/region

'for this IP address is automatically incremented

next

 

// At this point we have collected stats for all IP addresses in our log.

// Now let's display the results by country.

CountryStats ctyStats = new CountryStats();

foreach (CountryObj chObj in ctyStats)

{

 Response.Write(chObj.CountryCode + ": " + chObj.HitCount + "<br>");

}

 

Tip: See the ch_statsByCountry.asp and ch_statsByRegion.asp sample scripts for more information.

See Also:

Using the CountryStats Object

Using the RegionStats Object

Collecting Stats in Real-time

Persisting Statistics

CountryStats Object and Methods

RegionStats Object and Methods