Charting web page response codes

Log data often contains seemingly cryptic codes that have all sorts of meanings. This is true of our web access logs, where there is a status code that represents a web page response. This code is very useful as it can tell us whether certain events were successful or not. For example, error codes found in purchase events are less than ideal, and if our website was at fault, then we might have lost a sale.

In this recipe, we will write a Splunk search to chart web page responses against the various web pages on the site.

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.

How to do it…

Follow the given steps to chart the web page response codes over time:

  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 | chart count(eval(like(status,"2%"))) AS Success, count(eval(like(status,"4%") OR like(status,"5%"))) AS Error by uri_path
  4. Splunk will return a tabulated list of web pages, detailing for each page how many events were successful and how many generated errors.
    How to do it…
  5. Click on the Visualization tab, and you will see this data represented in a column (by default) chart.
  6. Save this search by clicking on Save As and then on Report. Give the report the name cp02_webpage_response_codes and click on Save. On the next screen, click on Continue Editing to return to the search.

How it works…

In this recipe, we selected to search by the uri_path field. This field represents the various web pages on the site. 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.

| chart count(eval(like(status,"2%"))) AS Success, count(eval(like(status,"4%") OR like(status,"5%"))) AS Error by uri_path

Stripping away the complexity for a moment, this is very similar to performing stats count by uri_path. However, in this case, we are using the chart command and only counting success and error status codes.

As the status field is essentially just a code, we are evaluating whether the code represents success or error. We do this using an inline eval command with the like function. The like function allows us to specify the start of the status field value and then wildcard it with a % sign. Any status code beginning with 2 represents success events, and any status code beginning with either 4 or 5 represents an error.

There's more…

Hopefully, you can start to see the power of the SPL, as we start to ramp up the complexity a bit. We can now take this search a little further to provide a bit more insight.

Totaling success and error web page response codes

We can further amend the search to show only the addItem and checkout web pages events, which seems a little more relevant to sales intelligence. Additionally, using the addcoltotals command, we can add up the total success and error events:

index=main sourcetype=access_combined uri_path="/addItem" OR uri_path="/checkout" | chart count(eval(like(status,"2%"))) AS Success, count(eval(like(status,"4%") OR like(status,"5%"))) AS Error by uri_path | addcoltotals label=Total labelfield=uri_path

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

Totaling success and error web page response codes

We use labelfield=uri_path and label=Total to tell Splunk to place a value of Total in the uri_path field column.

See also

Also refer to the following recipes for more information:

  • The Identifying the top-referring websites recipe
  • The Displaying web page response time statistics recipe
  • The Listing the top-viewed products recipe
..................Content has been hidden....................

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