DEV Community

muckitymuck
muckitymuck

Posted on • Updated on

Prometheus and Grafana

Monitoring services is a big part of Cloud Infrastructure Management. Here we will go through one way to install Prometheus on Ubuntu and make pretty dashboards with Grafana on a separate machine.

Go grab this download and extract to start:

wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz

tar -xvzf prometheus-2.11.1.linux-amd64.tar.gz

cd prometheus/

./prometheus
Enter fullscreen mode Exit fullscreen mode

Should be great success:
image

Open a web browser and head over to the http://{IP}:9090/graph
image
So far, So Good
You can see the raw metrics by going to http://{IP}:9090/metrics
image
You can check what is up by going to /targets
image

Let's run it as a service, create this file:

/etc/systemd/system/prometheus.service
Enter fullscreen mode Exit fullscreen mode

And give it this basic text settings:

[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
User=root
Restart=on-failure

#Change this line if you download the 
#Prometheus on different path user

ExecStart=~/prometheus/prometheus --storage.tsdb.path=/var/lib/prometheus/data/ --web.external-url=http://myurl.com:9090

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

Make sure to reload it and start it up:

sudo systemctl daemon-reload
sudo systemctl start prometheus
Enter fullscreen mode Exit fullscreen mode

There are Exporters you can add to Prometheus to increase the utility. Node Exporter is one.

wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar -xvzf node_exporter-0.18.1.linux-amd64.tar.gz
mv node_exporter-0.18.1.linux-amd64 node_exporter
cd node_exporter
./node_exporter
Enter fullscreen mode Exit fullscreen mode

You can open the service in a browser at http://{IP}:9100
image

You can add the node exporter to Prometheus in /etc/prometheus/prometheus.yml
image

Let's make it into a service. Create a file:

sudo vi /etc/systemd/system/node_exporter.service
Enter fullscreen mode Exit fullscreen mode
[Unit]
Description=Node Exporter
After=network.target
[Service]
User={user}
Group={user}
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

Let's go ahead and get this going:

sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl status node_exporter
Enter fullscreen mode Exit fullscreen mode

You can see the two services on /targets
image

If all is running well, enable this service to start at boot.

sudo systemctl enable node_exporter
Enter fullscreen mode Exit fullscreen mode

That's enough for today. I will continue this in a second part for Grafana.

Top comments (0)