metrics-tracker / watchlog
A PHP package for sending metrics.
Requires
- guzzlehttp/guzzle: ^7.0
This package is not auto-updated.
Last update: 2025-04-21 13:10:23 UTC
README
Introduction
The Watchlog
class is a simple PHP class for sending various types of metrics to a server. It uses the Guzzle HTTP client for making asynchronous HTTP requests.
Setup
-
Install Watchlog: Ensure you have the Watchlog package installed via Composer. Run the following command in your project directory:
composer require metrics-tracker/watchlog
-
Include the
Watchlog
Class: Ensure your PHP script includes theWatchlog
class. Use an autoloader or include the class file directly.
Usage
Here are the methods available in the Watchlog
class and how to use them:
-
Increment a Metric:
use MetricsTracker\Watchlog; $watchlog = new Watchlog(); $watchlog->increment('page_views'); // Optionally increment by a different value $watchlog->increment('page_views', 5);
-
Decrement a Metric:
$watchlog->decrement('active_users'); // Optionally decrement by a different value $watchlog->decrement('active_users', 2);
-
Set a Gauge Value:
$watchlog->gauge('memory_usage', 512);
-
Set a Percentage Value:
$watchlog->percentage('cpu_usage', 75);
-
Set a System Byte Value:
$watchlog->systembyte('disk_space', 1024000);
Notes
- Ensure the server agent is set up to handle the incoming metric requests.
- Each method (
increment
,decrement
,gauge
,percentage
,systembyte
) sends a metric to the server with the specified method, metric name, and value. - The
sendMetric
method is a private method used internally to handle the HTTP request logic.
This documentation should help you understand how to set up and use the Watchlog
class for tracking metrics in your PHP application.