pantheon-systems/php-apm

Name: php-apm

Owner: Pantheon

Description: PHP APM (Alternative PHP Monitor)

Created: 2016-04-27 00:34:12.0

Updated: 2018-04-28 09:43:45.0

Pushed: 2017-03-21 01:57:42.0

Homepage: http://pecl.php.net/package/APM

Size: 991

Language: C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

APM (Alternative PHP Monitor)

Build Status

APM (Alternative PHP Monitor) is a monitoring extension enabling native Application Performance Management (APM) for PHP. It doesn't require any modification to your application's code and let's you collect performance metrics as well as catching issues that may arise.

Installing
From PECL:
  1. $ sudo pecl install apm
From source:
  1. $ git clone https://github.com/patrickallaert/php-apm.git

  2. $ cd php-apm

  3. $ phpize

  4. Configure the extension, by default, sqlite3, MariaDB/MySQL, StatsD, HTTP, and Socket support are enabled:

    configure [--with-sqlite3[=DIR]] [--with-mysql[=DIR]] [--enable-statsd] [--enable-socket] [--enable-http] [--with-debugfile[=FILE]]
    

    To disable the support of a --with-* switch, use: --without-*, example: $ ./configure --without-sqlite3 To disable the support of a --enable-* switch, use: --disable-*, example: $ ./configure --disable-socket

  5. Compile it:

    ke [-j]
    

    Tip: use -j to activate parallel compilation.

  6. Install it:

    do make install
    
Upgrading
From 2.0 to 2.1
MariaDB / MySQL
LTER TABLE request ADD COLUMN method TEXT NOT NULL;
SQLite
LTER TABLE request ADD COLUMN method TEXT NOT NULL DEFAULT '';
Configuration
Common
  1. Activate the extension in the php configuration by adding:

    nsion=apm.so
    

    Note: APM depends on JSON, so the apm.so extension must be loaded after JSON!

MariaDB/MySQL driver

The MariaDB/MySQL driver lets you store errors and stats in a local, remote or shared database.

  1. Create a user/database for storing APM events.

  2. Set the following settings in the php configuration:

    mysql_enabled=1
    ror reporting level specific to the MariaDB/MySQL driver, same level as for PHP's *error_reporting*
    mysql_error_reporting=E_ALL|E_STRICT
    mysql_host=<host>
    .mysql_port=<port>
    mysql_user=<user>
    mysql_pass=<password>
    mysql_db=<dbname>
    
SQLite driver

The SQLite driver lets you store errors and stats in a local SQLite database.

Note that if performance matters, you should better use the MariaDB/MySQL driver.

  1. Create the directory for the SQLite database as it will be referenced in the setting: apm.sqlite_db_path (see next step):

    dir -p /var/php/apm/db/
    mod a+rwx /var/php/apm/db/
    
  2. Set the following settings in the php configuration:

    sqlite_enabled=1
    e directory containing the "events" file
    sqlite_db_path="/path/to/directory/configured/in/previous/step."
    ror reporting level specific to the SQLite3 driver, same level as for PHP's *error_reporting*
    sqlite_error_reporting=E_ALL|E_STRICT
    
StatsD driver

The StatsD driver is handy to send performance metrics of your web sites/applications directly to StatsD, without interfering with your code. The most common backend for StatsD is Graphite, see [Etsy's blog post on StatsD/Graphite], but other backends exist as well.

  1. Install StatsD.

  2. Configure it in the php configuration:

    ether to enable the statsd driver
    statsd_enabled=On
    st of the statsd server
    statsd_host=localhost
    rt of the statsd server
    statsd_port=3306
    
Socket driver

The socket driver lets you send errors and stats directly by Unix and/or TCP sockets. This is handy if you want to write you own piece of code to handle those.

  1. Configure it in the php configuration:

    ether to enable the socket driver
    socket_enabled=On
    cket path (accept multiple entries, separated by "|", prefixed with "file:" or "tcp:")
    ample: apm.socket_path=file:/var/tmp/apm.sock|tcp:localhost:1234
    socket_path=file:/tmp/apm.sock
    
Web frontend

The web frontend to visualize the data is now available at: https://github.com/patrickallaert/php-apm-web

Advanced configuration
plication identifier, helps identifying which application is being monitored
application_id="My application"
able the capture of events such as errors, notices, warnings,...
event_enabled=On|Off
ximum duration in ms a request can take before it gets recorded
stats_duration_threshold="100"
ximum User CPU time in ms a request can take before it gets recorded
stats_user_cpu_threshold="100"
ximum System CPU time in ms a request can take before it gets recorded
stats_sys_cpu_threshold="10"
olean controlling whether the stacktrace should be stored or not
store_stacktrace=On|Off
olean controlling whether the ip should be stored or not
store_ip=On|Off
olean controlling whether the cookies should be stored or not
store_cookies=On|Off
olean controlling whether the POST variables should be stored or not
store_post=On|Off
ximum recursion depth used when dumping a variable
TE: With today's application complexity, the amount of data collected in stacktraces
cluding arguments can lead to several thousands of MiB of memory consumed.
 recommend increasing this value with care.
dump_max_depth=1

r the configuration below, <driver_name> can be any of: sqlite, mysql, statsd or socket

tivate or deactivate a specific driver (note also that it must be compiled in to be activated).
<driver_name>_enabled=On|Off
ether to collect stats for this driver (ATTENTION: Has a small performance overhead when used with a DB drivers!)
<driver_name>_stats_enabled=On|Off
ror reporting level specific to this driver
<driver_name>_error_reporting=E_ALL|E_STRICT
ntrol which exceptions to collect (0: none exceptions collected, 1: collect uncaught exceptions (default), 2: collect ALL exceptions)
<driver_name>_exception_mode=1
ores silenced events (Errors, warnings, notices,... that are muted with the PHP '@' operator)
<driver_name>_process_silenced_events=On|Off

For a list of all PHP ini directives, take a look at the apm.ini file.

Common issues

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.