Custom Events
After installing and configuring the Watchlog Agent, you can emit custom metrics/events directly from your application using our language-specific client libraries.
Node.js
Installation
npm install watchlog-metric
Usage
const watchlog = require("watchlog-metric");
// Increment a metric by a value (default is 1)
watchlog.increment("Your_metric");
watchlog.increment("Your_metric", 75);
// Decrement a metric by a value (default is 1)
watchlog.decrement("Your_metric");
watchlog.decrement("Your_metric", 25);
// Record a percentage (value between 0 and 100)
watchlog.percentage("Your_metric", 12.23);
// Record a gauge (numeric value)
watchlog.gauge("Your_metric", 12.23);
// Record system bytes (e.g., for memory or bandwidth)
watchlog.systembyte("Your_metric", 1024000000); // 1 GB
Python
Installation
pip install watchlog-python
Usage
from watchlog import Watchlog
watchlog_instance = Watchlog()
# Increment a metric (default +1)
watchlog_instance.increment('page_views', 10)
# Decrement a metric (default -1)
watchlog_instance.decrement('items_in_cart', 2)
# Record a gauge value
watchlog_instance.gauge('current_temperature', 22.5)
# Record a percentage (0 to 100)
watchlog_instance.percentage('completion_rate', 85)
# Record system bytes
watchlog_instance.systembyte('memory_usage', 1024)
PHP
Installation
composer require metrics-tracker/watchlog
Usage
use MetricsTracker\Watchlog;
$watchlog = new Watchlog();
// Increment (default +1)
$watchlog->increment('page_views');
$watchlog->increment('page_views', 5);
// Decrement (default -1)
$watchlog->decrement('active_users');
$watchlog->decrement('active_users', 2);
// Record a gauge value
$watchlog->gauge('memory_usage', 512);
// Record a percentage (0 to 100)
$watchlog->percentage('cpu_usage', 75);
// Record system bytes
$watchlog->systembyte('disk_space', 1024000);
C#
Installation
dotnet add package Watchlog.Metric
Usage
using Watchlog.Metric;
// Initialize the client
var watchlog = new WatchlogClient();
// Increment (default +1)
watchlog.Increment("your_metric");
watchlog.Increment("your_metric", 75);
// Decrement (default -1)
watchlog.Decrement("your_metric");
watchlog.Decrement("your_metric", 25);
// Record a percentage (0 to 100)
watchlog.Percentage("your_metric", 12.23);
// Record a gauge value
watchlog.Gauge("your_metric", 12.23);
// Record system bytes
watchlog.SystemByte("your_metric", 1024000000); // 1 GB