Azure

Monitor Logs And Analytics In Azure Monitor

Introduction

Once we are the administrator of the corporate’s Azure cloud infrastructure and accountable for programs which can be vital to our firm’s operations, we are going to arrange monitoring and diagnostics to assist look ahead to issues.

Azure Monitor helps you maximize the supply and efficiency of your functions and companies. It delivers a complete answer for amassing, analyzing, and appearing on telemetry out of your cloud and on-premises environments. – Definition supplied in Azure Docs

Conditions

  • Azure account (You will get a free Azure account from the Microsoft developer necessities program)
  • Already must have an Azure Storage account. In case you do not kindly create an account referring to the articles.

Making a Log Analytics Workspace

After logging into the Azure Portal.

Within the high search bar, kind in and click on on Log Analytics workspaces

Proper underneath the Log Analytics workspaces title, click on on + Create.

  1. For the Useful resource group, create a brand new one or else selected the out there one. For Title, Kindly use the distinctive title.
  2. For Area, selected East-us. Click on Overview + Create after which press Create

After the deployment is full, click on on Go to the useful resource.

Configuring the Diagnostics Settings

  1. On the monitor-wa web page, within the left-hand menu scroll all the way down to the Monitoring part, then click on Diagnostic settings. Click on + Add diagnostic setting

On the Diagnostic setting web page, enter the next:

  • Diagnostic setting title: AuditToAnalytics
  • Logs: Test audit
  • Vacation spot particulars: Test to Ship to Log Analytics workspace

Within the top-left, click on Save.

Monitor Logs and Analytics in Azure Monitor

Configure Log Analytics and Create a Question

On the highest search bar, kind in and click on on Monitor, and on the left-hand menu, click on on Logs.

Within the Choose a scope web page, kind in monitor-wa within the Search to filter gadgets… bar, press enter, and choose monitor-wa, then click on Apply.

Monitor Logs and Analytics in Azure Monitor

On the correct of the web page underneath the Run button, within the question editor which says Kind your question right here, paste within the following:

LAQueryLogs | the place TimeGenerated > in the past(1h) | summarring(ResponseCode), bin(TimeGenerated, 1m) | render columnchart with (variety=stacked)ize rely() by tost

Monitor Logs and Analytics in Azure Monitor

On the highest, click on on Save > Save as a question. Then, within the Save as question pop-up, for Question title kind in AnalyticsLogResponseCodes and click on Save.

Click on on the primary line of the question you entered earlier to pick it, then click on Run

Beneath the question, within the Chart tab, you will note a bar graph. If not, await about 5 minutes, then run it once more; the question makes use of knowledge created from this lab. so no outcomes could have been logged while you first run the question.

Monitor Logs and Analytics in Azure Monitor

Arrange Alerts

Within the left-hand menu, click on Alerts. Click on + New Alert Rule. On the Create an alert rule web page, on the Scope tab, click on + Choose scope.

On the Choose a useful resource panel, from Filter by useful resource kind choose Storage accounts, then click on the row with the Useful resource and selected the specified useful resource group. Click on Finished.

Again on the Create an alert rule web page, click on the Situation tab.

A Choose sign panel will present up. Chances are you’ll want to attend just a few seconds for the indicators to point out up.

In Choose a sign panel, and click on the row with a Sign title of Egress, This can trigger a Configure sign logic panel to seem.

Monitor Logs and Analytics in Azure Monitor

Within the Configure sign logic panel, scroll all the way down to the underside of the panel, and on the finish of the Alert logic part, go away Threshold as Static, and for Threshold worth enter 0. Then Press Finished.

Again on the Create an alert rule web page, click on the Actions tab, then click on + Create an motion group. Selected the specified useful resource group after which Click on Overview + Create and Create.

Monitor Logs and Analytics in Azure Monitor

Again on the Create an alert rule web page, click on the Particulars tab, then enter the next:

  • Alert rule title: StorageAcountAnyEgressAlert
  • Alert rule description: Alert triggers each minute there may be any egress from the storage account.

