We create awesome websites.

Codeigniter and Metricfire - a Codeigniter Library for Awesome Metrics

Listed under: Awesome Stuff > Check It Out on Tue 13th March 2012



A while back, I blogged about Metricfire, a really amazing application metrics service for your PHP (or Python) applications. If you haven't checked it out yet, it's time you do. Right now.

Using the Metricfire raw PHP file as a template (Dave @ Metricfire said it was OK!), I've hacked about with it to form it into a Codeigniter library. This means that all you Codeigniter developers out there can sign up for Metricfire, plug in the Library, and obtain up-to-the-second metrics on your web application. Suh-weet!

 

Here is the file - download it, unpack it and take a look.

 


How To Use This Library:

1. Go to the Metricfire site and go to the "Get Early Access" button (it's in Beta as at March 2012, the time of writing)

2. Get your API Key, and save it somewhere on your PC.

3. Copy the downloaded Metricfire_library.php to your CodeIgniter ./application/libraries/ folder

4. Load the library by placing the following into your controller (text in [brackets] are where your settings are input - brackets included so remove them too):


        
        $mykey = array("key" => "[my_metricfire_key]");
        $options = array("application" => "my_application"); // This (my_application) can be named anything, single word alphanumeric string only.
               
        $params = array($mykey, $options);
        $this->load->library('Metricfire_library', $params);

 

 

5. From your controller, model, or view, use the following to send a metric:
       
        $val = 1;
        // ..or
        // $val = rand(1, 100);

        $this->metricfire_library->send("testdata.special", $val);

   


6. Log in to your Metricfire dashboard, and configure a graph to read the testdata.special metric from your my_application application.
   
7. Watch your stats graph before your very eyes!

 

Notes:

- When sending a metric, the first letter of metricfire_library needs to be lower case, in contrast to loading the library, where the first letter is capitalized.

- testdata.special is a metric name, and can be changed to whatever you like.

- Metric names should be alphanumeric but self-descriptive.

- To group metrics into categories, use periods as separators, like cache.hits and cache.misses

 

 

 

 

Try it out yourself - it is really very cool.


What do you think of the Metricfire Codeigniter library? Drop me a line below if you have any feedback about the library file, or Metricfire in general....!






Comments are closed for this blog entry.