Skip to content

Install Prometheus Service and Data Source

Video Lecture

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

It has installed two services named prometheus and prometheus-node-exporter. We can check them using

sudo service prometheus status


sudo service prometheus-node-exporter status

Press ctrl-c to exit each of the above status commands.

We can test the Prometheus metrics endpoint is running locally by using the command


If your server is on the public internet, it may be accessible via the address http://[your domain or IP]:9100/. If you are not using a dedicated firewall, then you can block it for external users by using these iptables rules below.

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

After installing Prometheus 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 the prometheus user using the command

id prometheus

You can check which processes it is running by using the command

ps -u prometheus

You can see which ports each process is listening on by using the command

ss -ntlp | grep prometheus

The Prometheus Node Exporter also creates a metrics HTTP endpoint on port 9100. You can check it locally using


If your server is on the public internet, and you haven't configured a dedicated firewall, it may be accessible via the address http://[your domain or IP]:9100/

You can also restrict access to port 9100 using iptables if you need.

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


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


install iptables-persistent

sudo apt install iptables-persistent

This will save your settings into two files called,



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.

IPTables Cheat Sheet

Grafana 10 and Ubuntu 22.04 Notes

To add a data source, click ConnectionsData Sources[Add Data Source] button.

ExplorePrometheusMetrics browser

In Grafana 10, when exploring the new Prometheus data source, the default view is the new Builder UI. My video shows the Code UI, where it shows the Metrics browser option.

You can view the Code UI by pressing the option at the right of the screen.

Code UI Button

Daemons using outdated libraries

Since Ubuntu 22.04, installing new packages may give you a full screen prompt to restart other dependent services. Press Tab to highlight the OK option, and press Enter.