ody/influxdb
Composer 安装命令:
composer require ody/influxdb
包简介
InfluxDB 2.x logging integration for ODY Framework
README 文档
README
⚠️ IMPORTANT: This repository is automatically generated from the ody repo and is read-only.
A custom logging solution for ODY Framework that stores logs in InfluxDB 2.x.
Installation
composer require ody/influxdb
Configuration
Register the Service Provider
Add the InfluxDB2 service provider to your config/app.php configuration:
'providers' => [ // Other providers InfluxDB\Logging\InfluxDB2ServiceProvider::class, ],
Configure the Logger
Add an InfluxDB channel to your config/logging.php configuration:
'channels' => [ // Other channels... 'influxdb' => [ 'driver' => 'influxdb', 'url' => env('INFLUXDB_URL', 'http://127.0.0.1:8086'), 'token' => env('INFLUXDB_TOKEN', ''), 'org' => env('INFLUXDB_ORG', 'organization'), 'bucket' => env('INFLUXDB_BUCKET', 'logs'), 'measurement' => env('INFLUXDB_MEASUREMENT', 'logs'), 'level' => env('INFLUXDB_LOG_LEVEL', 'debug'), 'use_coroutines' => env('INFLUXDB_USE_COROUTINES', false), 'tags' => [ 'service' => env('APP_NAME', 'ody-service'), 'environment' => env('APP_ENV', 'production'), 'instance' => env('INSTANCE_ID', gethostname()), ], ], // Optional: Add to stack to log to multiple destinations 'production' => [ 'driver' => 'group', 'channels' => ['file', 'influxdb'], ], ],
Environment Variables
Configure the following environment variables in your .env file:
INFLUXDB_URL=http://localhost:8086
INFLUXDB_TOKEN=your_token_here
INFLUXDB_ORG=your_org
INFLUXDB_BUCKET=logs
INFLUXDB_LOG_LEVEL=debug
INFLUXDB_USE_COROUTINES=false
Usage
Basic Usage
// Log to InfluxDB channel logger('User registered', ['user_id' => 123], 'influxdb'); // Or configure influxdb as your default channel in config/logging.php // and use logger normally logger('System started');
Using Tags for Better Querying
// Log with custom tags logger('API request processed', [ 'duration' => 120, 'endpoint' => '/users', 'tags' => [ 'module' => 'api', 'method' => 'GET', 'status' => 200 ] ], 'influxdb');
Dependency Injection
use Psr\Log\LoggerInterface; class UserService { protected $logger; public function __construct(LoggerInterface $logger) { $this->logger = $logger; } public function registerUser($data) { // Register user logic... $this->logger->info('User registered', [ 'id' => $user->id, 'email' => $user->email ]); } }
Advanced Configuration
Using with Swoole Coroutines
For high-performance applications using Swoole, enable coroutines to make logging non-blocking:
'influxdb' => [ // ...other config 'use_coroutines' => true, ],
This will use Swoole coroutines to perform writes to InfluxDB asynchronously, preventing your application from blocking during log writes.
Custom Measurement Names
You can specify a custom measurement name:
'influxdb' => [ // ...other config 'measurement' => 'application_logs', ],
Grouping Related Logs
You can group related logs by adding the same tag values:
$requestId = uniqid(); logger('Request started', [ 'tags' => ['request_id' => $requestId] ]); // Later in the code logger('Database query executed', [ 'query' => 'SELECT * FROM users', 'duration' => 25, 'tags' => ['request_id' => $requestId] ]); // And finally logger('Request completed', [ 'duration' => 150, 'tags' => ['request_id' => $requestId] ]);
This allows you to query InfluxDB for all logs related to a specific request.
License
MIT
ody/influxdb 适用场景与选型建议
ody/influxdb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「Metrics」 「influxdb」 「time-series」 「InfluxDB2」 「ody」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ody/influxdb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ody/influxdb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ody/influxdb 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Send your app metrics to InfluxDB
Application metrics toolbox for InfluxDB
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
PSR-7 Middleware for instrumenting PHP applications
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-15