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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
$ sudo pecl install apm
$ git clone https://github.com/patrickallaert/php-apm.git
$ cd php-apm
$ phpize
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
Compile it:
ke [-j]
Tip: use -j
to activate parallel compilation.
Install it:
do make install
LTER TABLE request ADD COLUMN method TEXT NOT NULL;
LTER TABLE request ADD COLUMN method TEXT NOT NULL DEFAULT '';
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!
The MariaDB/MySQL driver lets you store errors and stats in a local, remote or shared database.
Create a user/database for storing APM events.
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>
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.
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/
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
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.
Install StatsD.
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
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.
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
The web frontend to visualize the data is now available at: https://github.com/patrickallaert/php-apm-web
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.
SQLite database isn't created: this usually happens when your webserver or PHP process (fcgi, fpm) has no filesystem access:
Not all data on the specific PHP scripts in which errors occur is collected:
APM is configured correctly, but nothing shows up, and phpinfo() doesn't show anyting related to APM: