October 1, 2019

How to monitor Salesforce Platform Events daily or 24-hour or hourly period usage?

Note:
MonthlyPlatformEvents (API version 47.0 and earlier)
MonthlyPlatformEventsUsageEntitlement (API version 48.0 and later)

1. Sample Code:
Map < String, OrgLimit > mapOrgLimit = OrgLimits.getMap();
Integer intLimit;
Integer intValue;

if ( mapOrgLimit.containsKey( 'DailyStandardVolumePlatformEvents' ) ) {
    
    mapOrgLimit.get( 'DailyStandardVolumePlatformEvents' ).getLimit();
    mapOrgLimit.get( 'DailyStandardVolumePlatformEvents' ).getValue();
    system.debug(
        'DailyStandardVolumePlatformEvents usage is ' +  intLimit + ' - ' + intValue
    );
    
}

if ( mapOrgLimit.containsKey( 'HourlyPublishedStandardVolumePlatformEvents' ) ) {
    intLimit = mapOrgLimit.get( 'HourlyPublishedStandardVolumePlatformEvents' ).getLimit();
    intValue = mapOrgLimit.get( 'HourlyPublishedStandardVolumePlatformEvents' ).getValue();
    system.debug(
        'HourlyPublishedStandardVolumePlatformEvents usage is ' +  intLimit + ' - ' + intValue
    );
    
}

if ( mapOrgLimit.containsKey( 'MonthlyPlatformEvents' ) ) {
    
    intLimit = mapOrgLimit.get( 'MonthlyPlatformEvents' ).getLimit();
    intValue = mapOrgLimit.get( 'MonthlyPlatformEvents' ).getValue();
    system.debug(
        'MonthlyPlatformEvents usage is ' +  intLimit + ' - ' + intValue
    );
    
}

if ( mapOrgLimit.containsKey( 'MonthlyPlatformEventsUsageEntitlement' ) ) {
    
    intLimit = mapOrgLimit.get( 'MonthlyPlatformEventsUsageEntitlement' ).getLimit();
    intValue = mapOrgLimit.get( 'MonthlyPlatformEventsUsageEntitlement' ).getValue();
    system.debug(
        'MonthlyPlatformEventsUsageEntitlement usage is ' +  intLimit + ' - ' + intValue
    );
    
}
 
2. Sample Code:
Execute the below code and download the log.
for ( OrgLimit o : OrgLimits.getAll() ) {
    system.debug( o.getName() + ' - ' + o.getValue() + ' - ' + o.getLimit() );                  
}  

Check DailyStandardVolumePlatformEvents


Check HourlyPublishedStandardVolumePlatformEvents


Check MonthlyPlatformEvents


Use the below link to subscribe using Workbench.

https://www.infallibletechie.com/2019/09/how-to-subscribe-to-salesforce-platform.html
 
To get usage data for event publishing and CometD-client delivery, query the PlatformEventUsageMetric object. Usage data is available for the last 24 hours, ending at the last hour, and for historical daily usage.

PLATFORM_EVENTS_PUBLISHED — Number of platform events published
PLATFORM_EVENTS_DELIVERED — Number of platform events delivered to CometD clients

Query to check Publishing Usage:
SELECT Name, StartDate, EndDate, Value FROM PlatformEventUsageMetric
WHERE Name='PLATFORM_EVENTS_PUBLISHED'
AND StartDate=2021-09-03T13:35:00.000Z AND EndDate=2021-09-03T14:35:00.000Z

Query to check Delivery Usage:
SELECT Name, StartDate, EndDate, Value FROM PlatformEventUsageMetric
WHERE Name='PLATFORM_EVENTS_DELIVERED'
AND StartDate=2021-09-03T13:35:00.000Z AND EndDate=2021-09-03T14:35:00.000Z

No comments:

Post a Comment