Oracle Cloud Infrastructure Resource Monitoring — Alarm triggers Notification when Metrics satisfy Condition

Image for post
Image for post

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:

Image for post
Image for post

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 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.

Image for post
Image for post

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
Image for post
Image for post

The notification topic HelloExecutionTopic:

Image for post
Image for post

The Alarm is associated with the Notification Topic:

Image for post
Image for post

And a subscription is created on the topic — with email destination type:

Image for post
Image for post

After this subscription is created, I received an email, inviting me to confirm the subscription of this email address on the Notification Topic:

Image for post
Image for post

I confirmed as invited. And now I am ready to receive the notification emails when the hello function is invoked.

And… Action

Image for post
Image for post

And sure enough, I receive an email that advises me of the fact that the alarm was triggered:

Image for post
Image for post

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.

Originally published at https://technology.amis.nl on February 3, 2020.

Written by

Lucas Jellema is solution architect and CTO at AMIS, The Netherlands. He is Oracle ACE Director, Groundbreaker Ambassador, JavaOne Rockstar and programmer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store