LaravelPackages.net
Acme Inc.
Toggle sidebar
saifh/laravel-phpfpm-prometheus-exporter

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

7
3
1.0.1
About saifh/laravel-phpfpm-prometheus-exporter

saifh/laravel-phpfpm-prometheus-exporter is a Laravel package for exposes a prometheus /metrics endpoint in your laravel application, intended for use as a kubernetes hpa driver.. It currently has 3 GitHub stars and 7 downloads on Packagist (latest version 1.0.1). Install it with composer require saifh/laravel-phpfpm-prometheus-exporter. Discover more Laravel packages by saifh or browse all Laravel packages to compare alternatives.

Last updated

Laravel PHP-FPM Prometheus Exporter

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.

Comments