WHERE DO I START?
You are here:Integrations > PHP

PHP

Summary

You can monitor your PHP applications using our PHP client library, the Linux Agent, and the Netuitive StatsD server. To get up and running, all you'll need is to install our Linux Agent and then instrument custom metrics.

Important   For the configuration section and examples, we used our own PHP client library, but you can use any compatible PHP client library. The Netuitive PHP Client library currently only has support for gauges, counters, and timers; please feel free to extend our library or use another library you've found online. Note that while some libraries may support varying metric types, the Netuitive StatsD server only supports gauge, set, counter, timer, and histogram types. See the Netuitive StatsD server doc for more info.

Configuration

Note   Before you configure metric instrumentation in your PHP application(s), you'll need to install the Linux Agent and Netuitive StatsD server first. See the instructions on this page for how to install it.
  1. Set the statsd setting in the netuitive-agent.conf file to enabled = True.
    # local statsd server
    [[[statsd]]]
    enabled = True
  2. StatsD requires a client library to push metrics, so you'll need to install a PHP client library. We have a PHP client library that can be found in our GitHub repository. The open source community also has many PHP client libraries for StatsD that should all work with our agent.
  3. Include the client library file on any page you want to collect metrics, or you can reference the file globally.
    include 'StatsD_Client.php';
  4. Instrument your application code by calling the appropriate functions. Check out the example below or the timer example included in the library repo.
    Example(s)   What follows are examples of how to create metrics using the types compatible with our Netuitive PHP Client library:
    //add a gauge in any section of your code
    .gauge('test.data.gauge', 20);
    
    //to add this time you must first add code to calculate the start and end time.
    //typically we use epoch time.  And add code at the start and end of the code you want to measure.
    //the timing function expects time in milliseconds
    .timing('test.data.timer', 1000, 1);
    
    
    //you can add or subtract from any metric with these functions
    .increment('test.data.counterup', 1);
    .decrement('test.data.counterdown', 1);

    These metrics will show up under the statsd node in the Metrics page like so:

  5. Save your application, and restart both your application and the Linux Agent.

Dependencies

OS

Redhat 6 and 7
CentOS 6 and 7
Amazon Linux (latest)
Ubuntu 12, 14, 15, and 16
Debian 7, 8, and 9

Miscellaneous

Linux Agent
Netuitive StatsD Server
PHP Client Library