Last Updated on March 30, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
- How to monitor Platform Events consumption?
After reading this blog, you’ll be able to:
- Understand the platform events
- Different apps to monitor platform event usages
- Query platform event usages for a given time-frame
Business Use case
Jestilla Zetkin is working as a System administrator at Gurukul On Cloud (GoC). She has received a requirement from her project manager to give the day-wise consumption of platform events published and delivered for the last 90 days.
What is Platform Events?
Event-driven architectures have become very popular in recent years, and for a good reason. It is based on the fire-and-forget pattern. Firing an event and letting each system handle business logic allows you to keep unrelated systems decoupled and can help simplify the architecture.
Platform events enable you to deliver secure, scalable, and customizable event notifications within Salesforce or from external sources. Apps can publish and subscribe to Platform Events on the Salesforce platform using Apex, Flow, or in an external system using CometD. If you want to learn more about Platform Event, check out the Trailhead Module.
Understand PlatformEventUsageMetric Object
Let’s take a pause here, familiarize yourself with the PlatformEventUsageMetric object in Salesforce. It contains useful data for event publishing and CometD-client delivery.
Usage data is available for the last 24 hours, ending at the last hour, and for historical daily usage. PlatformEventUsageMetric contains separate usage metrics for platform events and change data capture events.
|Name||The name of the metric to get usage for.
|StartDate||The start date and time in UTC used for querying usage metrics. The date granularity is hourly.|
|EndDate||The end date and time in UTC used for querying usage metrics. The date granularity is hourly.|
|Value||The usage value for the specified metric and date range.|
We will use PlatformEventUsageMetric to get visibility into our event usage and usage trends. The usage data gives us an idea of how close we are to our allocations and when it requires more allocations.
Route to AppExchange
We often encounter the requirement to find out daily or monthly platform event consumption with analytics. There are various apps on AppExchange to achieve it. Some of them are listed below:
- Platform Event Usage Monitor – Understand the platform event usage in your org.
- Streaming Monitor – Monitor streaming events (PushTopic, Generic, Standard/Custom Platform Events, CDC, etc.).
Guided Practice (We-do):
To find Platform Events published and delivered consumption for the last 90 days, we will use Developer Console to Query PlatformEventUsageMetric object.
Today is March 20, 2022 so that means that 90 days before today would be December 20, 2021.
- Click Setup | Developer Console
- In the Query Editor, run the following SOQL query
- If you want to download the data to share with the project manager or executive team, then consider using Visual Studio Code or Workbench.
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.