MonItems - between real-time counters and storage

The MonItems class is the bridge between the counters and the storage.

The MemItems class either maps the contents of an existing memory-mapped file into MonItem objects or maps registered MonItem objects into a new or existing memory-mapped file.

Starting with release 2026.2, the format of the monitor segment (the file that rt.monitorfile specifies) has changed. If you have an application that reads the monitor segment with MemItems, you must rebuild the application against the P4 API for C/C++ from release 2026.2 or later. The segment now also contains per-user records, which the server uses for rate limiting. These records are named rl:user.

To write a utility that accesses the counters and reads their values, see the example that exports the counters in a manner compatible with Prometheus real-time monitoring, p4mon-prometheus-exporter.cc, which is located inside the Perforce filehost location for p4source.tgz

For more information, see p4 monitor realtime in P4 CLI Reference.

Constructor
MonItems()
Methods
bool Load(const char *file, Error *e)

Loads an existing memory mapped file, registering the MonItem objects in the file

void Display()

Dumps all the registered MonItem objects to STDOUT

MonItem *First()

Returns the first registered MonItem object. Use with Next(MonItem *counter) to iterate over MonItem objects

MonItem *Next(MonItem *counter)

Returns the next registered MonItem object. Use with First() to iterate over MonItem objects