承接 altelma/laravel-prometheus-exporter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

altelma/laravel-prometheus-exporter

Composer 安装命令:

composer require altelma/laravel-prometheus-exporter

包简介

A Prometheus exporter for Laravel and Lumen

README 文档

README

Software License Latest Version on Packagist Total Downloads

A prometheus exporter package for Laravel and Lumen.

This package is a wrapper bridging promphp/prometheus_client_php into Laravel and Lumen.

However, This package get inspire from another package below

Feel free to use above package instead, because this package just try to cover compatibility for previous version of Laravel and Lumen such as 6.x to 8.x, etc.

Installation

Install the package via composer

composer require altelma/laravel-prometheus-exporter

If you are using Lumen need to register the service provider in bootstrap/app.php

$app->register(Altelma\LaravelPrometheusExporter\PrometheusServiceProvider::class);

Configuration

The package has a default configuration which uses the following environment variables.

PROMETHEUS_NAMESPACE=app

PROMETHEUS_METRICS_ROUTE_ENABLED=true
PROMETHEUS_METRICS_ROUTE_PATH=metrics
PROMETHEUS_METRICS_ROUTE_MIDDLEWARE=null
PROMETHEUS_COLLECT_FULL_SQL_QUERY=true
PROMETHEUS_STORAGE_ADAPTER=memory

PROMETHEUS_REDIS_HOST=localhost
PROMETHEUS_REDIS_PORT=6379
PROMETHEUS_REDIS_TIMEOUT=0.1
PROMETHEUS_REDIS_READ_TIMEOUT=10
PROMETHEUS_REDIS_PERSISTENT_CONNECTIONS=0
PROMETHEUS_REDIS_PREFIX=PROMETHEUS_

Metrics with multiple pods in k8s

If you want to expose metrics endpoint with application that running in k8s. It needs to store the same information with a single endpoint. So you need to add config like below

PROMETHEUS_REDIS_NAME="<your_custom_name>"

You need to ensure config set like this and this support Redis adapter only

PROMETHEUS_REDIS_PREFIX_DYNAMIC=true
PROMETHEUS_REDIS_PREFIX=<your_prefix_name>
PROMETHEUS_REDIS_NAME="<your_custom_name>"

Metrics

The package allows you to observe metrics on the application routes. Metrics on request method, request path and status code.

Laravel

In order to observe metrics in Laravel application routes (the time between a request and response), you should register the following middleware in your application's app/Http/Kernel.php:

protected $middleware = [
    \Altelma\LaravelPrometheusExporter\Middleware\PrometheusLaravelMiddleware::class,
];

Lumen 9.x

In order to observe metrics in Lumen application routes (the time between a request and response), you should register the following middleware in your application's bootstrap/app.php:

$app->middleware([
    \Altelma\LaravelPrometheusExporter\Middleware\PrometheusLumenMiddleware::class,
]);

Lumen 8.x and Lower

In Lumen 8.x and lower, cannot get route in global middleware just need to do in route middleware instead

$app->routeMiddleware([
    'http.prometheus' => \Altelma\LaravelPrometheusExporter\Middleware\PrometheusLumenRouteMiddleware::class,
]);

Protect metrics endpoint

If you need to prevent someone see your routes in /metrics you can add middleware to protect your endpoint. Now we start to support only basic_auth to protect you metrics endpoint

PROMETHEUS_METRICS_ROUTE_AUTH_ENABLED=true
PROMETHEUS_METRICS_ROUTE_AUTH_USERNAME=<basic_auth_username>
PROMETHEUS_METRICS_ROUTE_AUTH_PASSWORD=<basic_auth_password>

สนับสนุนผมได้นะ ☕

สวัสดีเพื่อนๆ ทุกคนนะครับ หากมีข้อเสนอแนะอะไร แนะนำมาได้นะครับ นอกจากนี้ เพื่อนๆ สามารถแวะไปอ่านบทความของผมเพิ่มเติมได้ ที่นี่ ครับ

Bug Report

This package is not perfect right, but can be improve together. If you found bug or have any suggestion. Send that to me or new issue. Thank you to use it.

altelma/laravel-prometheus-exporter 适用场景与选型建议

altelma/laravel-prometheus-exporter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.49k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「laravel」 「prometheus」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 altelma/laravel-prometheus-exporter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 altelma/laravel-prometheus-exporter 我们能提供哪些服务?
定制开发 / 二次开发

基于 altelma/laravel-prometheus-exporter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-06