Oracle Cloud Infrastructure gathers metrics from all OCI resources. These metrics can be visualized and analyzed with the Metrics Explorer. And Alarms can be defined with rules evaluating the metrics that publish to a Notification Topic to signal a situation of interest. Subscriptions can be defined on these Notification Topics, to route the notifications to destinations that can be of three types: email, PagerDuty or WebHook. The latter means that a notification can be sent virtually anywhere – including to an API Gateway on OCI that routes the notification to a Function.
OCI Resources that can be observed include Functions (FaaS), Streams (Streaming Topics), Object Storage Buckets, API Gateway (Deployments) and Virtual Networks. Each resource or metrics namespace produces a different set of metrics. The next figure gives an overview of the metrics for each type of resources:
Conditions are defined using a streaming query language (Monitoring Query Language, MQL) that uses aggregation operators applied to time intervals.
Using these conditions, we can create alarms that are triggered when something happens (a lot) and also when something does not happen (as much). We can make these alarms publish to a notification topic and create a subscription that sends an email as a result.
I will now show a simple example of an Alarm [+ Notification Topic + Subscription] that results in an email when a function is invoked.
Example Alarm – Sending an Email when a Function is invoked More then X times per Time Interval
The next figure shows the set up in this example: Function hello is observed; the metric that counts the number of invocations of the function is used in a rules: the number is aggregated over 1 minute and every time that aggregation produces a value larger than 0 (meaning: the function was executed at least once), the alarm is triggered. This by itself does not really mean anything or at least does not automatically results in any action being taken.
The Alarm is associated with a Notification Topic called HelloExecutionTopic . Whenever the Alarm is triggered, it will publish a message on this topic. Subsequently, a subscription is created on this topic. It has a destination of type Email, and the email address provided is my own. The entire flow: when function hello is invoked, after at most one minute the Alarm is triggered, a notification event is published on HelloExecutionTopic and and email is sent to my email address, notifying me of this momentous event.
The steps I went through on OCI to set this up. Note: the Function Hello was already there (and I know its OCID).
- Create Alarm Definition – using the function invocation count metric for function Hello – aggregating per minute
- Create Notification Topic and associate Alarm Definition with this Topic
- Create a Subscription on the Notification Topic – configured with my email address
- Confirm the subscription of my email address my responding to a confirmation email sent to my email account
And then to see some action:
- invoke function hello
- wait for the email to arrive that tells me about the fact that there has been a minute during which at least one function call was made to hello
In more detail:
The Alarm Definition is composed from a number of elements:
- Name, Severity and Body
- Resource Type and Scope (FaaS , lab-compartment), Metric (FunctionInvocationCount), Interval (1m) and Statistic (Sum)
- Resource (metric dimension) resourceId (OCID for function hello) Note: I tried to work with resourceDisplayName as Dimension and lab1:hello as as Dimension Value; however, that did not seem to work – the Alarm was not triggered
- Trigger Rule: > 0 (after at least 1 minute) – if the sum of the function invocation count for lab1:hello over 1 minute is greater than 0 i.e. if function hello is invoked, then trigger this alarm
The notification topic HelloExecutionTopic:
The Alarm is associated with the Notification Topic:
And a subscription is created on the topic – with email destination type:
After this subscription is created, I received an email, inviting me to confirm the subscription of this email address on the Notification Topic:
I confirmed as invited. And now I am ready to receive the notification emails when the hello function is invoked.
And… Action
Invoke function hello (via API Gateway):
And sure enough, I receive an email that advises me of the fact that the alarm was triggered:
Of course there are far more interesting events to raise alarms for than the fact that a function is invoked. And there are more interesting things to do with the event raised by the alarm than sending an email; through the WebHook that we can have invoked, we can perform all kinds of automated actions. Note that OCI Monitoring also supports custom metrics.
Resources
Oracle Cloud Infrastructure Docs:
- Managing Alarms: https://docs.cloud.oracle.com/en-us/iaas/Content/Monitoring/Tasks/managingalarms.htm
- Building MQL Queries – https://docs.cloud.oracle.com/en-us/iaas/Content/Monitoring/Tasks/buildingqueries.htm
- Notifications Overview – https://docs.cloud.oracle.com/en-us/iaas/Content/Notification/Concepts/notificationoverview.htm