Monday, December 14, 2015

AWS Metrics
AWS metrics relevant to compute are provided by
1. Amazon ECS Metrics for clusters which monitor CPU and memory utilization across the cluster as a whole, and across the services in the clusters.
2. Amazon EC2 Metrics for compute instances which monitor CPU utilization, disk read/writes, network traffic and status checked
Amazon ECS Metrics:
CPUUtilization - The percentage of CPU units that are used in the cluster or service.
Cluster CPU utilization (metrics that are filtered by ClusterName without ServiceName) is measured as the total CPU units in use by Amazon ECS tasks on the cluster, divided by the total CPU units that were registered for all of the container instances in the cluster.
Service CPU utilization (metrics that are filtered by ClusterName and ServiceName) is measured as the total CPU units in use by the tasks that belong to the service, divided by the total number of CPU units that are reserved for the tasks that belong to the service.
Units: Percent
MemoryUtilization - The percentage of memory that is used in the cluster or service.
Cluster memory utilization (metrics that are filtered by ClusterName without ServiceName) is measured as the total memory in use by Amazon ECS tasks on the cluster, divided by the total amount of memory that was registered for all of the container instances in the cluster.
Service memory utilization (metrics that are filtered by ClusterName and ServiceName) is measured as the total memory in use by the tasks that belong to the service, divided by the total memory that is reserved for the tasks that belong to the service.
Units: Percent
Dimensions for Amazon ECS Metrics are also provided to refine the metrics returned for the Amazon ECS resources. These include:
ClusterName
This dimension filters the data requested for all resources in a specified cluster. All Amazon ECS metrics are filtered by ClusterName.
ServiceName
This dimension filters the data requested for all resources in a specified service within a specified cluster.
Amazon EC2 Metrics:
The following metrics are available from each EC2 instance.
CPUCreditUsage
(Only valid for T2 instances) The number of CPU credits consumed during the specified period.
CPUCreditBalance
(Only valid for T2 instances) The number of CPU credits that an instance has accumulated.
CPUUtilization
The percentage of allocated EC2 compute units that are currently in use on the instance. This metric identifies the processing power required to run an application upon a selected instance.
DiskReadOps
Completed read operations from all ephemeral disks available to the instance in a specified period of time.
DiskWriteOps
Completed write operations to all ephemeral disks available to the instance in a specified period of time.
DiskReadBytes
Bytes read from all ephemeral disks available to the instance
DiskWriteBytes
Bytes written to all ephemeral disks available to the instance
NetworkIn
The number of bytes received on all network interfaces by the instance.
NetworkOut
The number of bytes sent out on all network interfaces by the instance.
Dimensions for Amazon EC2 Metrics allow you to filter the EC2 instance data
These include:
ImageId : This dimension filters the data requested for all instances running this EC2 Amazon Machine Image (AMI).
InstanceId: This dimension filters the data you request for the identified instance only.
InstanceType: This dimension filters the data you request for all instances running with this specified instance type.
AWS metrics relevant to storage are provided by Amazon Simple Storage Service Dimensions:
BucketSizeBytes - The amount of data in bytes stored in a bucket in the Standard storage class or in the Reduced Redundancy Storage (RRS) class.
NumberOfObjects - The total number of objects stored in a bucket.
And the corresponding dimensions used to filter the data include:
BucketName - This dimension filters the data requested for the identified bucket only.
StorageType - This dimension filters the data you have stored in a bucket by the type of storage. The types are StandardStorage for the Standard storage class, ReducedRedundancyStorage for the Reduced Redundancy Storage (RRS) class, and AllStorageTypes.
Sample API call: http://monitoring.amazonaws.com/?SignatureVersion=2
&Action=ListMetrics
&Version=2010-08-01
&AWSAccessKeyId=< AWS Access Key Id>
&SignatureVersion=2
&SignatureMethod=HmacSHA256
&Timestamp=2010-11-17T05%3A13%3A00.000Z

Sample error response
This is specified as:
<ErrorResponse>
<Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Invalid nextToken</Message>
</Error>
<RequestId>cb1c4191-0e5d-11e2-9c15-6f306828daaa<RequestId>
</ErrorResponse>

SDK Libraries are available in Java, PHP, Python, Ruby and .NET.

Sample to get metrics
To get statistics we use the GetMetricStatistics API to get a variety of statistics though these are only available for 14 days.
Example: Call GetMetricStatistics with the following parameters to get the CPU utilization per hour for an EC2 instance for a 3-day range

MetricName = CPUUtilization
Period = 3600
Statistics list includes Maximum
Dimensions (Name=InstanceId, Value="<your-instance-id>")
Namespace = AWS/EC2
StartTime = 2011-01-09T23:18:00
EndTime = 2011-01-12T23:18:00

Sample to create alarms
To create or update an alarm, you use the PutMetricAlarm API function
To list any or all of the currently configured alarms, and list any alarms in a particular state use the DescribeAlarms API
To disable and enable alarms use the DisableAlarmActions and EnableAlarmActions APIs (mon-disable-alarm-actions and mon-enable-alarm-actions commands).
To test an alarm by setting it to any state use the SetAlarmState API (mon-set-alarm-state command)
Finally, to view an alarm's history use the DescribeAlarmHistory API (mon-describe-alarm-history command).

#codingexercise
String ReverseWordsInASentence(String sentence)
{
var words = sentence.split(' ');

var reversedSentence  = words.Aggregate((sent, next) =>  next + " " + sent);

return reversedSentence;
}

1 comment: