Finding the most used web browsers

Users visiting our website use a variety of devices and web browsers. By analyzing the web access logs, we can understand which browsers are the most popular and, therefore, which browsers our site must support at the least. We can also use this same information to help identify the types of devices that people are using.

In this recipe, we will write a Splunk search to find the most used web browsers over a given period of time. We will then make use of both the eval and replace commands to clean up the data a bit.

Getting ready

To step through this recipe, you will need a running Splunk Enterprise server, with the sample data loaded from Chapter 1, Play Time – Getting Data In. You should be familiar with the Splunk search bar and the time range picker to the right of it.

How to do it…

Follow the given steps to search for the most used web browsers:

  1. Log in to your Splunk server.
  2. Select the Search & Reporting application.
  3. Ensure that the time range picker is set to Last 24 hours and type the following search into the Splunk search bar. Then, click on Search or hit Enter.
    index=main sourcetype=access_combined | eval browser=useragent | replace *Firefox* with Firefox, *Chrome* with Chrome, *MSIE* with "Internet Explorer", *Version*Safari* with Safari, *Opera* with Opera in browser | top limit=5 useother=t browser
  4. Splunk will return a tabulated list of the top five most used web browsers on our site, by count and percent.
    How to do it…
  5. Save this search by clicking on Save As and then on Report. Give the report the name cp02_most_used_webbrowsers and click on Save. On the next screen, click on Continue Editing to return to the search.

How it works…

Let's break down the search piece by piece:

Search fragment

Description

index=main sourcetype=access_combined

You should now be familiar with this search from the earlier recipes in this chapter.

| eval browser=useragent

Using the eval command, we evaluate a new field called browser and populate it with the contents of the useragent field.

| replace *Firefox* with Firefox, *Chrome* with Chrome, *MSIE* with "Internet Explorer", *Version*Safari* with Safari, *Opera* with Opera in browser

Using the replace command, we use wildcards (*) within the content of the browser field to replace the values with shortened browser names. Note that the values that contain spaces require quotes around them, for example, "Internet Explorer".

| top limit=5 useother=t browser

Using the top command, we tell Splunk to find the top five web browsers and classify everything else under the value of other.

In this recipe, we used both the eval and replace commands for illustrative purposes. This approach absolutely works, but a better approach can be to use Splunk's lookup functionality to look up the useragent value and return the browser name and version. Lookups are covered later in this book.

There's more…

Often, the same field values can be used in different ways to provide additional insight. In this case, the useragent field can be used to inform the types of devices that access our site.

Searching for the web browser data for the most used OS types

Let's modify the search to display the types of user operating systems that access our website:

index=main sourcetype=access_combined | eval os=useragent | replace *Windows* with Windows, *Macintosh* with Apple, *Linux* with Linux in os | top limit=3 useother=t os

When the search is run, you should see results similar to the following screenshot:

Searching for the web browser data for the most used OS types

The search is similar, but this time we decided to pull the OS-related information from the useragent field and used it to compare access between major OS types.

See also

Also refer to the following recipes for more information:

  • The Finding the most accessed web pages recipe
  • The Identifying the top-referring websites recipe
  • The Charting web page response codes recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.248.208