In this demo,
I'll be installing Prometheus and Grafana
on a DigitalOcean droplet.
When you enter the URL with the reference code right here,
you get to this page
where you enter your email address and password and sign up.
You will then also get the $100 coupon,
which is valid for 60 days
when you enter a valid payment method.
Once logged in, you will see a dashboard,
just like mine right here
and here you can then create a droplet.
You can create an Ubuntu Xenial distribution
but I am actually going to use 18.04,
which is the latest LTS.
I'm going to choose for a two-gigabyte, $10-a-month machine.
I'm going to launch it in London
but you can launch it in any region that you want.
And then you can add an SSH key.
If you know what an SSH key is
and you already have one,
you can create a new one or you can import yours.
If you do not know what an SSH key is,
you can just use password authentication
and you don't have to add an SSH key.
I already have one,
so I will just use mine.
If you don't select this,
then DigitalOcean will just email your password.
So that works as well.
I'm going to call this prometheus
and I'll add a tag and the tag will be prometheus.
I'm going to create this droplet.
And then immediately, I'm gonna go to Networking, Firewalls.
I'm going to make sure
that my Prometheus is properly protected
by adding a firewall.
So I'm gonna create a firewall.
I'm gonna call it prometheus.
And I'm going to say all TCP
but not from all IP addresses
but only from my IP address.
And to know what your IP address is,
you can go to ifconfig.co
and this will just display your IP address.
So if I add this,
then you can choose to add this as an address
and then All TCP and maybe also All UDP and ICMP.
Only to your IP address for now.
And this will make sure
that only you will be able
to access this droplet.
So we're going to apply this to prometheus
to the droplet or even to the tag.
Then everything that you tag with prometheus
will get this firewall applied.
Firewall created successfully.
So now we should be able to log in.
First, we need the IP address.
Our prometheus server is running.
We copy the IP address.
And then you can open a terminal.
On macOS X, you can just open the program terminal.
On Windows, you can use PuTTY.
And on Linux, you can also just use SSH in a terminal.
So I'm going to ssh to root at this IP address.
I'm going to use my key file.
But if you didn't set an SSH key,
then you just use the password that has been emailed to you.
I press yes.
And I'm now logged in.
So this is the Ubuntu 18.04 LTS that I'm running.
First, we need to get our Git repository.
So I'm going to git clone,
github.com/in4it.prometheus-course.
And this will create a directory, prometheus-course
and in this directory, prometheus-course,
I have the scripts.
So to install Prometheus,
I'm going to execute one of the scripts.
So we have 1-install,
which installs Prometheus,
2 installs node-exporter.
It's just going to install a piece of software
that will export the metrics
of this server so that we have some metrics in Prometheus
and we will install Grafana,
which will be showing visualizations or graphs.
So first, we start with install.sh
to install Prometheus.
Scripts/1-install.
And this will download Prometheus and then install it.
Prometheus is now installed.
Let's have a look whether it's running.
Prometheus is running,
so we should be able to go to the Prometheus web console.
So if you go to the IP address of the droplet, port 9090,
then you get to the Prometheus web front end.
So if you want to see one of the metrics,
then you can click here
and here, you have some metrics
that are already in Prometheus by default.
So for instance, if you just take a look
at scrape_samples_scraped,
I click Execute, then we see scrape_samples_scraped
localhost:9090, job equals prometheus.
These are the labels and this is the sample.
682 samples are scraped.
And we can also show this in a graph.
So here we see the samples that are scraped.
Let's have a look at Prometheus install script
that we executed.
So the PROMETHEUS_VERSION is 2.2.1.
You can change this version once newer version come out.
Then you can also use newer versions using these scripts.
First, what the script does
is it's going to get from the releases the correct version.
It's going to extract it.
It's going to cd in this directory
and actually, at this point,
you could already start Prometheus using the config file.
But first, what we are going to do
is we're going to create a user
so that Prometheus doesn't start as root but as a user.
So we're going to add the Prometheus user,
create the directories for the configuration files
and for the data.
Change ownership, copy the binaries,
change ownership after we copy the binaries as well.
Copy the config right here.
So we do a few copies
and a few ownership changes
and then we have the systemd script.
So this is going to write a systemd script
to start and stop the daemon.
So this is systemd.
So use the user prometheus
and here's the command that we use
to start Prometheus.
Then we do systemctl daemon-reload.
We enable it at boot time and then we start prometheus.
So that is the only thing that this script does.
So it's pretty generic.
It should work on any modern Linux distribution
that uses systemd.