Phetric: Persistent Metrics for PHP applications

This is part two of three in a series on how we monitor application metrics on AddThis.com. See part 1.

Last month we open sourced two internally developed pieces of our metrics stack. Drew Stephens wrote about the first, MetricCatcher, which enables non-java applications to utilize Coda Hale’s Metrics Package. The second piece, which we use on AddThis.com to monitor internal application metrics, is Phetric.

AddThis.com attracts millions of page views each month across multiple servers on a complex site to which we are constantly adding new features and enhancements. In order to monitor our metrics during this process, we gather metrics with Phetric and MetricCatcher, sending them on to Ganglia and Graphite for recording and viewing.

Using Phetric

To initialize Phetric, first you must include Sender.php and call Phetric_Sender::init() which takes the following four arguments (the final two of which are optional):

  1. The host where we want to send our metrics
  2. The port where MetricCatcher is listening
  3. A string you want prepend to all metric names
  4. A boolean for if you want to send each metric as it comes in rather then waiting for the end. (off by default)

All metrics are sent (as JSON) using UDP, which is a non-blocking operation; sending metrics won’t ever hang your application. Phetric hooks into php’s shutdown event to send the metrics after your application code has finished. If you are debugging or running extremely long running application code, setting the auto flush boolean to true will mean you send all the metrics as they come in.

Phetric supports everything offered by Coda Hale’s metric Package except for health check. Take a look at the Phetric Readme to see how to implement each metric.

Verifying your metrics

There are two options for verifying the metrics that you are sending as you develop. The first is to point Phetric at an install of MetricCatcher and tail its logs. If you aren’t using MetricCatcher, you can trivially see the metrics that Phetric emits using Netcat. I have this function in my .bashrc to make testing easy:

catcher(){
    while true;
    do
         nc -w 1 -l -u 1420;
    done;
}

In Conclusion

Grab Phetric on Github, it’s available under the MIT License. If you want to extend it please submit a pull request. Have ideas or questions? Open an issue on Github.

If you haven’t already, check out Drew Stephens previous post on MetricCatcher, where our Phetric metrics end up. Also, check back here soon for the final part of this series.

If our pre-game analysis was any indication of fan-base, the majority of the nation is happy with last night’s outcome. We analyzed millions of data points to bring you some highlights of the social activity that took place while the New York Giants took on the New England Patriots in Super Bowl XLVI. Activity was at an all-time high and amazingly, mobile sharing was up 500% from last year. Check out some of the online behavior that the game, commercials and performances inspired.

Bridgestone, Pepsi and Budweiser saw huge spikes in interest in their brand during the game. Anhueser-Busch ran four different ads, but you can see the final “Here Weego” spot had the biggest impact.

Interest is based on an analytics of related shares, clicks and searches:

Click for larger version.

 

As for the performances, perhaps we shouldn’t be surprised that M.I.A.’s much talked about obscene gesture had the most sustained interest throughout the 4th quarter and even after the game. Cee Lo wins for generating overall most interest.

Entertainment Graph

Click for larger version.

 

Doritos, Budweiser and Teleflora were the big winners in terms of percentage lift in brand interest. Below you can see the lift in clicks, shares and searches for each brand relative to the day before Super Bowl.

Click for larger version.

 

Looks like Canada was more interested in Madonna than the US! This intensity map illustrates the scale of interest in Madonna due to her flashy halftime show.

Click for larger version.

 

And, finally, this map shows a geographic break down of interest in Budweiser brands in the US. Bud’s got some big fans in Colorado it seems. Maybe the folks in WV and KY need a little elbow in the ribs.

Click for larger version.

 

Some other great stats are around where all the activity was taking place:

  • Sharing via mobile was up 500% from last year
  • Overall sharing was up 143% from last year
  • Shares to and Clicks from Twitter was up 116% from last year
  • Shares to and Clicks from Tumblr was up 615% from last year
  • Shares to and Clicks from Facebook was up 18% from last year

