How to monitor Platform Events consumption?
I've checked every documentation on platform events I could find, and the answer is: you can't monitor it without doing the monitoring yourself.
You can create a custom object or a custom setting to store the event count, since platform events support after insert
triggers. From there, you can determine how many calls were made during a specific day (and even get a report on it, if you use a custom object). Something along the lines of:
trigger MyEventTrigger on MyEvent__e (after insert) {
// 1. Get your object that is being used as log
// 2. increment with the value of Trigger.new.size()
// 3. upsert said object
}
To avoid getting a huge record count, if you use a custom object, you can create one record for the day, or for the week. On the custom object you can have one field to track the amount for the day, or seven fields to track the days of the week (this seems more interesting since you can create formula fields to get averages on the same record, instead of using a report - just an idea).
Update from the Winter '20 release notes:
Monitor Platform Event Publishing Usage in REST API
The hourly event publishing usage for standard-volume and high-volume platform events is now available in REST API. Use the limits REST resource in your app to monitor your event publishing usage against the two allocations.
How: The limits resource contains these new values.
HourlyPublishedPlatformEvents
—High-volume platform event notifications published per hourHourlyPublishedStandardVolumePlatformEvents
—Standard-volume platform event notifications published per hour
I've checked, and they are also exposed via the OrgLimits
, so you can get them directly in Apex as well.
Comment from Jay Hurst (Salesforce PM for Platform Events):
There is currently not a way to actively check outside of using Shield Event Monitoring. We are planning on adding the current usage against the total limit to our REST API /limits resource. (Source)
So, beyond trying to track the limits yourself, I'd suggest voting to the idea: Expose Platform Event Limit Usage
As of the Spring '19 release you are now able to monitor Event Delivery through the limits resource via the REST API (stored in the DailyStandardVolumePlatformEvents response) - https://releasenotes.docs.salesforce.com/en-us/spring19/release-notes/rn_messaging_standard_volume_limit.htm
To monitor your monthly event delivery usage for High Volume Platform Events if you have purchased the add-on, use the limits REST API resource, and inspect the MonthlyPlatformEvents value. With the add-on purchase, they measure entitlement usage over the month rather than the strictly enforcing the daily limit. The limits resource returns the monthly maximum allocation - https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_event_limits.htm