weble/laravel-databox

Laravel的数据框API集成

dev-main 2023-07-03 15:23 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel的数据框集成,支持发送指标和检索可用指标列表。

数据在Laravel应用程序发送响应后通过单个推送请求发送,以避免影响用户。也可以通过配置文件中的简单选项将数据推送操作移动到队列中。

示例用法

use \LaravelDataBox\Facades\DataBox;

// gets the default source
$source = DataBox::source();

// Push a new metric
$source->push(new Metric(
    key: 'sales', 
    value: 888.22, 
));

安装

您可以通过Composer安装此包

composer require weble/laravel-databox

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="laravel-databox-config"

这是已发布配置文件的内容,每个选项都有注释

<?php

return [

    // name of the default source, used when not passing a specific source name
    'default_source' => 'default',

    // should the data be pushed with a queued job?
    // default setting, can be overridden per source
    'queue' => false,

    // List of sources, you can create as many as you want, each with its
    // own token and queue setting
    'sources' => [

        'default' => [

            // The token generated in the databox UI
            'token' => env('DATABOX_TOKEN', ''),

            // Each source can override the queue setting.
            // null means use the default setting above
            'queue' => null,
        ],
        
        // More sources....
    ],
];

使用方法

您可以通过facade LaravelDataBox\Facades\DataBox与DataBox API进行交互

推送单个指标

use \LaravelDataBox\Facades\DataBox;

// gets the default source
$source = DataBox::source();

// Push a new metric
$source->push(new Metric(
    key: 'sales', // Adds automatically the $ sign if not present
    value: 888.22, // any float / int value
));

推送多个指标

use \LaravelDataBox\Facades\DataBox;

$source = DataBox::source();
$source->push([
    new Metric(
        key: 'sales',
        value: 888.22, 
    ),
    new Metric(
        key: 'sales', 
        value: 72,
    ),
]);

指标选项完整列表

use \LaravelDataBox\Facades\DataBox;

$source = DataBox::source();
$source->push(new Metric(
    key: 'sales',
    value: 888.22, 
    date: now()->subDay(), // date of the metric event
    attributes: [ // Custom attributes for dimensions
        'channel' => 'sales'
    ],
    'unit' => 'EUR', // Unit of the value
));

使用不同的来源

use \LaravelDataBox\Facades\DataBox;

$source = DataBox::source('other_source');
$source->push(new Metric(
    key: 'sales',
    value: 888.22
));

测试

composer test

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

贡献

请参阅贡献指南以获取详细信息。

安全漏洞

请审查我们的安全策略以了解如何报告安全漏洞。

致谢

许可

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