Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Relic Solution: API Ideas—404 Tracking


#1

I thought I’d share a simple example which I used on a personal project. I changed the entire internal way I was storing posts on the site and it resulted in a large volume of the external URLs for existing content changing.

As a result I wanted to be able to monitor requests for 404’s and redirect recurring requests to URLs that didn’t exist to the correct new url / a valid page relating to the request.

Check it out!


API ideas: 404 tracking
#2

The API for the PHP Agent lets you add lots of new data to your transactions and Insights.

I was wondering how other people in PHP land might have used the API’s and Insights dashboard building and what example use cases that others might find useful.

I thought I’d share a simple example which I used on a personal project. I changed the entire internal way I was storing posts on the site and it resulted in a large volume of the external URLs for existing content changing.

As a result I wanted to be able to monitor requests for 404’s and redirect recurring requests to URLs that didn’t exist to the correct new url / a valid page relating to the request.

Insight Data
As each request comes in for a PHP Transaction, I knew I already could track the volume of 404’s with NRQL with no additional work.

SELECT count(*) FROM Transaction WHERE httpResponseCode = '404'

https://www.evernote.com/l/AdM4c2wJ3ThJpJF6k85gd4zS3-tABouciZwB/image.png

In the Transaction table, we track the URI or Transaction Name. So it’s easy to tell which file is handling these 404’s, in my Wordpress install the themes 404.php handles all the 404 requests. I need to know where the URLs which are coming in that lead to a 404 request and take action on the most recurring 404s first to ensure that the end user experience on my site is a valid and correct url.

In my 404.php I added the lines

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
newrelic_add_custom_parameter("Actual URL", $actual_link);

This meant anytime 404.php was called, my insights would contain a new query-able column of ‘Actual URL’.

As such it made it easy to query for recurring URLs that meet 404.

SELECT count(*) FROM Transaction WHERE httpResponseCode = '404' FACET `Actual URL` SINCE 24 hour ago LIMIT 40

https://www.evernote.com/l/AdPZvHeK1-FOW6BxXGMti3rXHCgaHXiloSkB/image.png

This gives me a view of url locations that I need to action, starting with the most recurring requests.

SELECT count(*) FROM Transaction WHERE section = '404' SINCE 1 week ago COMPARE WITH 2 weeks ago

Now I have a dashboard where I track the volume of 404’s today and this week. Compare this week to last week to ensure I’m making progress / a dent in the problem.

Anyone else done anything interesting combining API and Insights to create dashboards that help you tackle problems or create further insight into specific tasks / problems? Has anyone considered the above use case as a basic example of some of the things you can achieve with New Relic agent API and Insights