Shares to and Clicks from Email were down 16% from last year

It seems Internet users are drifting away from email for much of their social correspondence and interacting more and more on social networks… and on mobile. Food for thought!

If you have any questions about our data or would like more information about AddThis and Clearspring, please feel free to contact us. We’d love to hear from you!

This is the second Big Game match-up for these two teams in recent years. The New York Giants beat the New England Patriots 17-14 in 2008 for Super Bowl XLII. But are citizens of the great United States hoping for an even score?

Not according to our data! We analyzed the search keywords, sharing behaviors and other social data points of millions of Internet users and found that the Giants are causing the most activity:

 

We’re also looking forward to analyzing our data for all the Super Bowl commercials. The big game is one of the most obvious illustrations of offline media affecting online behavior. Leading up to today, Honda saw a great spike in interest over the Ferris Bueller ad campaign this past week:

 

 

Can’t wait to see the other big winners.

Follow us on Twitter to get more Super Bowl data! We’ll follow up with some stats after the game.

We’ve added a slew of new places to share, including the Save to Foursquare button.

To get the Foursquare button, just add some code to your current AddThis implementation. The documents to do this can be found here. If you have any questions, please feel free to visit our help center.

Other new services that have been added to our menu and immediately available for your users are Azadegi, Bland takkinn, Blogkeen, BO.LT, CleanPrint, ClipDO, Jolly, Mendeley, PoliticNote, QRSrc, Research Gate, WebMoney.ru and to.ly.

 

Crunching Data…

One reason I love working at Clearspring is the awesome data processing power we have. Inspired by the 2012 election cycle, I wanted a better understanding of where in the United States Mitt Romney was generating the most interest.

The intensity map below shows that former Governor Romney is drawing lots of interest in his home states of Massachusetts and New Hampshire and in the next primary state, South Carolina. The state that is most interested in Romney is Utah, and not far behind is Georgia. Advertisements running for Romney in South Carolina are being seen by Georgia residents. Note that I normalized the data based on the percentage of population in each state with access to the Internet. We look forward to sharing more election data throughout the 2012 election cycle.

Romney_us_internet_pop

Advanced Metrics Tracking for Webapps

MetricCatcher is a bookkeeping agent for application metrics. It utilizes Coda Hale’s Metrics package to provide languages that aren’t Java (or aren’t long-running) with the easy-to-use tracking & advanced maths of Metrics.

If you have a Java app and are tracking its performance, the best way to do that is using Coda Hale’s Metrics package, which provides convenient objects for counting happenings in your application. In other languages you don’t have the option of using this great library, and in web apps that start up a new process for each request, simply keeping the persistent data to enable metrics like this is a hassle. That’s where MetricCatcher comes in—toss values at MetricCatcher and it will create corresponding Metric objects, allowing your non-Java app to take advantage of Coda Hale’s fancy maths. Metrics in a Java application can be viewed with Jconsole (or even better, VisualVM), but to really realize the power of tracking your application, MetricCatcher can pump its data into Graphite or Ganglia.

We use MetricCatcher to keep tabs on our PHP code using the Phetric library.  The combination of Phetric & MetricCatcher allows the easy creation & updating of metrics without requiring any state to be kept on the PHP side of things.

Running MetricCatcher

Grab MetricCatcher from the Clearspring GitHub repository for MetricCatcher

The only configuration that MetricCatcher requires is the location of your Ganglia or Graphite server, which can be defined in the conf/config.properties of the distribution. MetricCatcher will send metrics to whichever metrics servers are defined. Starting & stopping MetricCatcher can be done using the included scripts in the bin directory.

Getting Data In

MetricCatcher listens for JSON on UDP port 1420 for metrics to track—simply feed it lists of Metrics objects, each of which must have a name, type, timestamp, and value. MetricCatcher supports all of the types that Coda Hale’s Metrics provides, except for Health Checks. Note that histograms are either biased (favor more recent data) or uniform (weight all data equally) and are referred to as such. The JSON format looks like this:

