openclerk/metrics

There is no license information available for the latest version (0.1.0) of this package.

0.1.0 2017-09-11 07:39 UTC

This package is auto-updated.

Last update: 2024-10-14 09:16:27 UTC


README

A library for simple metrics (page, database) capture in PHP.

Installing

Include openclerk/metrics as a requirement in your project composer.json, and run composer update to install it into your project:

{
  "require": {
    "openclerk/metrics": "dev-master"
  }
}

Make sure that you run all of the migrations that can be discovered through component-discovery; see the documentation on openclerk/db for more information.

$migrations = new AllMigrations(db());
if ($migrations->hasPending(db())) {
  $migrations->install(db(), $logger);
}

Features

  1. Capture runtime metrics of pages and databases (through openclerk/db)
  2. Capture runtime metrics of templates (through openclerk/pages)
  3. Optionally store runtime metrics into the database (requires migrations through component-discovery)
  4. Optionally generate performance reports (requires openclerk/jobs)

Using

This project uses openclerk/db for database management, openclerk/events for capturing and processing events, and openclerk/config for config management.

Configure the component if necessary:

Openclerk\Config::merge(array(
  // these are default values
  "metrics_enabled" => true,
  "metrics_db_enabled" => true,
  "metrics_page_enabled" => true,
  "metrics_templates_enabled" => true,

  // store reports into the database
  "metrics_store" => false,
));

You now need to register the metrics events handlers, and trigger the page events as necessary:

// set up metrics
Openclerk\MetricsHandler::init(db());

// trigger page load metrics
Openclerk\Events::trigger('page_init', null);

// when rendering a page...
Openclerk\Events::trigger('page_start', null);
// do things
Openclerk\Events::trigger('page_end', null);

// print out metrics stats
print_r(Openclerk\MetricsHandler::getInstance()->printResults());

TODO

  1. Tests
  2. CURL report jobs
  3. How to extend your metrics capture (e.g. graphs metrics)