bexiocom/prometheus_php
Composer 安装命令:
composer require bexiocom/prometheus_php
包简介
A PHP instrumentation library for Prometheus compatible with PHP 5.5 5.6, 7.0 and 7.1.
关键字:
README 文档
README
This library aims to be a lightweight utility for instrumenting a PHP application using Prometheus. It is heavily inspired by the golang client.
- The library is supposed to be compatible with the PHP version 5.5, 5.6, 7.0 and 7.1.
- This library tries to do not take any assumptions about the environment it is used in. You should be able to use it without any magic or with what ever tool belt you are using. Be it a lightweight dependency injection, Sympfony or something else.
Features
- Counter, Gauge and Histogram metric types.
- Redis and in memory storage.
- Rendering to text format.
Missing features
- Summary metric types.
- Ability to submit metric samples to a PushGateway.
- Storage utilising filesystem, Memcached and APC.
- Rendering to Protocol buffer format
- Registry class to ease usage when using the library without andy dependency injection tool.
Getting Started
Add this library to your project.
composer require bexiocom/prometheus_php:dev-master
Usage
Simple counter with no labels attached:
<?php use Bexio\PrometheusPHP\Metric\Counter; use Bexio\PrometheusPHP\Storage\InMemory; $storage = new InMemory(); $counter = Counter::createFromValues('simple_counter', 'Just a simple counting'); $counter->inc(); $storage->persist($counter);
More enhanced counter with labels:
<?php use Bexio\PrometheusPHP\Metric\CounterCollection; use Bexio\PrometheusPHP\Storage\InMemory; $storage = new InMemory(); $collection = CounterCollection::createFromValues('labeled_counter', 'Counting with labels', ['type']); $blueCounter = $collection->withLabels(['type' => 'blue']); $blueCounter->inc(); $redCounter = $collection->withLabels(['type' => 'red']); $redCounter->add(42); $storage->persist($collection);
Expose the metrics:
<?php use Bexio\PrometheusPHP\Metric\Counter; use Bexio\PrometheusPHP\Metric\CounterCollection; use Bexio\PrometheusPHP\Output\TextRenderer; use Bexio\PrometheusPHP\Storage\InMemory; use GuzzleHttp\Stream\BufferStream; $buffer = new BufferStream(); $renderer = TextRenderer::createFromStream($buffer); $storage = new InMemory([ 'simple_counter' => [ InMemory::DEFAULT_VALUE_INDEX => 1 ], 'labeled_counter' => [ '{"type":"blue"}' => 1, '{"type":"red"}' => 42, ], ]); $counter = Counter::createFromValues('simple_counter', 'Just a simple counting'); $renderer->render($counter, $storage->collectSamples($counter)); $collection = CounterCollection::createFromValues('labeled_counter', 'Counting with labels', ['type']); $renderer->render($collection, $storage->collectSamples($collection)); header(sprintf('Content-Type: %s', TextRenderer::MIME_TYPE)); echo $buffer->getContents();
Use Redis as storage backend:
NOTE: When using the Redis storage, it is highly suggested to add
ext-redisas requirement to your project.
<?php use Bexio\PrometheusPHP\Storage\Redis; $redis = new \Redis(); $redis->connect('localhost'); // Optional: tune your redis connection. $redis->setOption(\Redis::OPT_READ_TIMEOUT, 10); $storage = new Redis($redis, 'PROMETHEUS:');
Use Redis but open connection lacily:
<?php use Bexio\PrometheusPHP\Storage\Redis; $redis = new \Redis(); $storage = new Redis(new \Redis(), 'PROMETHEUS:', function(\Redis $redis) { if (!$redis->connect('localhost')) { throw new \Exception('Failed to connect to Redis server'); } $redis->setOption(\Redis::OPT_READ_TIMEOUT, 10); });
How to contribute
First off, thank you for considering contributing to this PHP Prometheus client library. It's people like you that make it useful for more than a handful of people.
Pull requests are happily accepted, given they follow the following simple rules:
- New feature must be covered with tests
- All tests must pass
composer check
- Do not mix things up. Only one feature/fix per pull request.
bexiocom/prometheus_php 适用场景与选型建议
bexiocom/prometheus_php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46.01k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2017 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「monitoring」 「prometheus」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bexiocom/prometheus_php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bexiocom/prometheus_php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bexiocom/prometheus_php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
Metrics endpoint for Laravel applications
A Prometheus exporter for Laravel and Lumen
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Statsd (Object Oriented) client library for PHP
统计信息
- 总下载量: 46.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-26