Monitoring PHP FPM using OpenTelemetry

OpenTelemetry PHP FPM

To monitor PHP FPM performance, you can use OpenTelemetry Collector to collect metrics and Uptrace to visualize them.

It works like this:

  • PHP-FPM exporter provides a Prometheus endpoint with metrics.
  • OpenTelemetry Collector scrapes the PHP-FPM Prometheus endpoint and exports data to Uptrace.
  • Uptrace stores and visualizes the metrics it receives from OpenTelemetry Collector.

PHP-FPM exporter

PHP-FPM Exporteropen in new window is a Prometheus exporter that allows you to scrape PHP-FPM metrics using Prometheus or OpenTelemetry Collector.

PHP-FPM Exporter collects metrics such as request counts, response times, memory usage, and various other performance-related data from PHP-FPM. These metrics can then be visualized, monitored, and used for alerting in Uptrace.

To retrieve information from PHP-FPM running on 127.0.0.1:9000 with status endpoint being /status:

php-fpm_exporter get --phpfpm.scrape-uri tcp://127.0.0.1:9000/status

See php-fpm_exporteropen in new window documentation for more details.

What is OpenTelemetry Collector?

You can deploy OpenTelemetry Collectoropen in new window as an agent that runs on individual hosts, where it periodically collects and forwards diagnostic information about the running system to various distributed tracing toolsopen in new window.

OpenTelemetry Collector provides powerful data processing capabilities. It can aggregate, filter, transform, and enrich telemetry data as it flows through the system.

Scraping PHP FPM metrics

To start monitoring PHP-FPM with OpenTelemetry, you need to configure OpenTelemetry Collector to scrape the PHP-FPM exporter endpoint.

Here is the OpenTelemetry Collector config from php-fpmopen in new window Docker example:

receivers:
  otlp:
    protocols:
      grpc:
      http:
  prometheus/phpfpm:
    config:
      scrape_configs:
        - job_name: php-fpm
          static_configs:
            - targets: [php-fpm-exporter:9253]

exporters:
  otlp/uptrace:
    endpoint: otlp.uptrace.dev:4317
    headers: { 'uptrace-dsn': '${UPTRACE_DSN}' }

processors:
  resourcedetection:
    detectors: [env, system]
  cumulativetodelta:
  batch:
    timeout: 10s

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/uptrace]
    metrics:
      receivers: [otlp, prometheus/phpfpm]
      processors: [cumulativetodelta, batch, resourcedetection]
      exporters: [otlp/uptrace]
  telemetry:
    logs:
      level: 'debug'

Next, use Uptrace or Grafana Alternativesopen in new window to create dashboards and graphs based on the PHP-FPM metrics collected by OpenTelemetry Collector.

OpenTelemetry Backend

Once the metrics are collected and exported, you can visualize them using a compatible backend system. For example, you can use Uptrace to create dashboards that display metrics from the OpenTelemetry Collector.

Uptrace is a distributed tracing toolopen in new window that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace Overview

Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with notifications, and integrations for most languages and frameworks.

Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.

In just a few minutes, you can try Uptrace by visiting the cloud demoopen in new window (no login required) or running it locally with Dockeropen in new window. The source code is available on GitHubopen in new window.

What's next?

By setting up the PHP-FPM Exporter and integrating it with Uptrace, you can gain insights into the performance and health of your PHP-FPM instances and make informed decisions regarding optimizations or troubleshooting.

Next, you can learn more about configuring OpenTelemetry Collector. To start using OpenTelemetry and Uptrace, see Getting started with Uptrace.

Last Updated: