Docs » Integrations Guide » Use the Smart Agent » Monitors » collectd/opcache

collectd/opcache 🔗

Monitor Type: collectd/opcache (Source)

Accepts Endpoints: Yes

Multiple Instances Allowed: Yes

Overview 🔗

Monitors Opcache using opcache_get_status().

Setup 🔗

You must install on your PHP webserver the following PHP script:

header('Content-Type: application/json');
echo json_encode($status,JSON_PRETTY_PRINT);

Example with nginx:

location ~ /monitoring/.*\.php$ {
    #access_log off;
    allow ::1;
    deny all;
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_param  PHP_ADMIN_VALUE "open_basedir=/var/log:/usr/bin:/srv/http/monitoring";
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass php-handler;

Put the script named opcache_stat.php into /srv/http/monitoring then:

curl http://localhost/monitoring/opcache_stat.php
"opcache_enabled": true,
"cache_full": false,
"restart_pending": false,
"restart_in_progress": false,
"memory_usage": {
    "used_memory": 82614848,
    "free_memory": 183437232,
    "wasted_memory": 2383376,
    "current_wasted_percentage": 0.88787674903869629

Config Examples 🔗

 - type: collectd/opcache
   host: localhost
   port: 80

If status script is exposed on an endpoint other than /opcache_stat.php, you can use the path config option:

 - type: collectd/opcache
   host: localhost
   port: 80
   path: "/opcache"

You can also define the entire URL yourself using url config option but keep in mind useHTTPS will be ignored if so:

 - type: collectd/opcache
   host: localhost
   port: 80
   useHTTPS: true # will be ignored
   url: "http://{{.host}}:{{.port}}/opcache"

For a full list of options, see Configuration.

Configuration 🔗

To activate this monitor in the Smart Agent, add the following to your agent config:

monitors:  # All monitor config goes under this key
 - type: collectd/opcache
   ...  # Additional config

For a list of monitor options that are common to all monitors, see Common Configuration.

Config option Required Type Description
host no string The hostname of the webserver (i.e.
port no integer The port number of the webserver (i.e. 80). (default: 0)
useHTTPS no bool If true, the monitor will use HTTPS connection. (default: false)
path no string The URL path to use for the scrape URL for opcache script. (default: /opcache_stat.php)
url no string The URL, either a final URL or a Go template that will be populated with the host, port and path values.
name no string This will be sent as the plugin_instance dimension and can be any name you like.

Metrics 🔗

These are the metrics available for this monitor. All of the metrics emitted from this monitor are categorized as custom but the ones that are emitted by default from the monitor are in bold and italics in the list below.

  • cache_ratio.opcache_statistics-opcache_hit_rate (gauge)
    Hits / (Hits + Miss).
  • cache_result.opcache_statistics-hits (cumulative)
    Number of successful reads.
  • cache_result.opcache_statistics-misses (cumulative)
    Number of unsuccessful reads.
  • cache_size.memory_usage-free_memory (gauge)
    Amount of memory free.
  • cache_size.memory_usage-used_memory (gauge)
    Amount of memory used.
  • files.opcache_statistics-max_cached_keys (gauge)
    Maximum number of keys.
  • files.opcache_statistics-num_cached_keys (gauge)
    Number of keys in cache.
  • files.opcache_statistics-num_cached_scripts (gauge)
    Number of cached scripts.

Non-default metrics (version 4.7.0+) 🔗

To emit metrics that are not default, you can add those metrics in the generic monitor-level extraMetrics config option. Metrics that are derived from specific configuration options that do not appear in the above list of metrics do not need to be added to extraMetrics.

To see a list of metrics that will be emitted you can run agent-status monitors after configuring this monitor in a running agent instance.

Dimensions 🔗

The following dimensions may occur on metrics emitted by this monitor. Some dimensions may be specific to certain metrics.

Name Description
plugin_instance Set to whatever you set in the name config option.