Note:

Automate a Custom Log Alert on Oracle Cloud Infrastructure Compute Linux using Oracle Cloud Infrastructure Logging

Introduction

In today’s cloud-centric world, effective monitoring and alerting are crucial to ensure the smooth operation of your applications and infrastructure. Proactive monitoring helps in identifying issues before they escalate, ensuring minimal downtime and optimal performance. In this tutorial, we will set up log monitoring and alerting without the need for tedious UI deployment and potential mistakes. This approach enhances automation and simplifies the management of both current and future deployments. For more information, see Custom Logs.

Objectives

We will collect and monitor Apache error logs. You can adapt this process for monitoring any logs that require constant attention. Since this tutorial provides Terraform code, you can reuse or modify it according to your specific requirements. This tutorial will guide you through setting up a comprehensive monitoring and alerting system using Oracle Cloud Infrastructure (OCI), Terraform, OCI Resource Manager, OCI Custom logs, OCI Connector Hub, and OCI Notifications.

We will create the following resources in Terraform, each with specific objectives:

Prerequisites

Automate a Custom Log Alert

  1. Log in to the OCI Console, go to Developer Services, Resource Manager, Stacks and click Create stack.

    Edit button

  2. Download the Terraform file from here: custom_log_alerts.zip and upload it to the stack.

    Edit button

    Edit button

    Edit button

    Edit button

    Edit button

  3. Enter the following information.

    • Existing compartment: This is where all resources will be deployed.Select the compartment where compute instances exist for log alerting.

    • Existing domain: This is Existing domain in the compartment.If not modified,Default domain is selected.

    • Label: Enter any keyword. This label gets prefixed to all resources created.

    • idcs_endpoint: This is the domain URL. To retrieve domain URL, go to the OCI Console and navigate to Identity, Domains.

    • email_endpoint: Enter email address to receive alerts.

    • Log_path: Any absolute path of logs which you want to alert. For example, for Apache error logs it will be /var/log/apache2/error.log.

    • parser: Select a related parser. For starters, select NONE by default. In this tutorial, select APACHE_ERROR parser for better visualization.

    Edit button

  4. Select Run apply and click Create. Wait until the stack job state shows succeeded as shown in the following image. The stack will create respective dynamic groups, policies, log group, custom log, agentconfig, connector hub, notifications and email subscriptions.

    Edit button

    Edit button

  5. (Optional) To check Apache logs from OCI Logging, go to the OCI Console and navigate to Observability and Management, Logging, select your compartment, click log name and Explore Log. This will be available only if there are new logs in the compute instance.

    Edit button

    Edit button

    Edit button

  6. Final test is to see if the alerts are being notified using email, ensure to click Confirm Subscription to receive notifications. Generate logs on an ad hoc basis if needed for testing.

    Edit button

Next Steps

By completing this tutorial, you have successfully set up an automated monitoring and alerting system for Apache error logs on OCI using Terraform. This streamlined approach ensures real-time log visibility and immediate notifications for critical issues, enhancing your ability to maintain optimal application performance. You can now extend this setup to monitor any logs requiring constant attention, ensuring proactive management of your infrastructure

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.