WP Manifestindependent plugin directory
manifest / analytics / prometheus-metrics-in-wordpress

Prometheus Metrics in WordPress

Prometheus endpoint customizable for WordPress

★ 54stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/codeatcode/prometheus-metrics-in-wordpress/archive/refs/heads/master.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

A WordPress plugin, based on https://github.com/CodeAtCode/WPDB-Status.

Grafana dashboard avalaible on official website, the wp_info data JSON for Grafana it's available here.

Build project

  • You need Composer
  • Run composer update -o

Settings

The plugin has a settings panel where you can configure what you need include the key.

Prometheus

To add a new target:

  - job_name: "WordPress metrics"
    static_configs:
      - targets: ["domain.tld"]
    scrape_interval: "5m"
    metrics_path: "/wp-json/metrics"
    params:
      prometheus: ['fg98dfgkj']
      users: ['yes']
      posts: ['yes']
      pages: ['yes']
      autoload: ['yes']
      transient: ['yes']
      user_sessions: ['yes']
      posts_without_content: ['yes']
      posts_without_title: ['yes']
      db_size: ['yes']
      pending_updates: ['yes']
    scheme: "https"

WordPress customization

This plugin includes a hook to append new metrics: prometheus_custom_metrics

URL parameters

Enable all

all=yes enables all of the default filters at once

Enable or disable specific metrics

See the included page at Tools -> Site Health -> Prometheus with specific metric parameters.

Changelog

3.1.x

  • Metrics
    • Added / Improved metrics for more technical insights (DB, PHP, WordPress)
  • Site Health Check
    • Added section with InfluxDB Task example
  • Some cleanup

3.0.x

2.1

  • Seperated host and schema (and port)
  • Added metric for writing temporary file into uploads folder
  • Disabled legacy metrics by default (to avoid warnings in the logs)
    • Enable it, by adding define('PROMETHEUS_INCLUDE_LEGACY_METRICS', true); to wp-config.php

2.0

  • Major rewrite, which may break your current metrics!
  • Requires at least WordPress 5.6 and PHP 7.3
    • Added PHP 8.0 polyfill
  • Use 'gauge' instead of 'counter'
    • Define PROMETHEUS_LEGACY_TYPE with true to change this
  • Added more metrics
    • You can add custom metrics by implementing WP_Prometheus_Metrics\Metric
  • Added timestamps to metrics
  • Metrics will be cached for 1h by default (use filter prometheus-metrics-for-wp/timeout to change this)
  • Seperated metrics for different post types
  • Site health check integration
    • View url for endpoint
    • Ability to generate authentication keys

Legacy support

To use 'counter' instead of 'gauge', add the following to your wp-config.php

define('PROMETHEUS_LEGACY_TYPE', true);