saifh/laravel-phpfpm-prometheus-exporter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

saifh/laravel-phpfpm-prometheus-exporter

最新稳定版本:1.0.1

Composer 安装命令:

composer require saifh/laravel-phpfpm-prometheus-exporter

包简介

Exposes a prometheus /metrics endpoint in your Laravel application, intended for use as a Kubernetes HPA driver.

README 文档

README

This project exposes a Prometheus metrics endpoint in your Laravel application, based on FPM's current state.

It exposes 3 metrics:

  1. Idle processes
  2. Total processes
  3. Active processes

This can be used in conjunction with Prometheus Adapter to give you new metrics to scale your application up and down with Kubernetes.

Config

Publish the config file via php artisan vendor:publish --tag=prometheus to customize your configuration.

Prometheus Adapter Config

Given the following rule:

rules:
  default: false
  custom:
    - seriesQuery: 'phpfpm_active_processes{namespace!="",pod_name!=""}'
      resources:
        overrides:
          namespace:
            resource: namespace
          pod_name:
            resource: pod
      name:
        matches: "phpfpm_active_processes"
        as: "phpfpm_active_processes_utilization"
      metricsQuery: avg(phpfpm_active_processes{<<.LabelMatchers>>} / phpfpm_total_processes{<<.LabelMatchers>>}) by (<<.GroupBy>>)

And the following Kubernetes HPA

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2
metadata:
  name: php-fpm-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-fpm
  # autoscale between 1 and 2 replicas
  minReplicas: 1
  maxReplicas: 2
  metrics:
  # use a "Pods" metric, which takes the average of the
  # given metric across all pods controlled by the autoscaling target
  - type: Pods
    pods:
      # use the metric that you used above: pods/http_requests
      metric:
        name: phpfpm_active_processes_utilization
      #Value: 500m: Targets 50% utilization
      target:
        type: Value
        averageValue: 500m

This will trigger a scale up when your average worker utilization hits 50%

Full Example

Coming soon.

Note

This project was heavily inspired by hipages/php-fpm_exporter.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-31