Then Click on Overview + create, then click on Create.

Monitor Logs and Analytics in Azure Monitor

You may be again on the Monitor | Alerts web page. Click on Alert guidelines.

Monitor Logs and Analytics in Azure Monitor

Configuring the Purposes Insights

We have to create an Utility Insights useful resource that can monitor an utility that we’re going to create within the upcoming part.

On the highest search bar, kind in and click on on Utility Insights, and Click on Create Utility Insights apps

On the Utility Insights web page, enter the next:

  • Useful resource Group: As the identical useful resource group that we used beforehand
  • Title: monitor-aw
  • Area: (US) East US
  • Log Analytics Workspace: monitor-wa(the title of the workspace you created earlier)

Click on Overview + create, then click on Create.

When the deployment is finished, then navigate to the useful resource web page.

Creating an Utility to Monitor

We’re going to create an ASP.NET Core utility and will configure it to watch the account utilizing the Utility Insights useful resource now we have created.

Copy down the Connection String from the monitor-aw perception for additional use.

Monitor Logs and Analytics in Azure Monitor

We’re going to create an utility utilizing Azure Cloud Shell.

On the highest of the display screen, click on on the Cloud Shell button and selected the PowerShell within the immediate

Monitor Logs and Analytics in Azure Monitor

Within the You don’t have any storage mounted window, click on on Present superior settings, and enter the next:

Click on Create storage.

  • Cloud Shell area: East US
  • Useful resource group: Choose Use current
  • Storage Account: Choose Use current and select the specified one
  • File share: powershell (Depart Create new chosen.)

Press Create storage.

As soon as the PowerShell command immediate is on the market, run the command dotnet new mvc -o mvc --no-https

Enter cd mvc, then enter dotnet add package deal Microsoft.ApplicationInsights.AspNetCore

After this, now we have a easy ASP.NET Core MVC utility created, and the Utility Insights package deal put in.

Enter code .

To open the venture within the VS Code.

Monitor Logs and Analytics in Azure Monitor

On the editor, on the left underneath FILES, click on on appsettings.json.

We’re going to Overwrite the contents of appsettings.json with the JSON under, then substitute <Connection String> on line 11 with the worth you saved earlier (be certain to enter the connection string inside double quotes).

{
    "Logging": {
        "LogLevel": {
            "Default": "Info",
            "Microsoft": "Warning",
            "Microsoft.Internet hosting.Lifetime": "Info"
        }
    },
    "AllowedHosts": "*",
    "ApplicationInsights": {
        "ConnectionString": "<Connection String>"
    }
}

We are including the ApplicationInsights setting, which can enable the Utility Insights to watch this utility.

Save the file utilizing the ctrl + S command

Click on on the Startup.cs file and the companies.AddApplicationInsightsTelemetry(); underneath the ConfigureServices() technique and Save it.

Navigate to FILES >Controllers >HomeController.cs. Overright the prevailing Index() technique with the under code.

public IActionResult Index() {
    _logger.LogWarning("Index accessed efficiently");
    return View();
}

Again on the command immediate, run the command dotnet run

On the highest of the PowerShell panel, click on the Internet preview button after which click on on the Configure

On the Configure port to preview window, kind 5000 into the sphere, and click on Open and browse.

It opens a welcome web page in a brand new tab.

Then refresh the tab a number of instances then shut the home windows. It is going to generate a log occasion which we are going to monitor by Utility insights

Monitor Logs and Analytics in Azure Monitor

Again to the portal browser tab and shut the PowerShell. 

On the left-hand menu click on on Transaction search and Click on See all knowledge within the final 24 hours.

Monitor Logs and Analytics in Azure Monitor

We’ll see underneath Outcomes numerous occasions, together with the log warning our code printed, Index accessed efficiently.

Conclusion

Now it is every little thing is about up for builders to have the ability to produce a correct net utility with utility insights enabled.

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button