{"id":1069,"date":"2025-07-08T07:10:41","date_gmt":"2025-07-08T07:10:41","guid":{"rendered":"https:\/\/blog.vavencloud.com\/?p=1069"},"modified":"2025-07-08T07:10:41","modified_gmt":"2025-07-08T07:10:41","slug":"setting-up-prometheus-and-grafana","status":"publish","type":"post","link":"https:\/\/blog.vavencloud.com\/?p=1069","title":{"rendered":"Setting up Prometheus and Grafana"},"content":{"rendered":"<h4 data-start=\"227\" data-end=\"253\"><strong data-start=\"230\" data-end=\"253\">What is Prometheus?<\/strong><\/h4>\n<p data-start=\"255\" data-end=\"605\">Prometheus is an open-source monitoring and alerting toolkit originally developed at SoundCloud. It is designed for reliability and scalability, ideal for collecting time-series metrics from cloud-native environments like Kubernetes or AWS. Prometheus stores data in a custom time-series database and uses a flexible query language called <strong data-start=\"594\" data-end=\"604\">PromQL<\/strong>.<\/p>\n<p data-start=\"607\" data-end=\"805\">Prometheus works by scraping metrics from targets (like EC2, Node Exporter, or containers) at specified intervals. These metrics are then stored locally and can be queried or used to trigger alerts.<\/p>\n<p data-start=\"807\" data-end=\"956\">Prometheus supports service discovery, meaning it can automatically detect and begin monitoring new services based on changes in your infrastructure.<\/p>\n<h4 data-start=\"963\" data-end=\"986\">What is Grafana?<\/h4>\n<p data-start=\"988\" data-end=\"1328\">Grafana is an open-source analytics and visualization platform that integrates seamlessly with Prometheus. It helps users create interactive and customizable dashboards to visualize metrics data. Grafana supports alerts, templating, role-based access, and can be used to monitor everything from infrastructure and logs to user applications.<\/p>\n<p data-start=\"1330\" data-end=\"1442\">Grafana doesn\u2019t collect data itself \u2014 it reads it from sources like Prometheus, InfluxDB, MySQL, Loki, and more.<\/p>\n<h4 data-start=\"1449\" data-end=\"1496\"><strong data-start=\"1452\" data-end=\"1496\">How Prometheus and Grafana Work Together<\/strong><\/h4>\n<ul data-start=\"1498\" data-end=\"1765\">\n<li data-start=\"1498\" data-end=\"1576\">\n<p data-start=\"1500\" data-end=\"1576\"><strong data-start=\"1500\" data-end=\"1514\">Prometheus<\/strong> collects and stores metrics from services and infrastructure.<\/p>\n<\/li>\n<li data-start=\"1577\" data-end=\"1657\">\n<p data-start=\"1579\" data-end=\"1657\"><strong data-start=\"1579\" data-end=\"1590\">Grafana<\/strong> reads these metrics via Prometheus\u2019s HTTP API and visualizes them.<\/p>\n<\/li>\n<li data-start=\"1658\" data-end=\"1765\">\n<p data-start=\"1660\" data-end=\"1765\">This combination provides real-time monitoring, alerting, and visual dashboards for DevOps and SRE teams.<\/p>\n<p><strong data-start=\"1775\" data-end=\"1820\">Install Prometheus and Grafana on AWS EC2<\/strong><\/p>\n<\/li>\n<li data-start=\"1658\" data-end=\"1765\">You can set up Prometheus and Grafana on your EC2 instance in just a few steps.<br \/>\n<h4 data-start=\"1908\" data-end=\"1934\">Install Prometheus<\/h4>\n<pre># Amazon Linux 2\nsudo yum update -y\n\n# Ubuntu\nsudo apt-get update<\/pre>\n<\/li>\n<li data-start=\"1658\" data-end=\"1765\">2. Create a Prometheus user and folders\n<pre>sudo useradd --no-create-home --shell \/bin\/false prometheus\n\nsudo mkdir \/etc\/prometheus \/var\/lib\/prometheus<\/pre>\n<\/li>\n<li data-start=\"1658\" data-end=\"1765\">3. Download and install Prometheus\n<pre>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.34.0\/prometheus-2.34.0.linux-amd64.tar.gz\ntar -xvzf prometheus-2.34.0.linux-amd64.tar.gz\ncd prometheus-2.34.0.linux-amd64\n\nsudo cp prometheus promtool \/usr\/local\/bin\/\nsudo cp -r consoles console_libraries \/etc\/prometheus\nsudo cp prometheus.yml \/etc\/prometheus\nsudo chown -R prometheus:prometheus \/etc\/prometheus \/var\/lib\/prometheus<\/pre>\n<p>4. Create systemd service file<\/p>\n<pre>sudo vim \/etc\/systemd\/system\/prometheus.service<\/pre>\n<\/li>\n<li data-start=\"1658\" data-end=\"1765\">Paste the following:\n<pre>[Unit]\nDescription=Prometheus\nAfter=network.target\n\n[Service]\nUser=prometheus\nExecStart=\/usr\/local\/bin\/prometheus \\\n--config.file=\/etc\/prometheus\/prometheus.yml \\\n--storage.tsdb.path=\/var\/lib\/prometheus\/\nRestart=always\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n<p>5. Start Prometheus<\/p>\n<pre>sudo systemctl daemon-reexec\n\nsudo systemctl enable prometheus\n\nsudo systemctl start prometheus<\/pre>\n<\/li>\n<li data-start=\"1658\" data-end=\"1765\">Prometheus will run on port <code data-start=\"3245\" data-end=\"3251\">9090<\/code><br data-start=\"3251\" data-end=\"3254\" \/>Check by visiting:<br data-start=\"3272\" data-end=\"3275\" \/>\n<pre><code data-start=\"3275\" data-end=\"3309\">http:\/\/&lt;your-ec2-public-ip&gt;:9090<\/code><\/pre>\n<\/li>\n<li data-start=\"1658\" data-end=\"1765\">\n<h6 data-start=\"3316\" data-end=\"3339\">Install Grafana<br \/>\n<strong>ubuntu<\/strong><\/h6>\n<pre data-start=\"3341\" data-end=\"3364\">sudo apt-get install -y software-properties-common\nsudo add-apt-repository \"deb https:\/\/packages.grafana.com\/oss\/deb stable main\"\nsudo apt-get update\nsudo apt-get install grafana<\/pre>\n<p>Amazon Linux 2<\/p>\n<pre>sudo yum install -y https:\/\/dl.grafana.com\/oss\/release\/grafana-8.3.0-1.x86_64.rpm<\/pre>\n<p>Start Grafana<\/p>\n<pre>sudo systemctl enable grafana-server\n\nsudo systemctl start grafana-server<\/pre>\n<p>Grafana will run on port <code data-start=\"3802\" data-end=\"3808\">3000<\/code><br data-start=\"3808\" data-end=\"3811\" \/>Access it via:<br data-start=\"3825\" data-end=\"3828\" \/><\/p>\n<pre><code data-start=\"3828\" data-end=\"3862\">http:\/\/&lt;your-ec2-public-ip&gt;:3000<\/code><\/pre>\n<h5 data-start=\"3869\" data-end=\"3893\"><strong data-start=\"3873\" data-end=\"3893\">Login to Grafana<\/strong><\/h5>\n<ul data-start=\"3895\" data-end=\"3972\">\n<li data-start=\"3895\" data-end=\"3916\">\n<p data-start=\"3897\" data-end=\"3916\">Username: <code data-start=\"3907\" data-end=\"3914\">admin<\/code><\/p>\n<\/li>\n<li data-start=\"3917\" data-end=\"3972\">\n<p data-start=\"3919\" data-end=\"3972\">Password: <code data-start=\"3929\" data-end=\"3936\">admin<\/code> (you will be prompted to change it)<\/p>\n<\/li>\n<\/ul>\n<h5 data-start=\"3979\" data-end=\"4029\"><strong data-start=\"3983\" data-end=\"4029\">Add Prometheus as a Data Source in Grafana<\/strong><\/h5>\n<ol data-start=\"4031\" data-end=\"4139\">\n<li data-start=\"4031\" data-end=\"4094\">\n<p data-start=\"4034\" data-end=\"4094\">Click the <strong data-start=\"4044\" data-end=\"4057\">gear icon<\/strong> in the left menu \u2192 <strong data-start=\"4077\" data-end=\"4093\">Data Sources<\/strong>.<\/p>\n<\/li>\n<li data-start=\"4095\" data-end=\"4120\">\n<p data-start=\"4098\" data-end=\"4120\">Select <strong data-start=\"4105\" data-end=\"4119\">Prometheus<\/strong>.<\/p>\n<\/li>\n<li data-start=\"4121\" data-end=\"4139\">\n<p data-start=\"4124\" data-end=\"4139\">Set the URL to:<br \/>\nhttp:\/\/&lt;your-ec2-public-ip&gt;:9090<\/p>\n<\/li>\n<li data-start=\"4121\" data-end=\"4139\">Click <strong data-start=\"4190\" data-end=\"4205\">Save &amp; Test<\/strong> to verify the connection.<br \/>\n<h5>Using Node Exporter for System Metrics<\/h5>\n<p data-start=\"4511\" data-end=\"4574\">To monitor EC2-level system metrics like CPU, disk, and memory:<\/p>\n<ol data-start=\"4576\" data-end=\"4618\">\n<li data-start=\"4576\" data-end=\"4618\">\n<pre data-start=\"4579\" data-end=\"4618\">Download and install <strong data-start=\"4600\" data-end=\"4617\">Node Exporter<\/strong>:\n\nwget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v1.5.0\/node_exporter-1.5.0.linux-amd64.tar.gz\ntar -xvzf node_exporter-1.5.0.linux-amd64.tar.gz\ncd node_exporter-1.5.0.linux-amd64\n.\/node_exporter\n\n<\/pre>\n<\/li>\n<\/ol>\n<p>2. Update\u00a0 prometheus.yml<\/p>\n<pre>scrape_configs:\n\n- job_name: 'node'\n\nstatic_configs:\n\n- targets: ['localhost:9100']<\/pre>\n<\/li>\n<\/ol>\n<p>3. Restart Prometheus to load changes:<\/p>\n<pre>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0sudo systemctl restart prometheus<\/pre>\n<\/li>\n<\/ul>\n<h4 data-start=\"5070\" data-end=\"5087\"><strong data-start=\"5073\" data-end=\"5087\">Conclusion<\/strong><\/h4>\n<p data-start=\"5089\" data-end=\"5408\">Prometheus and Grafana together form a powerful, open-source monitoring and visualization stack. Setting them up on AWS EC2 gives you full control of your metrics and dashboards. Whether you&#8217;re monitoring applications, infrastructure, or containers, this setup gives you the tools to ensure performance and reliability.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Prometheus? Prometheus is an open-source monitoring and alerting toolkit originally developed at SoundCloud. It is designed for reliability and scalability, ideal for collecting time-series metrics from cloud-native environments like Kubernetes or AWS. Prometheus stores data in a custom time-series database and uses a flexible query language called PromQL. Prometheus works by scraping metrics [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1070,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-1069","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci-cd-monitoring"],"_links":{"self":[{"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=\/wp\/v2\/posts\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1069"}],"version-history":[{"count":0,"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=\/wp\/v2\/posts\/1069\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vavencloud.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}