Install Prometheus Service and Data Source

Video Lecture

Install Prometheus Service and Data Source Install Prometheus Service and Data Source

Install Prometheus Service and Data Source

Prometheus is already available on the default Ubuntu 20.04 repositories. So we can just install it and it will be set up as a service already.

sudo apt install prometheus
sudo service prometheus status

Test it by visiting http://[your domain or ip]:9090/

Restrict internet access by

iptables -A INPUT -p tcp -s localhost --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp --dport 9090 -j DROP
iptables -L

After installing Prometheues using apt, yum, dnf etc, it is also likely to have,

  • installed a local Prometheus Node Exporter,
  • created and started 2 services for Prometheus and Prometheus Node Exporter,
  • created a specific user called prometheus that both services are running under.

You can check whether a new user was created, and which processes it is running using the command

ps -u prometheus

The Prometheus Node Exporter also creates a metrics http endpoint on port 9100.

If your server is on the public internet, it may be accessible via the address http://[your domain or ip]:9100/

You can also restrict access to port 9100 using iptables

iptables -A INPUT -p tcp -s localhost --dport 9100 -j ACCEPT
iptables -A INPUT -p tcp --dport 9100 -j DROP
iptables -L

Warning

iptables settings will be lost in case of system reboot. You will need to reapply them manually,

or

install iptables-persistent

sudo apt install iptables-persistent

This will save your settings into two files called,

/etc/iptables/rules.v4

/etc/iptables/rules.v6

Any changes you make to the iptables configuration won't be auto saved to these persistent files, so if you want to update these files with any changes, then use the commands,

iptables-save > /etc/iptables/rules.v4

iptables-save > /etc/iptables/rules.v6

Prometheus Course

If you want to try a more detailed course on Prometheus, then you can visit my Prometheus tutorials.