Monitoring in AWS

Just like Microsoft Azure, AWS provides an integrated solution, which allows IT operations to monitor applications, resources, and services in real time. In AWS, this solution is called CloudWatch. It provides nearly the same features as Application Insights, meaning it works for the entire AWS subscription, and includes dashboards and diagrams, for quick access to analytic data.

The following example illustrates how to use AWS CloudWatch to monitor generic metrics and custom metrics, so that you can learn how to deploy it for your own needs:

  1. Open the Tic-Tac-Toe web project, and download and install the Amazon Web Services SDK for .NET - Core Runtime NuGet package called AWSSDK.Core, as well as the Amazon Web Services CloudWatch NuGet package called AWSSDK.CloudWatch.
  2. Add a new service called AmazonWebServicesMonitoringService to the Services folder, make it inherit the IMonitoringService interface, and implement the TrackEvent method with the AWS-specific code, as shown in the following code block:
        public class AmazonWebServicesMonitoringService : 
IMonitoringService {
readonly AmazonCloudWatchClient _telemetryClient = new
AmazonCloudWatchClient(); public void TrackEvent(string eventName, TimeSpan
elapsed,
IDictionary<string, string> properties = null) { ... } }

  1. Here is the actual code in the TrackEvent method: 
var dimension = new Dimension { Name = eventName, Value = eventName };  
var metric1 = new MetricDatum 
{ 
  Dimensions = new List<Dimension> { dimension }, 
  MetricName = eventName, StatisticValues = new StatisticSet(), 
  Timestamp = DateTime.Today, Unit = StandardUnit.Count 
}; 
 
if (properties?.ContainsKey("value") == true) 
  metric1.Value = long.Parse(properties["value"]); 
else   metric1.Value = 1; 
 
var request = new PutMetricDataRequest 
{ MetricData = new List<MetricDatum>() { metric1 }, Namespace = eventName  }; 
 _telemetryClient.PutMetricDataAsync(request).Wait();
  1. Update the Configure method in the Startup class, and register the Amazon Web Services Cloud Watch Monitoring Service, if it has been configured in the appsettings.json configuration file, as follows:
        ... 
        if (monitoringOptions.MonitoringType ==
"azureapplicationinsights") { services.AddSingleton<IMonitoringService,
AzureApplicationInsightsMonitoringService>(); } else if (monitoringOptions.MonitoringType ==
"amazonwebservicescloudwatch") { services.AddSingleton<IMonitoringService,
AmazonWebServicesMonitoringService>(); }
  1. Update the Monitoring section in the appsettings.json configuration file, and configure it for AWS CloudWatch, as follows:
        "Monitoring": { 
          "MonitoringType": "amazonwebservicescloudwatch", 
          "MonitoringSettings": "" 
        } 
  1. Publish the Tic-Tac-Toe web application to AWS Elastic Beanstalk, so that the new AWS CloudWatch configurations are applied. If you do not know how to do this, you can look it up in Chapter 12, Hosting ASP.NET Core 3 Applications.
  2. Start the application. Go to the AWS Management Console, enter CloudWatch in the AWS services textbox, and click on the displayed link. You will be redirected to the AWS CloudWatch welcome page, as follows:

  1. On the CloudWatch welcome page, click on the TicTacToe application, as follows:

  1. Click on an alarm to get more specific details about it, as follows:
  1. Return to the CloudWatch welcome page, enter RegisterUser as a search term in the textbox, and then click on Browse Metrics, as follows:

  1. You will see a diagram, as shown here, with the custom RegisterUser business metric:

This should suffice to give you a feel of how you can monitor your platform, but it is advised that you play around to see all the extra capabilities. I'm quite certain that you will have fun detecting and preventing anomalies in whatever application for which you are responsible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.31.206