cdn77/papi

此包已被废弃,不再维护。未建议替代包。

PApi - Prometheus 的 PHP API 客户端库

v2.1 2018-06-01 14:11 UTC

This package is not auto-updated.

Last update: 2020-03-19 10:48:09 UTC


README

Build Status

提供从 Prometheus API 获取数据的简单方法。

兼容 Prometheus 1.x 和 <= v2.2 API 规范 注意:一些端点仅在 Prometheus 的新版本中可用。详细信息请参阅下方的 可用调用表

安装

使用 composer 添加 PApi 依赖

$ composer install cdn77/papi

使用方法

创建客户端

<?php
use PApi\Client;

require __DIR__ . '/vendor/autoload.php';

$client = new Client([
    'host' => 'my-prometheus.com',
]);

可用选项

名称 默认值 描述
scheme http 主机方案
host localhost 主机地址
port 9090 主机端口
path /api/v1/ 基本 API 端点路径
timeout 30 请求超时
username null HTTP 认证用户名
password null HTTP 认证密码
connectionHeaders [] 连接头
connectionType CurlConnection::class 用于连接的类。见下文

可用连接类

  • CurlConnection - 纯 PHP curl 实现。默认使用。
  • GuzzleConnection - 使用 guzzle 6.3+ 库。

可用调用

PApi 目前具有 Prometheus 提供的所有可用端点的调用方法。

调用 代码 Prometheus 兼容性 官方文档
查询 $client->getQuery('up', new \DateTimeImmutable('now'); >=1.0 文档
QueryRange $client->getQueryRange('up', new \DateTimeImmutable('today'), new \DateTimeImmutable('now'), '12h'); >=1.0 文档
Series $client->getSeries(['up'], new \DateTimeImmutable('-1 minute'), new \DateTimeImmutable('now'); >=1.0 文档
Label Values $client->getLabelValues('job'); >=1.0 文档
Targets (active only) $client->getTargets(); >=1.0 文档
Alert Managers $client->getAlertManagers(); >=1.0 文档
Create snapshot $client->createSnapshot(); >=2.1 文档
Delete series $client->deleteSeries(['up'], new DateTimeImmutable('today'), new DateTimeImmutable('now'); >=2.1 文档
Clean tombstones $client->cleanTombstones(); >=2.1 文档
Get Config $client->getConfig(); >=2.2 文档
Get Flags $client->getFlags(); >=2.2 文档