How to Write and Archive Custom Metrics using Amazon CloudWatch with PowerShell
Think you can do better? Show us!
Hello and Welcome to this video I'm going to show you how to write and archive custom metrics. Using Amazon Cloudwatch with powershell, so they get started. Let's have a look at some of the existing metrics that we can look at. So we're going to look at the metric list available for EC 2 instances using CW metric list. So you'll see, there we have various metrics that are there by default and that we can query within cloudwatch but you may have come across a situation where you need to create a custom metric to do this is fairly straightforward so fast. We need some data that we're going to query in this case. I'm going to use the World News Subreddit and the number of active users on that group at the moment. We're going to use invoke rest method to retrieve that data then we're going to pass that into an object. metric datum we need to pass into that timestamp a metric name, which have used /r World News and then we're going to count so essentially the number of users. So if we look at the value at the moment. This 14,199 users are not separated so to write this data in use a commandlet called write CW metric data. The first option is namespace so this is an umbrella for collection of metrics. So we're going to add our users under the namespace called active users so these are most 2 important parameters or other parameters are for a profile name and the region that were working. So by executing this commandlet we're going to write one data point to cloudwatch. So if we go over to the console and then you'll see custom namespaces, then active users. And then you'll see our metric name, which is World News if we have a look up in the graph. You'll see the data point that we've just written to cloudwatch and you'll see some previous data points that I've written. So you can go into your metrics and you can change time interval that you want to look at them and you can actually view by hovering over the graph your individual data points that you sent in to cloudwatch. So next we're going to look archiving data symmetric data is stored in cloudwatch for a finite period of time, so before metrics. Each oh of cloudwatch metric data points move through a tiered system where they are aggregated and stored as less granular. Metric data So what does that mean for example, metrics gathered on a per minute period are aggregated and stored as 5 minutes metrics when they reach an age 15 days so the longest period you can store metrics include watches for 15 months. So the further that goes on. That process up to the 50 months when they remove the less granular your data will be so to retrieve our data. You can use a commandlet get CWmetricStatistic so we're going to query. Our namespace active users. We query extended statistics that value can range from zero to 100 and we pass in our metric name. We have to pass in a start time. And the end type what I've done here is looking for the last 3 years worth of data and a time period of 60. So if we run that. And you'll see the results so let's have a look and count how many data points. We've got in those results so if it's data points. So we can actually inspect the data So what I'm going to do is have a look at the last data point that we wrote and there, you'll see this value under extended is 14199. So that data you can then output to storage system or archive system of your preference. Thank you for watching this video.