thecodingcompany/php-fluentd-mariadb

用于与 Fluentd exec_filter 插件配合使用的 PHP 库

v1.0.0 2017-11-27 16:31 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:36:46 UTC


README

使用此插件将 FluentD (TCP) 的 exec_filter 插件发送的数据发送到 MariaDB。

#TD-agent 配置示例 td-agent 配置示例

## built-in TCP input
## @see http://docs.fluentd.org/articles/in_forward
## @see https://docs.fluentd.org/v0.12/articles/out_exec_filter
<source>
  @type forward
  @label @PHP_FILE
  port 2017
  bind 127.0.0.1
  @log_level debug
</source>
<label @PHP_FILE>
    <match php_out>
        #@type stdout
        @type exec_filter
        command /bin/php /usr/local/example.php 2>&1
        in_format json
        out_format json
        flush_interval 1s
        tag php_out
        @log_level debug
    </match>
</label>

#PHP 代码(示例)

<?php
require_once("theCodingCompany/MariaDBStore.php");

$settings = array(
    "cdn"       => "mysql:host=127.0.0.1;port=3306;dbname=event_log;",
    "username"  => "root",
    "password"  => "MySecretPassword"
);

/*
* Example data: {"attributes":{"voornaam":"Victor","achternaam":"Angelier"}} that is forwarded from FluentD to STDIN
*/
$fields = array("attributes");

$maria = new theCodingCompany\MariaDBStore($settings);
$maria->setTable("event_log")
    ->setFields($fields)
    ->start();

最终数据存储在 MariaDB 的 event_log 表中,数据库为 event_log,值为:{"voornaam":"Victor","achternaam":"Angelier"}