kibatic/prometheus-metrics-builder

一个帮助构建Prometheus指标的库

v1.0.1 2022-11-21 20:19 UTC

This package is auto-updated.

Last update: 2024-09-22 00:31:53 UTC


README

example workflow

这个库可以帮助你为PHP应用程序构建Prometheus指标端点。

快速开始

安装库

composer require kibatic/prometheus-metrics-builder

基本用法

$metricList = new MetricList();
$metricList->addMetric(new Metric('foo', 1));
$metricList->addMetric(new Metric('bar', "NaN"));
$metricList->addMetric(new Metric(
    'bar',
    1.35,
    [
        'label1' => 'value1',
        'label2' => 'value2',
    ]
));
$response = $metricList->getResponseContent();
$metricList->clearMetrics();

响应内容将是

foo 1
bar NaN
bar{label1="value1",label2="value2"} 1.35

更高级的用法

属性

$metric = new Metric(
    'my_metric_name',
    12,
    [
        'module' => 'invoice',
        'instance' => 'value2',
    ],
    new \DateTimeImmutable()
)

带毫秒的时间戳

$metric = new Metric(
    'foo',
    1,
    [],
    new \DateTimeImmutable('2020-01-01 00:00:00.012')
);

对于开发者

运行测试

# install all the needed dependencies
make composer

# run unit tests
make test

路线图

  • 目前没有计划

版本

2022-11-21 : v1.0.1

  • 添加CI与GitHub Actions

2022-11-21 : v1.0.0

  • 初始版本