This example records a single data source named wf_demo in a
collector-local plugin table. It illustrates three decisions a plugin
author must make: which hook supplies the data, which installation owns
the write, and how repeated delivery affects storage.
The poller builds a batch keyed by RRD path. Each entry carries a
local_data_id and a times array mapping Unix timestamps to data-source
names and values. Cacti passes that batch to the poller_output function
hook. The example registers a callback in its install function:
api_plugin_register_hook('workflowdemo', 'poller_output', 'workflowdemo_output', 'setup.php');On a remote collector, remote_collect:1 in INFO enables this hook.
The separate remote_poller capability applies to poller_bottom.
Choose poller_output when you need the measurements themselves.
The main server also dispatches the hook. The example checks the collector
ID and returns immediately on collector 1, which keeps the write local to
the remote instance.
$collector = defined('POLLER_ID') ? POLLER_ID : (int) $config['poller_id'];
if ($collector === 1) {
return $batch;
}Within the callback, return the original batch on every normal path. Other registered callbacks can receive the value your callback returns.
For each timestamp, the example selects the wf_demo field. A unique key
covers collector ID, local data ID, timestamp, and field name. The table's
primary key enforces uniqueness across concurrent connections. Replaying
the same identity updates its reading. A new timestamp produces a new row.
$key = hash('sha256', implode(':', [$collector, $rrd['local_data_id'], $time, 'wf_demo']));
db_execute_prepared('INSERT INTO plugin_workflowdemo_samples
(sample_key, collector, data_id, sample_time, reading) VALUES (?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE reading = VALUES(reading)',
[$key, $collector, $rrd['local_data_id'], $time, $fields['wf_demo']]);The example keeps the reading as text so an unknown sample (U) remains
distinguishable from zero. Its table lives on the collector. A plugin
that also displays these records centrally needs a separate transfer and
reconciliation design. Declaring a hook capability does not replicate
plugin-owned rows.
Use a disposable main installation with collector ID 1 and a remote installation with its own Cacti database and a configured collector ID greater than 1. See Remote Poller Setup for the collector configuration. Deploy the same example plugin on both. Confirm the plugin tables exist and the hook is enabled in both databases:
SELECT name, hook, status FROM plugin_hooks
WHERE name = 'workflowdemo' AND hook = 'poller_output';
SELECT COUNT(*) FROM plugin_workflowdemo_samples;Start with hook status 1 and zero sample rows. From the Cacti root on the main server, run this command once. Then run it twice on the collector:
php plugins/workflowdemo/replay.phpThe CLI fixture sends one synthetic batch to the real registered-hook
dispatcher. It checks that the returned batch is unchanged. It uses local
data ID 42, timestamp 1700000000, field wf_demo, and reading 7. It does
not require an RRD file or an SNMP agent.
Run this query separately against the main and collector databases:
SELECT collector, data_id, sample_time, reading, COUNT(*) AS copies
FROM plugin_workflowdemo_samples
GROUP BY collector, data_id, sample_time, reading;The main database should return no rows. For collector ID 2, the collector
should return exactly 2, 42, 1700000000, 7, 1. If the collector has no
row, inspect its local plugin registration, INFO, and actual collector
ID. If it has two rows for one identity, inspect the key definition. For
a plugin that consumes live devices, also poll a configured test device
and trace its actual data-source name and timestamp through the callback.
The replay exercises dispatch and persistence downstream of collection.
For comparison, see the upstream poller implementation and hook capability checks.
Copyright (c) 2004-2026 The Cacti Group