{"id":41,"date":"2025-10-28T12:00:00","date_gmt":"2025-10-28T12:00:00","guid":{"rendered":"https:\/\/rezachegini.com\/?p=41"},"modified":"2026-10-30T06:39:34","modified_gmt":"2026-10-30T06:39:34","slug":"building-my-first-monitoring-setup-with-prometheus-on-ubuntu","status":"publish","type":"post","link":"https:\/\/rezachegini.com\/?p=41","title":{"rendered":"Building My First Monitoring Setup with Prometheus on Ubuntu"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Today I want to share what I learned about Prometheus and how it helps monitor systems and applications in real environments.<\/p>\n<p class=\"wp-block-paragraph\">Prometheus is a popular open-source system for monitoring and alerting. It collects metrics, stores them as time-series data, and provides powerful tools to analyze and visualize performance. In this article, I explain how to install Prometheus on Ubuntu step by step.<\/p>\n<h3 class=\"wp-block-heading\">What is Prometheus<\/h3>\n<p class=\"wp-block-paragraph\">Prometheus is a monitoring tool that collects metrics from systems and applications. It saves data as time series and helps you check performance, create alerts, and find issues.<\/p>\n<p class=\"wp-block-paragraph\">Main features:<\/p>\n<ul class=\"wp-block-list\"><li>Stores data in its own time-series database<\/li><li>Pulls metrics from defined targets<\/li><li>Has a query language (PromQL)<\/li><li>Includes alerting and a built-in web interface<\/li><\/ul>\n<p class=\"wp-block-paragraph\">You can use it to monitor:<\/p>\n<ul class=\"wp-block-list\"><li>Linux servers (CPU, memory, disk)<\/li><li>Containers and Kubernetes clusters<\/li><li>Databases, web apps, and APIs<\/li><\/ul>\n<h3 class=\"wp-block-heading\">System Requirements<\/h3>\n<p class=\"wp-block-paragraph\">Before you start:<\/p>\n<ul class=\"wp-block-list\"><li>Ubuntu or Debian server<\/li><li>Internet connection<\/li><li>Port 9090 open for the web UI<\/li><\/ul>\n<p class=\"wp-block-paragraph\">Prometheus runs well with:<\/p>\n<ul class=\"wp-block-list\"><li>1\u20132 CPU cores<\/li><li>1\u20132 GB of RAM<\/li><li>10 GB or more disk space<\/li><\/ul>\n<h3 class=\"wp-block-heading\">Installation Steps<\/h3>\n<h3 class=\"wp-block-heading\">1. Create a Prometheus user and directories<\/h3>\n<p class=\"wp-block-paragraph\">It&#8217;s better not to run Prometheus as root. So I created a system user and folders:<\/p>\n<pre class=\"wp-block-code\"><code>sudo groupadd --system prometheus\nsudo useradd --system -g prometheus prometheus\nsudo mkdir -p \/etc\/prometheus \/var\/lib\/prometheus<\/code><\/pre>\n<h3 class=\"wp-block-heading\">2. Download and extract Prometheus<\/h3>\n<p class=\"wp-block-paragraph\">Get the Linux AMD64 version from the official site:<\/p>\n<pre class=\"wp-block-code\"><code>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v3.5.0\/prometheus-3.5.0.linux-amd64.tar.gz\ntar xvf prometheus-3.5.0.linux-amd64.tar.gz\ncd prometheus-3.5.0.linux-amd64<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Move binaries:<\/p>\n<pre class=\"wp-block-code\"><code>sudo mv prometheus promtool \/usr\/local\/bin\/<\/code><\/pre>\n<h3 class=\"wp-block-heading\">3. Move configuration files<\/h3>\n<p class=\"wp-block-paragraph\">Prometheus comes with a default config file. Move it to the configuration folder:<\/p>\n<pre class=\"wp-block-code\"><code>sudo mv prometheus.yaml \/etc\/prometheus\/<\/code><\/pre>\n<p class=\"wp-block-paragraph\">You can also create \/etc\/prometheus\/web.yml if you plan to add authentication or HTTPS later.<\/p>\n<h3 class=\"wp-block-heading\">4. Set correct permissions<\/h3>\n<p class=\"wp-block-paragraph\">Prometheus should own its directories:<\/p>\n<pre class=\"wp-block-code\"><code>sudo chown -R prometheus:prometheus \/etc\/prometheus \/var\/lib\/prometheus<\/code><\/pre>\n<h3 class=\"wp-block-heading\">5. Create a systemd service file<\/h3>\n<p class=\"wp-block-paragraph\">This file lets Prometheus run in the background and start automatically on boot.<\/p>\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/systemd\/system\/prometheus.service<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Paste this:<\/p>\n<pre class=\"wp-block-code\"><code>[Unit]\nDescription=Prometheus Service\nDocumentation=https:\/\/prometheus.io\/docs\/introduction\/overview\/\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=prometheus\nGroup=prometheus\nExecReload=\/bin\/kill -HUP $MAINPID\nExecStart=\/usr\/local\/bin\/prometheus \\\n  --config.file=\/etc\/prometheus\/prometheus.yaml \\\n  --storage.tsdb.path=\/var\/lib\/prometheus \\\n  --web.config.file=\/etc\/prometheus\/web.yml \\\n  --web.listen-address=0.0.0.0:9090\nSyslogIdentifier=prometheus\nRestart=on-failure\nRestartSec=5s\nLimitNOFILE=65536\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Save and exit.<\/p>\n<h3 class=\"wp-block-heading\">6. Start Prometheus<\/h3>\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo systemctl enable --now prometheus<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Check if it&#8217;s running:<\/p>\n<pre class=\"wp-block-code\"><code>sudo systemctl status prometheus<\/code><\/pre>\n<p class=\"wp-block-paragraph\">You should see active (running).<\/p>\n<h3 class=\"wp-block-heading\">Verify the Installation<\/h3>\n<p class=\"wp-block-paragraph\">Open your browser and go to:<\/p>\n<pre class=\"wp-block-code\"><code>http:\/\/&lt;your-server-ip&gt;:9090<\/code><\/pre>\n<p class=\"wp-block-paragraph\">You&#8217;ll see the Prometheus web UI. In the query box, type up and click Execute. If you see a result with value 1, Prometheus is running and monitoring itself.<\/p>\n<h3 class=\"wp-block-heading\">Basic Troubleshooting<\/h3>\n<ul class=\"wp-block-list\"><li>If the page doesn&#8217;t open, check your firewall: sudo ufw allow 9090\/tcp<\/li><li>To read logs: journalctl -u prometheus -n 50<\/li><li>To restart: sudo systemctl restart prometheus<\/li><\/ul>\n<h3 class=\"wp-block-heading\">What I Learned<\/h3>\n<p class=\"wp-block-paragraph\">Setting up Prometheus manually helped me understand:<\/p>\n<ul class=\"wp-block-list\"><li>How Linux services run with systemd<\/li><li>Why non-root users improve security<\/li><li>How configuration and data folders are organized<\/li><li>The first steps of monitoring with PromQL<\/li><\/ul>\n<p class=\"wp-block-paragraph\">Now that Prometheus is running, I plan to add Node Exporter next to collect CPU, RAM, and disk metrics.<\/p>\n<h2 class=\"wp-block-heading\">Adding Node Exporter for System Metrics<\/h2>\n<p class=\"wp-block-paragraph\">Now that Prometheus is installed, I added Node Exporter to collect server metrics like CPU, memory, and disk usage.<\/p>\n<h3 class=\"wp-block-heading\">Step 1 \u2013 Download and Install Node Exporter<\/h3>\n<pre class=\"wp-block-code\"><code>cd \/tmp\nwget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v1.10.2\/node_exporter-1.10.2.linux-amd64.tar.gz\ntar xvf node_exporter-1.10.2.linux-amd64.tar.gz\ncd node_exporter-1.10.2.linux-amd64\nsudo mv node_exporter \/usr\/local\/bin\/<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Create a system user for it:<\/p>\n<pre class=\"wp-block-code\"><code>sudo useradd --system node_exporter<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Create a systemd service:<\/p>\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/systemd\/system\/node_exporter.service<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Paste this:<\/p>\n<pre class=\"wp-block-code\"><code>[Unit]\nDescription=Node Exporter\nAfter=network.target\n\n[Service]\nUser=node_exporter\nGroup=node_exporter\nType=simple\nExecStart=\/usr\/local\/bin\/node_exporter\nRestart=on-failure\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Save and start it:<\/p>\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo systemctl enable --now node_exporter<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Check the status:<\/p>\n<pre class=\"wp-block-code\"><code>sudo systemctl status node_exporter<\/code><\/pre>\n<p class=\"wp-block-paragraph\">If it&#8217;s running, open your browser:<\/p>\n<pre class=\"wp-block-code\"><code>http:\/\/&lt;server-ip&gt;:9100\/metrics<\/code><\/pre>\n<p class=\"wp-block-paragraph\">You should see text data with many system metrics.<\/p>\n<h3 class=\"wp-block-heading\">Step 2 \u2013 Add Node Exporter to prometheus.yaml<\/h3>\n<p class=\"wp-block-paragraph\">Now tell Prometheus to scrape data from Node Exporter.<\/p>\n<p class=\"wp-block-paragraph\">Edit the file:<\/p>\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/prometheus\/prometheus.yaml<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Add this under scrape_configs:<\/p>\n<pre class=\"wp-block-code\"><code>global:\n  scrape_interval: 15s\n\nscrape_configs:\n  - job_name: 'prometheus'\n    static_configs:\n      - targets: ['localhost:9090']\n\n  - job_name: 'node_exporter'\n    static_configs:\n      - targets: ['localhost:9100']<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Save and reload Prometheus:<\/p>\n<pre class=\"wp-block-code\"><code>sudo systemctl restart prometheus<\/code><\/pre>\n<h3 class=\"wp-block-heading\">Step 3 \u2013 Verify Node Exporter in Web UI<\/h3>\n<p class=\"wp-block-paragraph\">Go to:<\/p>\n<pre class=\"wp-block-code\"><code>http:\/\/&lt;server-ip&gt;:9090\/targets<\/code><\/pre>\n<p class=\"wp-block-paragraph\">You should see two targets:<\/p>\n<ul class=\"wp-block-list\"><li>prometheus<\/li><li>node_exporter<\/li><\/ul>\n<p class=\"wp-block-paragraph\">Both should be in UP state. Now Prometheus collects metrics from your system through Node Exporter.<\/p>\n<h3 class=\"wp-block-heading\">What I Learned<\/h3>\n<p class=\"wp-block-paragraph\">Through this setup I learned:<\/p>\n<ul class=\"wp-block-list\"><li>How to install Prometheus and Node Exporter manually<\/li><li>How systemd services work<\/li><li>How to edit prometheus.yaml to add scrape targets<\/li><li>How to verify metrics through the web interface<\/li><\/ul>","protected":false},"excerpt":{"rendered":"<p>Today I want to share what I learned about Prometheus and how it helps monitor systems and applications in real environments. Prometheus&hellip;<\/p>\n","protected":false},"author":2,"featured_media":43,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_rezaops_part":"1","_rezaops_linkedin_url":"https:\/\/www.linkedin.com\/pulse\/building-my-first-monitoring-setup-prometheus-ubuntu-reza-chegini-rulkc\/","footnotes":""},"categories":[10,14],"tags":[8,19,18,16,17],"series":[15],"class_list":["post-41","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-observability","tag-devops","tag-monitoring","tag-node-exporter","tag-prometheus","tag-ubuntu","series-prometheus"],"jetpack_featured_media_url":"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/10\/building-my-first-monitoring-setup-prometheus-cover.jpg","_links":{"self":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=41"}],"version-history":[{"count":1,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions\/42"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/media\/43"}],"wp:attachment":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}