pxlwidgets/legacy-filebeat-emulator

此包的最新版本(0.9.2)没有可用的许可证信息。

PHP基于的filebeat-like日志处理仿真器

0.9.2 2019-08-07 10:10 UTC

This package is auto-updated.

Last update: 2024-09-13 00:52:24 UTC


README

这是一个将日志文件内容发送到配置了http输入插件的Logstash实例的粗略解决方案。

想法是在cron任务中运行此包提供的进程(例如,每五分钟一次)。然后,此进程将从保存的最新消息指针读取日志文件,并单独发送所有行以及一些可配置的附加上下文数据。

所有日志数据都应该是有效的JSON,这样才能正常工作。

变更日志

查看变更日志.

警告

这是一个非常粗略的方法,仅在以下情况下应予以考虑:

  • 使用的是古老软件;
  • 服务器没有root权限(因此无法安装filebeat);

使用和配置

建议通过一个确保不会重叠的cronjob来运行日志处理。在那个过程中,你可以轻松创建并使用像这样的处理器

<?php
use PXLWidgets\FilebeatEmulator\Config\Config;
use PXLWidgets\FilebeatEmulator\Config\SourceConfig;
use PXLWidgets\FilebeatEmulator\Config\ProcessConfig;
use PXLWidgets\FilebeatEmulator\Config\TargetConfig;
use PXLWidgets\FilebeatEmulator\Process\LogProcessorFactory;

// Provide log paths using glob wildcard patterns to define which logs should be processed.
$logPaths   = ['/home/some/path/log-*.txt', '/other/path/*.log'];
// Determine where the processing status file should be stored.
// This file marks up to where the log was previously processed successfully.
$statusPath = '/home/tmp/status.txt'; 

// The ElasticSearch index that should be used (added under root 'index' key).
$index = 'your-project-acceptance';

// The name for the environment in which your application runs.
$environment = 'acceptance';

// A friendly name for your application (added under root 'application' key).
$application = 'My testing application';

// Any extra data that will be added to all log records sent. This will not overwrite values for keys that are set explicitly.
$extra = [
    'your-key' => 'your value',
];

// The URI where you want to send the log entries to.
$host = 'localhost:5000';

// The (Basic Auth) user and password that you want to use.
$user     = null;
$password = null;

// Headers to send along with the curl call. For example, if you're going to send JSON data, set the correct Content-Type:
$headers = [
    'Content-Type' => 'application/json',
];


$config = new Config(
    new SourceConfig($logPaths, $statusPath),
    new TargetConfig($host, $user, $password, $headers),
    new ProcessConfig($index, $environment, $application, $extra) 
);

$processor = (new LogProcessorFactory())->make($config);


$processor->process();

这是最简单的设置,无需任何框架。鼓励使用环境变量和框架DI解决方案,如果有的话。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。