Monitor Platform Event Publishing and Delivery Usage

Monitor Platform Event Publishing and Delivery Usage

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.

  • CHANGE_EVENTS_DELIVERED:- Number of change data capture events delivered to CometD clients
  • CHANGE_EVENTS_PUBLISHED:- Number of change data capture events published
  • PLATFORM_EVENTS_DELIVERED:- Number of platform events delivered to CometD clients
  • PLATFORM_EVENTS_PUBLISHED:- Number of platform events published
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:

  1. Platform Event Usage MonitorUnderstand the platform event usage in your org.
  2. 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.

  1. Click Setup | Developer Console 
  2. In the Query Editor, run the following SOQL query 
    1. SELECT Name, StartDate, EndDate, Value
      FROM PlatformEventUsageMetric

      WHERE Name IN (‘PLATFORM_EVENTS_DELIVERED’, ‘PLATFORM_EVENTS_PUBLISHED’)
      AND StartDate>=2021-12-20T00:00:00.000Z ORDER BY StartDate
  3. 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.

  1. Enhanced usage metrics is available in API version 58.0 and later after you enable this feature in Metadata API using PlatformEventSettings.
  2. 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 the EventName and Client 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.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

One thought on “Monitor Platform Event Publishing and Delivery Usage

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.