Prometheus Use Cases,
Cloudwatch exporter.
So in this section,
I'll be explaining the Cloudwatch exporter,
the installation of the Cloudwatch exporter,
the configuration of the exporter,
plus everything needed in AWS.
I'm gonna talk about the charges involved,
AWS charges
0.01 US dollar
per thousand metrics requested
using the get metric data.
So keep that in mind if you keep stuff running,
or if you're cost conscious,
don't just query everything,
but just what you need.
And then we're going to query some metrics.
Hope you enjoy this Use Case.
Gonna start by SSH-ing back into our machine.
Then we're gonna go to the
Prometheus course directory,
scripts do a git pull to make sure
this repository is up to date.
As you can see, it's already up to date,
but we apply changes to this course
on a regular basis,
so make sure you do a git pull
every time you run the script.
And then we're gonna look at script six.
So what this is gonna do is
download the Cloudwatch exporter CHAR file
to install Java openjdk-9.
And it's gonna make the necessary directories,
as you can see.
Then it's gonna echo the template
for your SSH key
which I'll be explaining later on.
Then it's gonna create the system descript,
that's gonna enable the service.
And then you get a lot of instructions
that you need to perform
before you can successfully pull in metrics
from Cloudwatch.
So, all right, let's start by running it.
Now everything is installing.
All right, and now let's head over to
our AWS console and create an AWS key.
In your AWS console,
you go to services,
IAM,
and we're gonna create a new user.
So go to users, add a user,
and we're going to name it Prometheus.
Gonna give it programmatic access.
Gonna attach existing policies directly.
Gonna give it read only access to Cloudwatch.
I'm gonna review it,
I'm gonna create a user.
And now he created a user.
Make sure to download the csv
as it's containing your keys.
Now, you can also just press show here,
and copy the keys.
Let's head over to our file we just created here.
We're gonna edit it, vi that file.
We're gonna replace this and this
with the access key ID,
and the secret access key.
All right, step one is done.
So we created our AWS keys and
added them to the correct configuration file.
The Cloudwatch exporter uses the Java as the key
so default looks in this location,
but you can also use environment variables for this.
Now we're gonna add the following lines
to prometheus.yml.
So we're gonna edit etc prometheus.yml
before we press enter,
we're just gonna
copy these lines.
Go all the way to the bottom of this file,
and we add a new job called the Cloudwatch exporter.
All right, that is done.
Now, we're gonna add the following lines
to the Cloudwatch exporter configuration file.
This is just a default file to pull in
some metrics of all the amazon ELBa in the eu-west-1.
This is just as a starting example,
and we'll continue building on this file later on.
Gonna add that.
Now we gonna run systemctl start cloudwatch exporter.
We're gonna look at the status,
and it's running, great.
Now, we're also gonna
systemctl restart
Prometheus
to make sure that he has the correct
configuration file.
We also gonna do a status to make sure it started correctly.
And there you go.
And if wait a little moment,
they'll probably be pulling in the
Cloudwatch metrics as we speak.
So let's check them out.
So we head over to our Prometheus ui,
and we go to statuses and then targets.
You can see the Cloudwatch exporter
which we just added.
So, it's up and the last scrape was
4.234 seconds ago.
So great that's already working.
Let's copy this path,
and edit it.
And let's check what metrics are populated.
So as you can see here,
he's already reporting an elb
which I created for this course,
the prometheus course elb.
And the average,
so the aws_elb_healthy_host_count_average
is still one.
So there's still an instance attached to it,
you can see how many requests
you already did to the Cloudwatch API
because you can be billed for it,
if you scraping too much,
it's not that expensive,
but nevertheless, keep that in mind
if you set your scrape window,
or if you're just cost conscious,
make sure you don't query metrics
that you don't need.
All right, let's head back
to the Prometheus site.
Gonna reset the size,
then we're gonna go to graph.
So remember, we added the
aws_elb_healthy_host_count_average
which is this metric,
and let's see what it's reporting.
Okay, it's still reporting, great,
and let's graph this.
So as you can see here,
the healthy host count in eu-west-1c
is one.
So all right, we already have a metric.
The Cloudwatch exporter is working.
Let's head back to the Cloudwatch exporter,
expose some more metrics.
So now let's head back to our machine.
We're gonna edit the configuration file
for the Cloudwatch exporter.
We're gonna copy this,
and let's check what metrics are available.
So whenever you go to the
Cloudwatch documentation,
you can see what metrics are available,
for example, for the load balancer.
So in my case the latency's very important
to my product.
So let's check him out.
So we already added the healthy host count,
so let's add the latency to that.
Let's head back to our machine.
So the metric name is
Latency.
Right click the file.
So we're gonna restart the
Cloudwatch exporter.
Check it's status
to make sure we didn't make any
configuration errors.
So that's still running.
Now let's head back over to our
Prometheus console.
Status.
All right, so the Cloudwatch exporter's
still running.
Let check what metrics it's reporting.
And here you see.
So we go to aws_elb_latency_average.
Let's head back.
See if we can graph this.
So what metric was this,
it was the aws_elb average.
Let's execute it and graph it.
Here you can see there is some traffic,
and some traffic is coming in from
eu-west-1c and some is from 1b.
All right, now I'm interested in the request count.
How many people are visiting our website, for example,
or how many requests are happening
during a given time window.
So let's head back to our Prometheus machine.
Basically the same procedure.
And we're gonna add
the request count,
but this is no average,
we just wanna know how many.
So this is actually a sum.
Okay.
Let's restart the Cloudwatch exporter.
Check it's status.
Okay, it's running.
Let's head back to our machine.
Let's check if Prometheus is
already reporting this metric.
And here you go.
So we got the sum,
aws_elb_request_count_sum.
So let's check it out.
So we go to cloudwatch_requests_total.
Execute.
And here you can see we got a lot of traffic
coming in.
Okay, this is the end of this section.
I hope you have a better understanding now
of how the Cloudwatch exporter works.
Make sure to play around with it a little,
and consult the AWS documentation
to see what metrics you can pull.