disc/php-zabbix-sender
Modern PHP implementation of a Zabbix Sender client. Send metrics to Zabbix server quickly by adding host/key/value data and calling send(). Supports PHP 5.4+ and works with Zabbix 2.0.8, 2.1.7+ and 4.0.
zabbix_sender CLI tool, ideal for:
exec() calls to zabbix_sender with a managed PHP dependency.sendZabbixMetricJob) for async processing, reducing latency in critical paths.OrderProcessed, PaymentFailed).send() in a retry decorator (e.g., using spatie/laravel-retryable).queue:failed table to handle failed jobs.send() calls may block execution. Mitigate by:
addData() to prevent metric injection.$this->app->singleton(\Disc\Zabbix\Sender::class, function ($app) {
return new \Disc\Zabbix\Sender(config('zabbix.host'), config('zabbix.port'));
});
config/zabbix.php:
return [
'host' => env('ZABBIX_HOST', 'monitoring.example.com'),
'port' => env('ZABBIX_PORT', 10051),
'timeout' => env('ZABBIX_TIMEOUT', 5),
'hostname' => env('ZABBIX_HOSTNAME', 'laravel-app'),
];
.env for dynamic configuration:
ZABBIX_HOST=monitoring.internal
ZABBIX_PORT=10051
UserRegistered):
public function handle(UserRegistered $event) {
$sender->addData(config('zabbix.hostname'), 'users.registered', 1);
$sender->send();
}
public function handle($request, Closure $next) {
$start = microtime(true);
$response = $next($request);
$duration = microtime(true) - $start;
app(\Disc\Zabbix\Sender::class)
->addData(config('zabbix.hostname'), 'http.response.time', $duration)
->send();
return $response;
}
class SendZabbixMetricJob implements ShouldQueue {
public function handle() {
$sender = app(\Disc\Zabbix\Sender::class);
$sender->addData('app', 'queue.processing.time', $this->duration);
$sender->send();
}
}
exec('zabbix_sender ...') call with the PHP package.composer.json and test in a staging environment.exec() calls via feature flags or config switches.zabbix_sender CLI usage (e.g., via process logging).config/zabbix.php.ZabbixService facade/class to abstract sends.config/ to avoid hardcoding.ZABBIX_HOSTNAME).app.{key}).timeout config or investigate network latency.send() in a try-catch to log failures:
try {
$sender->send();
} catch (\Exception $e) {
\Log::error("Zabbix send failed: " . $e->getMessage());
}
tcpdump or Wireshark to inspect UDP traffic to port 10051.How can I help you explore Laravel packages today?