{
    "name":"namespace.metric.name",
    "value":numeric_value,
    "type":"[gauge|counter|meter|biased|uniform|timer]",
    "timestamp":unix_time.millis
}

Metrics are sent as a JSON list, so multiple individual metrics can be bundled:

[
    {"name":"foo","value":7,"type":"gauge","timestamp":1320682297.6631},
    {"name":"bar","value":77,"type":"meter","timestamp":1320682297.6631}
]

Where Data Goes

You can view the metrics using a JMX agent (jConsole or VisualVM as mentioned above), but the best way toview them is to define a metrics—collecting server in the config.properties file. If you do that, MetricCatcher will send its stats there once a minute, so you can check out your Graphite or Ganglia server to see the results.

Which pages are trending, right now? Which searches are bringing traffic to your site, and what words are visitors copying in order to search or email friends? What interests your visitors, and what are they saying about your website or blog? Find out the answers to these questions using your newly expanded AddThis Analytics Live View.

What’s Live View?

The AddThis Analytics Live View provides a look at what’s happening right now, across your site or for a specific page, including:

  • A map showing where people are interacting with your pages
  • A list of your top content, right now, based on shares and traffic back to your site
  • Your viewers’ interests, and what they’re saying about your content on Twitter

The Live View also introduces new types of information to help you understand how your audience is interacting with your site:

  • Searches: How many searches are bringing traffic to your site? What are your visitors looking for? Live View displays a list of top search keywords and phrases.
  • Text copy tracking: While searches indicate what brought users to your site, text that visitors copy can help you understand what they found interesting, and whether these keywords align with your search meta-data to help maximize SEO. Learn more

Zoom Into a Page

Interested in a particular page that’s trending? Zoom in for a closer look by clicking on it’s title, and discover how your visitors are interacting with that page, what searches brought them there, and what your audience is saying about that page on Twitter.

What do you think?

We’d love to hear what you think about the new AddThis Analytics Live View. Drop us a line in our forum with your feedback, and if you have any questions or need technical support, please visit our new Support Center.

AddThis now supports the Google+ badge for your branded Google+ pages. By displaying this button on your website, you will make it easier for your supporters to follow you on Google+.

The Google+ badge comes in small, medium and large sizes so you can easily customize it for your site’s design.

A couple tips for implementing the button:

1. You must include the URL of your Google+ page so the minimum value code would look like:

Example:

<a g:plusone:href="https://plus.google.com/102383601500147943541/"></a>

2. Similar to our Google +1 button, Google+ Follow badges come in multiple sizes; there is the option for a “Large version” that includes on page following. This button comes in a regular size and smaller size declared by either “badge” or “smallbadge”, respectively. There is also the buttons that solely link out to the brand page and those are “small”, “medium” and “large”.

Example:

<a g:plusone:href="https://plus.google.com/102383601500147943541/"
g:plusone:size="smallbadge"></a>

If you combine Google+ Follow with Facebook Subscribe and Twitter Follow buttons, you’ll have all your brand pages covered.

As always, please let us know if you have any questions or feedback!

Happy Holidays!

Our team wanted to take a moment and wish everyone happy holidays. Historically, we’ve created special logos. This year we wanted to give a quick shout out to Josh Cleland for providing an illustration for us to use.

Ps. Can you find the easter egg on our homepage. If you like it, give Foo a high five. :)

You may notice that the sharing menus on our blog and other pages on AddThis.com look a little different today. We’ve rolled out some new tools that are simple and streamlined.

These updated tools are designed to boost sharing by showing more of the viewer’s personalized services as a simple, friendly list. We’ve also redesigned and expanded the AddThis email form to be even easier to use.

If you want to try out these buttons for your own site they are available here.

Please let us know if you have any questions or feedback – we’d love to hear from you.

 


« Older Entries