PHPackages                             imiphp/imi-influxdb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. imiphp/imi-influxdb

ActiveLibrary[Database &amp; ORM](/categories/database)

imiphp/imi-influxdb
===================

imi 框架 InfluxDB 组件。imi InfluxDB component.

2.1.x-dev(3y ago)10MulanPSL-2.0PHP

Since Oct 28Pushed 3y ago1 watchersCompare

[ Source](https://github.com/imiphp/imi-influxdb)[ Packagist](https://packagist.org/packages/imiphp/imi-influxdb)[ RSS](/packages/imiphp-imi-influxdb/feed)WikiDiscussions 2.1 Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (3)Used By (0)

imi-influxdb
============

[](#imi-influxdb)

[![Latest Version](https://camo.githubusercontent.com/cffa4a56d70888132be942e975d1491918bcfc0e570f1cbcca7edd9c7af5ea77/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d697068702f696d692d696e666c757864622e737667)](https://packagist.org/packages/imiphp/imi-influxdb)[![Php Version](https://camo.githubusercontent.com/4a5c2ab20974058a8bab53ecb30ac4c2e6bb961df6229b7386fdc097ab53dfa8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e342d627269676874677265656e2e737667)](https://secure.php.net/)[![Swoole Version](https://camo.githubusercontent.com/2b08ceed852c672ccac1ba1e0db0399fd6c269b1f40d58b8d4cf11455a95446d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73776f6f6c652d2533453d342e382e302d627269676874677265656e2e737667)](https://github.com/swoole/swoole-src)[![imi License](https://camo.githubusercontent.com/98bdbfaa35e79370786c656980aab520be3e8af9551d8418a3ca4da1775f84c9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d756c616e50534c253230322e302d627269676874677265656e2e737667)](https://github.com/imiphp/imi-influxdb/blob/2.1/LICENSE)

介绍
--

[](#介绍)

此项目是 imi 框架的 InfluxDB 组件。

自动引入 `yurunsoft/influxdb-orm`，可以直接使用该 ORM 功能。

**支持的功能：**

- InfluxDB 连接管理
- [influxdb-orm](https://github.com/Yurunsoft/influxdb-orm)
- 服务指标监控

> 正在开发中，随时可能修改，请勿用于生产环境！

安装
--

[](#安装)

`composer require imiphp/imi-influxdb:~2.1.0`

使用说明
----

[](#使用说明)

### InfluxDB 连接管理

[](#influxdb-连接管理)

#### 配置连接

[](#配置连接)

`config.php`：

```
[
    'influxDB'  => [
        'clients'   => [
            // default 是连接名称，可以随意更改
            'default'   => [
                'host'              => '127.0.0.1', // 主机名
                'port'              => 8086, // 端口
                'username'          => '', // 用户名
                'password'          => '', // 密码
                'defaultDatabase'   => '', // 默认数据库名
                'ssl'               => false, // 是否启用 SSL
                'verifySSL'         => false, // 是否验证 SSL 证书
                'timeout'           => 0, // 超时时间
                'connectTimeout'    => 0, // 连接超时时间
                'path'              =>'/', // 请求路径前缀
                'createDatabase'    => true, // 当数据库不存在时，自动创建数据库
            ],
        ],
        'default'   => 'default', // 默认连接名
    ],
]
```

#### 获取客户端对象

[](#获取客户端对象)

```
use Imi\InfluxDB\InfluxDB;

$client = InfluxDB::getClient(); // 获取默认客户端
$client = InfluxDB::getClient('default'); // 获取指定名称客户端
```

#### 获取数据库对象

[](#获取数据库对象)

```
use Imi\InfluxDB\InfluxDB;

$db = InfluxDB::getDatabase(); // 获取默认数据库名的对象
$db = InfluxDB::getDatabase('dbname'); // 获取指定数据库名的对象
$db = InfluxDB::getDatabase(null, 'default'); // 指定客户端名称
```

#### 使用数据库对象

[](#使用数据库对象)

```
$db = InfluxDB::getDatabase();
$db->query(); // SQL 查询
$db->writePoints(); // 写入数据
```

> 详细用法请参考：

#### InfluxDB ORM

[](#influxdb-orm)

详细用法请参考：

#### SQL 查询

[](#sql-查询)

#### 写入

[](#写入)

### 服务指标监控

[](#服务指标监控)

仅支持 Swoole、Workerman。

支持 TDengine InfluxDB 协议写入。

#### 安装所需组件

[](#安装所需组件)

`composer require imiphp/imi-meter:~2.1.0`

#### 配置

[](#配置)

**配置监控指标：**

`@app.beans`：

```
[
    'MeterRegistry' => [
        'driver'  => \Imi\InfluxDB\Meter\InfluxDBMeterRegistry::class,
        'options' => [
            'database'   => null, // 使用的数据库名，可以设为null使用连接中配置的数据库名
            'clientName' => null, // 连接客户端名称，可以设为null使用默认客户端名称
            'batch'      => 1000, // 单次推送的记录数量
            'interval'   => 0, // 推送时间周期，单位：秒，默认为0不启用推送，如希望监控生效，请设置一个合理的数值。
            // 所有标签如设为空字符串或 null 则忽略该标签
            'resultTag' => 'result', // 标签名-结果
            'exceptionTag' => 'exception', // 标签名-异常类名
            'instanceTag' => 'instance', // 标签名-实例
            'workerTag' => 'worker', // 标签名-WorkerId
            'instance' => 'imi', // 当前实例名称，每个实例要设置不同
        ],
    ],
]
```

**TDengine InfluxDB 所需修改的配置：**

```
// 连接配置一定要设置这几项
[
    'port'              => 6041,
    'path'              => '/influxdb/v1/',
    'createDatabase'    => false,
    'username'          => 'root',
    'password'          => 'taosdata',
]
```

#### 使用

[](#使用)

##### 注解

[](#注解)

###### @Counted

[](#counted)

类名：`\Imi\Meter\Annotation\Counted`

计数统计，适合只累加，不减少的统计数据类型。

例如：访问次数统计。

参数名类型默认值描述name`string``imi.counted`指标名称recordFailuresOnly`false``bool`是否只在抛出异常时记录tags`array``[]`标签，键值数组description`string`描述options`array``[]`额外参数，每个驱动不同###### @Gauged

[](#gauged)

类名：`\Imi\Meter\Annotation\Gauged`

适合数字有上下波动的统计。

例如：CPU 占用率统计。

参数名类型默认值描述name`string``imi.counted`指标名称recordFailuresOnly`false``bool`是否只在抛出异常时记录tags`array``[]`标签，键值数组description`string`描述value`string|float``{returnValue}`写入的值；`{returnValue}` 表示方法返回值；`{returnValue.xxx}` 表示方法返回值的属性值；`{params.0}` 表示方法参数值；`{params.0.xxx}` 表示方法参数值的属性值；也可以是固定的 `float` 值operation`int``\Imi\Meter\Enum\GaugeOperation::SET`操作类型。设置`GaugeOperation::SET`；增加`GaugeOperation::INCREMENT`；减少`GaugeOperation::DECREMENT`options`array``[]`额外参数，每个驱动不同###### @Timed

[](#timed)

类名：`\Imi\Meter\Annotation\Timed`

耗时统计。

例如：方法执行耗时

参数名类型默认值描述name`string``imi.counted`指标名称tags`array``[]`标签，键值数组description`string`描述baseTimeUnit`int``\Imi\Meter\Enum\TimeUnit::NANO_SECOND`基础时间单位，默认纳秒，可以使用 `\Imi\Meter\Enum\TimeUnit::XXX` 常量设置。options`array``[]`额外参数，每个驱动不同###### @Histogram

[](#histogram)

类名：`\Imi\Meter\Annotation\Histogram`

柱状图，一般人用不懂，如无特殊需求可以无视。

参数名类型默认值描述name`string``imi.counted`指标名称tags`array``[]`标签，键值数组description`string`描述buckets`array``[]`桶，例如：`[100, 500, 1000]`baseTimeUnit`int``\Imi\Meter\Enum\TimeUnit::NANO_SECOND`基础时间单位，默认纳秒，可以使用 `\Imi\Meter\Enum\TimeUnit::XXX` 常量设置。value`string|float``{returnValue}`写入的值；`{returnValue}` 表示方法返回值；`{returnValue.xxx}` 表示方法返回值的属性值；`{params.0}` 表示方法参数值；`{params.0.xxx}` 表示方法参数值的属性值；也可以是固定的 `float` 值options`array``[]`额外参数，每个驱动不同###### @Summary

[](#summary)

类名：`\Imi\Meter\Annotation\Summary`

采样点分位图，一般人用不懂，如无特殊需求可以无视。

参数名类型默认值描述name`string``imi.counted`指标名称tags`array``[]`标签，键值数组description`string`描述percentile`array``[]`百分位数，例如：`[0.01, 0.5, 0.99]`baseTimeUnit`int``\Imi\Meter\Enum\TimeUnit::NANO_SECOND`基础时间单位，默认纳秒，可以使用 `\Imi\Meter\Enum\TimeUnit::XXX` 常量设置。value`string|float``{returnValue}`写入的值；`{returnValue}` 表示方法返回值；`{returnValue.xxx}` 表示方法返回值的属性值；`{params.0}` 表示方法参数值；`{params.0.xxx}` 表示方法参数值的属性值；也可以是固定的 `float` 值options`array``[]`额外参数，每个驱动不同**代码示例：**

```
use Imi\Meter\Annotation\Gauged;
use Imi\Meter\Annotation\Histogram;
use Imi\Meter\Annotation\Summary;
use Imi\Meter\Annotation\Timed;
use Imi\Meter\Enum\TimeUnit;

/**
 * @Gauged(name="test_memory_usage", description="memory usage", tags={"workerId"="{returnValue.workerId}"}, value="{returnValue.memory}")
 */
public function recordMemoryUsage(): array
{
    return [
        'workerId' => Worker::getWorkerId(),
        'memory'   => memory_get_usage(),
    ];
}

/**
 * @Timed(name="test_timed", description="memory usage", baseTimeUnit=TimeUnit::MILLI_SECONDS)
 */
public function testTimed(): int
{
    $ms = mt_rand(10, 1000);
    usleep($ms * 1000);

    return $ms;
}

/**
 * @Timed(name="test_timed_histogram", description="memory usage", baseTimeUnit=TimeUnit::MILLI_SECONDS, options={"histogram"=true})
 */
public function testTimedHistogram(): int
{
    $ms = mt_rand(10, 1000);
    usleep($ms * 1000);

    return $ms;
}

/**
 * @Histogram(name="test_histogram", baseTimeUnit=TimeUnit::MILLI_SECONDS)
 */
public function testHistogram(): int
{
    return mt_rand(10, 1000);
}

/**
 * @Summary(name="test_summary", baseTimeUnit=TimeUnit::MILLI_SECONDS)
 */
public function testSummary(): int
{
    return mt_rand(10, 1000);
}
```

##### 手动操作

[](#手动操作)

```
use \Imi\Meter\Facade\MeterRegistry;
use \Imi\Meter\Enum\TimeUnit;

$description = '我是描述';
$tags = ['result' => 'success'];

// counter
MeterRegistry::getDriverInstance()->counter('testCounterManual', $tags, $description)->increment();

// gauge
MeterRegistry::getDriverInstance()->gauge('testGaugeManual', $tags, $description)->record(114514);

// timer
$timer = MeterRegistry::getDriverInstance()->timer('testTimedManual', $tags, $description, TimeUnit::MILLI_SECONDS);
$timerSample = $timer->start();
usleep(mt_rand(10, 1000) * 1000);
$timerSample->stop($timer);

// timer Histogram
$timer = MeterRegistry::getDriverInstance()->timer('testTimedHistogramManual', $tags, $description, TimeUnit::MILLI_SECONDS, [
    'histogram' => true,
]);
$timerSample = $timer->start();
usleep(mt_rand(10, 1000) * 1000); // 你的耗时代码
$timerSample->stop($timer);

// Histogram
$value = 114514;
MeterRegistry::getDriverInstance()->histogram('testHistogramManual', $tags, $description)->record($value);

// Summary
$value = 114514;
MeterRegistry::getDriverInstance()->summary('testHistogramManual', $tags, $description)->record($value);
```

免费技术支持
------

[](#免费技术支持)

QQ群：17916227 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)，如有问题会有人解答和修复。

运行环境
----

[](#运行环境)

- [PHP](https://php.net/) &gt;= 7.4
- [Composer](https://getcomposer.org/) &gt;= 2.0
- [Swoole](https://www.swoole.com/) &gt;= 4.8.0
- [imi](https://www.imiphp.com/) &gt;= 2.1

版权信息
----

[](#版权信息)

`imi-influxdb` 遵循 MulanPSL-2.0 开源协议发布，并提供免费使用。

捐赠
--

[](#捐赠)

[![](https://camo.githubusercontent.com/24487a1dd6ab2d9c7b7492027024eae97eba149b95eab696a568034005ae335d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e312f7265732f7061792e706e67)](https://camo.githubusercontent.com/24487a1dd6ab2d9c7b7492027024eae97eba149b95eab696a568034005ae335d/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f696d697068702f696d6940322e312f7265732f7061792e706e67)

开源不求盈利，多少都是心意，生活不易，随缘随缘……

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1292d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (7 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imiphp-imi-influxdb/health.svg)

```
[![Health](https://phpackages.com/badges/imiphp-imi-influxdb/health.svg)](https://phpackages.com/packages/imiphp-imi-influxdb)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
