Last Updated on May 1, 2023 by Rakesh Gupta
Big Idea or Enduring Question:
- How to monitor Platform Events consumption?
Objectives:
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.
Field Name |
Details |
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.
After Summer’23 Release, you can get the aggregate usage data by event name and determine which event is using up more of your allocations. Group usage by client to find out how many clients subscribed to a particular event and how your event delivery usage is shared among clients. Use granular time aggregations of daily, hourly, and 15-minute periods to slice and dice usage data. When you query PlatformEventUsageMetric, you can use these new fields: EventName
, Client
, EventType
, and UsageType
.
- Enhanced usage metrics is available in API version 58.0 and later after you enable this feature in Metadata API using PlatformEventSettings.
- This example query returns hourly event usage for delivered events from April 1 through April 2 in UTC time. The query aggregates the results into one-hour intervals as specified by the
TimeSegment
field. Results are grouped per event and client because theEventName
andClient
fields are specified in the SELECT statement.SELECT EventName, Client, Value, StartDate, EndDate FROM PlatformEventUsageMetric WHERE TimeSegment='Hourly' AND UsageType='DELIVERY' AND StartDate >= 2023-04-01T00:00:00.000Z AND EndDate <= 2023-04-02T00:00:00.000Z
Formative Assessment:
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.
Is it possible to view how many platform events are waiting to be published right now?