jmonitor/collector

Simple php web server monitoring library

v1.1.0-alpha 2025-08-22 15:38 UTC

This package is auto-updated.

Last update: 2025-08-22 15:42:23 UTC


README

Easy monitoring for PHP web server.
Jmonitor.io is a simple monitoring sass for PHP applications and web servers that provides insights and alerting from various sources like MySQL, Redis, Apache, Nginx...

This package provide the collectors which send metrics to Jmonitor.io.

Requirements

  • PHP 7.4
  • Having a project with a Composer dependency manager

Installation

composer require jmonitor/collector

Getting Started

Create a project in jmonitor.io and get your API key.

Then, in your project, create a Jmonitor instance and add some collectors.

use Jmonitor\Jmonitor;
use Jmonitor\Collector\Apache\ApacheCollector;

$jmonitor = new Jmonitor('apiKey');

// Add some collectors 
$jmonitor->addCollector(new ApacheCollector('https://example.com/server-status'));
$jmonitor->addCollector(new SystemCollector());
// see the documentation below for more collectors

// send metrics periodically to jmonitor (ex. every 15 seconds)
$jmonitor->collect();

You can customize your HttpClient, for example, if you want to use the Symfony HttpClient or Guzzle.

composer require symfony/http-client nyholm/psr7
use Symfony\Component\HttpClient\Psr18Client;

$httpClient = ... // create or retrieve your Symfony HttpClient instance
$client = new Psr18Client()->withOptions(...);

$jmonitor = new Jmonitor('apiKey', $client);

Setup a cron

If you use this package as standalone (without symfony bundle), you'll need to setup a cron to periodically send metrics to Jmonitor.io.
/!\ You cannot use the $jmonitor->collect(); in every request on a page of your website, this is not the way.
Minimum time between collection is 15 seconds (This may change in the future in accordance to the evolution of Jmonitor).

Collectors

  • System

  • Apache

  • Nginx (todo)

  • Mysql

  • Php

  • Redis

  • FrankenPHP

  • Caddy (todo)

  • System

    Collects system metrics like CPU usage, memory usage, disk usage, etc.
    Only Linux is supported for now, feel free to open an issue if you need support for another OS.

    use Jmonitor\Collector\System\SystemCollector;
      
    $collector = new SystemCollector();
  • Apache

    Collects Apache server metrics from a server status URL.
    You'll need to enable the mod_status module in Apache and set up a server status URL. There are some resources to help you with that:

    Then you'll be able to use the ApacheCollector class to collect metrics from the server status URL.

    use Jmonitor\Collector\Apache\ApacheCollector;
    
    $collector = new ApacheCollector('http://localhost/server-status');
  • Mysql

    Collects MySQL server variables and status.
    You'll need to use PDO or Doctrine to connect to your MySQL database. If you need support for other drivers, like Mysqli, please open an issue.

    use Jmonitor\Collector\Mysql\MysqlCollector;
    use Jmonitor\Collector\Mysql\Adapter\PdoAdapter;
    use Jmonitor\Collector\Mysql\Adapter\DoctrineAdapter;
    use Jmonitor\Collector\Mysql\MysqlStatusCollector;
    use Jmonitor\Collector\Mysql\MysqlVariablesCollector;
    use Jmonitor\Collector\Mysql\MysqlQueriesCountCollector;
    
    // with PDO
    $adapter = new PdoAdapter($pdo); // retrieve your \PDO connection
    
    // or Doctrine DBAL
    $adapter = new DoctrineAdapter($connection) /* retrieve your Doctrine\DBAL\Connection connection*/ );
    
    // Mysql has multiple collectors, use the same adapter for all of them
    $collector = new MysqlStatusCollector($adapter);
    $collector = new MysqlVariablesCollector($adapter);
    $collector = new MysqlQueriesCountCollector($adapter, 'your_db_name');
  • Php

    Collects PHP metrics like loaded extensions, some ini settings, fpm, opcache status, etc.

    use Jmonitor\Collector\Php\PhpCollector
    
    $collector = new PhpCollector();
  • Redis

    Collects Redis metrics from info command.

    use Jmonitor\Collector\Redis\RedisCollector;
    
    // You can use any Redis client that supports the info command, like Predis or PhpRedis.
    $redisClient = new \Redis([...]);
    $redisClient = new Predis\Client();
    // also support \RedisArray, \RedisCluster, Relay... feel free to open an issue if you need support for another client.
    
    $collector = new RedisCollector($redis);
  • Frankenphp

    Collects metrics from FrankenPHP metrics endpoint (which is a Caddy endpoint actually).

    use Jmonitor\Collector\Frankenphp\FrankenphpCollector
    
    $collector = new FrankenphpCollector('http://localhost:2019/metrics');
  • Caddy

    Collects metrics from Caddy metrics endpoint.

    use Jmonitor\Collector\Caddy\CaddyCollector
    
    $collector = new CaddyCollector('http://localhost:2019/metrics');

Integrations

Roadmap

  • Nginx, Caddy, finish FrankenPHP
  • Memcached