{"id":65175,"date":"2024-09-15T15:03:40","date_gmt":"2024-09-15T09:33:40","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=65175"},"modified":"2026-04-08T12:49:49","modified_gmt":"2026-04-08T07:19:49","slug":"step-by-step-setup-grafana-and-prometheus-monitoring-using-node-exporter","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/step-by-step-setup-grafana-and-prometheus-monitoring-using-node-exporter\/","title":{"rendered":"Step-by-Step Setup: Grafana and Prometheus Monitoring using Node Exporter"},"content":{"rendered":"<h2><span style=\"color: #000000;\">Introduction<\/span><\/h2>\n<p><span style=\"color: #000000;\">Monitoring is a crucial aspect of managing cloud environments, ensuring that you can track the health, performance, and reliability of your infrastructure. Prometheus and Grafana are powerful tools commonly used for monitoring and visualization. Prometheus excels at collecting and querying metrics, while Grafana provides an interface for visualizing this data through customizable dashboards.<\/span><\/p>\n<p><span style=\"color: #000000;\">Using AWS EC2 to host these tools offers flexibility and scalability, making it an ideal choice for setting up a robust monitoring solution.<\/span><\/p>\n<h2><span style=\"color: #000000;\">Prerequisites<\/span><\/h2>\n<p><span style=\"color: #000000;\">Before diving into the setup, ensure you have the following:<\/span><\/p>\n<ul>\n<li><span style=\"color: #000000;\"><strong>AWS EC2 Instance:<\/strong> An active AWS account and an EC2 instance running Amazon Linux 2.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Basic Knowledge:<\/strong> Familiarity with Linux commands and basic AWS services.<\/span><\/li>\n<li><span style=\"color: #000000;\"><span style=\"color: #000000;\"><strong>Tools Needed:<\/strong> An SSH client to connect to your EC2 instance and AWS CLI for managing AWS resources.<br \/>\n<\/span>Note: This blog is based on the setup of Grafana and Prometheus on Amazon Linux 2, you can also use other OS versions as per your needs.<\/span><\/li>\n<\/ul>\n<h2><span style=\"color: #000000;\">Setting Up the EC2 Instance<\/span><\/h2>\n<h3><span style=\"color: #000000;\">Launching an EC2 Instance:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Log in to your AWS Console<\/strong> and navigate to the EC2 dashboard.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Launch a new instance<\/strong> by selecting &#8220;Launch Instance.&#8221;<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Choose Amazon Linux 2 as the Amazon Machine Image (AMI).<\/strong><\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Select an Instance Type:<\/strong> T2.small is sufficient for basic monitoring needs or if you want you can go for higher instance type.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Configure Security Groups:<\/strong> Allow inbound traffic for SSH (port 22), HTTP (port 80), HTTPS (port 443), and custom ports for Prometheus (9090) and Grafana (3000).<br \/>\n<\/span><\/p>\n<div id=\"attachment_65200\" style=\"width: 830px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65200\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65200\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-32-34.png\" alt=\"Security Group\" width=\"820\" height=\"475\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-32-34.png 1560w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-32-34-300x174.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-32-34-1024x593.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-32-34-768x445.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-32-34-1536x890.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-32-34-624x362.png 624w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><p id=\"caption-attachment-65200\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Security Group<\/span><\/p><\/div>\n<p>&nbsp;<\/li>\n<li><span style=\"color: #000000;\"><strong>Launch the Instance<\/strong> and download the key pair for SSH access.<\/span><\/li>\n<\/ol>\n<h3><span style=\"color: #000000;\">Connecting to the Instance:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>SSH into your EC2 instance<\/strong> using the downloaded key pair:<\/span>\n<pre><span style=\"color: #000000;\"><code>ssh -i your-key.pem ec2-user@your-ec2-public-ip<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Update the package list and install essential packages:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo yum update -y\r\nsudo yum install git wget -y<\/code><\/span><\/pre>\n<\/li>\n<\/ol>\n<h2><span style=\"color: #000000;\">Installing and Configuring Prometheus on Amazon Linux 2<\/span><\/h2>\n<h3><span style=\"color: #000000;\">Step-by-Step Installation of Prometheus:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Create a system user for Prometheus:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo useradd --no-create-home --shell \/bin\/false prometheus<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Create directories for Prometheus configuration and data:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo mkdir \/etc\/prometheus\r\nsudo mkdir \/var\/lib\/prometheus<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Set the ownership of the data directory:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo chown prometheus:prometheus \/var\/lib\/prometheus<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Move to the \/tmp directory:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>cd \/tmp\/<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Download Prometheus:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.31.1\/prometheus-2.31.1.linux-amd64.tar.gz<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Extract the downloaded Prometheus package:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>tar -xvf prometheus-2.31.1.linux-amd64.tar.gz<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Move to the extracted directory:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>cd prometheus-2.31.1.linux-amd64<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Move configuration files and set ownership:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo mv console* \/etc\/prometheus\r\nsudo mv prometheus.yml \/etc\/prometheus\r\nsudo chown -R prometheus:prometheus \/etc\/prometheus<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Move binaries and set ownership:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo mv prometheus \/usr\/local\/bin\/\r\nsudo chown prometheus:prometheus \/usr\/local\/bin\/prometheus<\/code><\/span><\/pre>\n<\/li>\n<\/ol>\n<h3><span style=\"color: #000000;\">Creating Prometheus Systemd Service:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Create a systemd service file for Prometheus:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo nano \/etc\/systemd\/system\/prometheus.service<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Add the following content:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>[Unit]\r\nDescription=Prometheus\r\nWants=network-online.target\r\nAfter=network-online.target\r\n\r\n[Service]\r\nUser=prometheus\r\nGroup=prometheus\r\nType=simple\r\nExecStart=\/usr\/local\/bin\/prometheus \\\r\n    --config.file \/etc\/prometheus\/prometheus.yml \\\r\n    --storage.tsdb.path \/var\/lib\/prometheus\/ \\\r\n    --web.console.templates=\/etc\/prometheus\/consoles \\\r\n    --web.console.libraries=\/etc\/prometheus\/console_libraries\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/code><\/span><\/pre>\n<p><div id=\"attachment_65204\" style=\"width: 669px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65204\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65204\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-48-03.png\" alt=\"Prometheus Service\" width=\"659\" height=\"455\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-48-03.png 812w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-48-03-300x207.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-48-03-768x531.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-48-03-624x431.png 624w\" sizes=\"(max-width: 659px) 100vw, 659px\" \/><p id=\"caption-attachment-65204\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Prometheus Service<\/span><\/p><\/div><\/li>\n<li><span style=\"color: #000000;\"><strong>Reload systemd to apply the new service:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl daemon-reload<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Enable and start Prometheus service:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl enable prometheus\r\nsudo systemctl start prometheus<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><b>Check if the Prometheus Service is running<\/b><\/span>\n<pre><span style=\"color: #000000;\">sudo systemctl status prometheus<\/span><\/pre>\n<\/li>\n<\/ol>\n<div id=\"attachment_65205\" style=\"width: 1356px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65205\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65205\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-51-13.png\" alt=\"Prometheus Status\" width=\"1346\" height=\"337\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-51-13.png 1920w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-51-13-300x75.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-51-13-1024x257.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-51-13-768x193.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-51-13-1536x386.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-51-13-624x157.png 624w\" sizes=\"(max-width: 1346px) 100vw, 1346px\" \/><p id=\"caption-attachment-65205\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Prometheus Status<\/span><\/p><\/div>\n<h3><span style=\"color: #000000;\"><br \/>\nTesting Prometheus:<\/span><\/h3>\n<p><span style=\"color: #000000;\"><strong>Access Prometheus UI:<\/strong> Open your browser and go to <code>http:\/\/your-ec2-public-ip:9090<\/code> to verify that Prometheus is running.<br \/>\n<\/span><\/p>\n<div id=\"attachment_65206\" style=\"width: 933px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65206\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65206\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-53-47.png\" alt=\"http:\/\/your-ec2-public-ip:9090\" width=\"923\" height=\"374\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-53-47.png 1116w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-53-47-300x122.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-53-47-1024x415.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-53-47-768x311.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-13-53-47-624x253.png 624w\" sizes=\"(max-width: 923px) 100vw, 923px\" \/><p id=\"caption-attachment-65206\" class=\"wp-caption-text\"><span style=\"color: #000000;\">http:\/\/your-ec2-public-ip:9090<\/span><\/p><\/div>\n<h3><span style=\"color: #000000;\">Step-by-Step Installation of Node Exporter:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Go to the Prometheus download page:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>http:\/\/prometheus.io\/download<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Copy the Node Exporter download link:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>wget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v1.5.0\/node_exporter-1.5.0.linux-amd64.tar.gz<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Extract the downloaded file:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>tar xvf node_exporter-1.5.0.linux-amd64.tar.gz<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Move into the extracted Node Exporter directory:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>cd node_exporter-1.5.0.linux-amd64\/<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Start Node Exporter by running the executable:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>.\/node_exporter<\/code><\/span><\/pre>\n<p><span style=\"color: #000000;\">You will see Node Exporter listening on port 9100.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Check if Node Exporter is running:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>curl localhost:9100\/metrics<\/code><\/span><\/pre>\n<div id=\"attachment_65211\" style=\"width: 697px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65211\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65211\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-21-19.png\" alt=\"curl localhost:9100\/metrics\" width=\"687\" height=\"639\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-21-19.png 1106w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-21-19-300x279.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-21-19-1024x952.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-21-19-768x714.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-21-19-624x580.png 624w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><p id=\"caption-attachment-65211\" class=\"wp-caption-text\">curl localhost:9100\/metrics<\/p><\/div>\n<p><span style=\"color: #000000;\"><br \/>\nAlternatively, visit <code>http:\/\/your-ec2-public-ip:9100\/metrics<\/code> from a browser.<\/span><\/li>\n<\/ol>\n<h3><span style=\"color: #000000;\">Setting Up Node Exporter as a Service:<\/span><\/h3>\n<p><span style=\"color: #000000;\">To ensure that Node Exporter runs as a background service and starts automatically on reboot, follow the steps below:<\/span><\/p>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Copy Node Exporter binary to \/usr\/local\/bin:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo cp node_exporter \/usr\/local\/bin<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Create a system user for Node Exporter:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo useradd node_exporter --no-create-home --shell \/bin\/false<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Change ownership of the Node Exporter binary:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo chown node_exporter:node_exporter \/usr\/local\/bin\/node_exporter<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Create a systemd service file for Node Exporter:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo nano \/etc\/systemd\/system\/node_exporter.service<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Add the following content to the service file:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>[Unit]\r\nDescription=Node Exporter\r\nWants=network-online.target\r\nAfter=network-online.target\r\n\r\n[Service]\r\nUser=node_exporter\r\nGroup=node_exporter\r\nType=simple\r\nExecStart=\/usr\/local\/bin\/node_exporter\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Reload systemd:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl daemon-reload<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Start and enable Node Exporter as a service:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl start node_exporter\r\nsudo systemctl enable node_exporter<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Check the status of the Node Exporter service:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl status node_exporter<\/code><\/span><\/pre>\n<\/li>\n<\/ol>\n<h2><span style=\"color: #000000;\">Adding Targets in prometheus.yml<\/span><\/h2>\n<h3><span style=\"color: #000000;\">Configuring Prometheus to Scrape Node Exporter Metrics-<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Edit the prometheus.yml file:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo nano \/etc\/prometheus\/prometheus.yml<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Add the Node Exporter targets under scrape_configs:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>scrape_configs:\r\n  - job_name: 'node_exporter'\r\n    static_configs:\r\n      - targets: ['localhost:9100']<\/code><\/span><\/pre>\n<div id=\"attachment_65217\" style=\"width: 911px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65217\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65217\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-36-47.png\" alt=\"prometheus.yml\" width=\"901\" height=\"610\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-36-47.png 1111w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-36-47-300x203.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-36-47-1024x693.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-36-47-768x520.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-36-47-624x422.png 624w\" sizes=\"(max-width: 901px) 100vw, 901px\" \/><p id=\"caption-attachment-65217\" class=\"wp-caption-text\">prometheus.yml<\/p><\/div>\n<p><span style=\"color: #000000;\"><br \/>\nNote: Replace <code>localhost:9100<\/code> with the actual IP and port if you are scraping multiple EC2 instances and allow port on instances for Prometheus. So, that the metrics can be scarped by Prometheus.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Restart Prometheus to apply the changes:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl restart prometheus\r\n<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Verify targets in Prometheus UI:<\/strong><\/span><br \/>\n<span style=\"color: #000000;\"><span style=\"color: #000000;\"><span style=\"color: #000000;\"><span style=\"color: #000000;\">visit http:\/\/your-ec2-public-ip:9090\/targets from a browser.<\/span><\/span><\/span><\/span><\/p>\n<p><div id=\"attachment_65218\" style=\"width: 729px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65218\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65218\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-41-37.png\" alt=\"http:\/\/your-ec2-public-ip:9090\/targets\" width=\"719\" height=\"328\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-41-37.png 798w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-41-37-300x137.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-41-37-768x350.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-05-14-41-37-624x285.png 624w\" sizes=\"(max-width: 719px) 100vw, 719px\" \/><p id=\"caption-attachment-65218\" class=\"wp-caption-text\">http:\/\/your-ec2-public-ip:9090\/targets<\/p><\/div><\/li>\n<\/ol>\n<h2><span style=\"color: #000000;\">Installing and Configuring Grafana<\/span><\/h2>\n<h3><span style=\"color: #000000;\">Setting Up Grafana:<\/span><\/h3>\n<p><span style=\"color: #000000;\">We will first add the Grafana repository so that the system knows where to retrieve it:<\/span><\/p>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Create a repository file for Grafana:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo nano \/etc\/yum.repos.d\/grafana.repo<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Add the following content to the repository file:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>[grafana]\r\nname=grafana\r\nbaseurl=https:\/\/packages.grafana.com\/oss\/rpm\r\nrepo_gpgcheck=1\r\nenabled=1\r\ngpgcheck=1\r\ngpgkey=https:\/\/packages.grafana.com\/gpg.key\r\nsslverify=1\r\nsslcacert=\/etc\/pki\/tls\/certs\/ca-bundle.crt<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Install Grafana:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo yum install grafana -y<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Reload the systemd manager configuration:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl daemon-reload<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Start the Grafana server:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl start grafana-server<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Check the status of the Grafana service:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl status grafana-server<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Enable Grafana to start on boot:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl enable grafana-server.service<\/code><\/span><\/pre>\n<\/li>\n<\/ol>\n<h3><span style=\"color: #000000;\">Testing Grafana:<\/span><\/h3>\n<p><span style=\"color: #000000;\">To test Grafana, open your browser and visit your EC2 instance\u2019s public IP followed by <code>:3000<\/code> (e.g., <code>http:\/\/your-ec2-public-ip:3000<\/code>).<\/span><\/p>\n<div id=\"attachment_65256\" style=\"width: 1006px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65256\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65256\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-03-51-53.png\" alt=\"http:\/\/your-ec2-public-ip:3000\" width=\"996\" height=\"538\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-03-51-53.png 1629w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-03-51-53-300x162.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-03-51-53-1024x553.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-03-51-53-768x415.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-03-51-53-1536x830.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-03-51-53-624x337.png 624w\" sizes=\"(max-width: 996px) 100vw, 996px\" \/><p id=\"caption-attachment-65256\" class=\"wp-caption-text\">http:\/\/your-ec2-public-ip:3000<\/p><\/div>\n<p><span style=\"color: #000000;\">Log in with the default credentials: <strong>Username: admin<\/strong> and <strong>Password: admin<\/strong>. You will be prompted to set a new password.<\/span><\/p>\n<h3><span style=\"color: #000000;\">Installing and Configuring Nginx:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Install Nginx on your EC2 instance:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo yum install nginx -y<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Obtain an SSL certificate:<\/strong> Use Let&#8217;s Encrypt for a free SSL certificate.<\/span>\n<ul>\n<li><span style=\"color: #000000;\"><strong>Install Certbot:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo yum install certbot python3-certbot-nginx -y<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Request an SSL certificate:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo certbot --nginx -d your-domain.com -d www.your-domain.com<\/code><\/span><\/pre>\n<\/li>\n<li><span style=\"color: #000000;\"><span style=\"color: #000000;\">Follow the prompts to complete the SSL setup.<\/span><\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Configure Nginx to redirect HTTP to HTTPS and proxy traffic to Grafana:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo nano \/etc\/nginx\/nginx.conf<\/code><\/span><\/pre>\n<p><span style=\"color: #000000;\">Add the following server block:<\/span><\/p>\n<pre><span style=\"color: #000000;\"><code>server {\r\n    listen 80;\r\n    server_name your-domain.com www.your-domain.com;\r\n    return 301 https:\/\/$host$request_uri;\r\n}\r\n\r\nserver {\r\n    listen 443 ssl;\r\n    server_name your-domain.com www.your-domain.com;\r\n\r\n    ssl_certificate \/etc\/letsencrypt\/live\/your-domain.com\/fullchain.pem;\r\n    ssl_certificate_key \/etc\/letsencrypt\/live\/your-domain.com\/privkey.pem;\r\n\r\n    location \/ {\r\n        proxy_pass http:\/\/localhost:3000;\r\n        proxy_set_header Host $host;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n        proxy_set_header X-Forwarded-Proto $scheme;\r\n    }\r\n}<\/code><\/span><\/pre>\n<p><div id=\"attachment_65303\" style=\"width: 760px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65303\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65303\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/nginx.conf_.jpg\" alt=\"nginx.conf\" width=\"750\" height=\"401\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/nginx.conf_.jpg 1027w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/nginx.conf_-300x160.jpg 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/nginx.conf_-1024x547.jpg 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/nginx.conf_-768x411.jpg 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/nginx.conf_-624x334.jpg 624w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><p id=\"caption-attachment-65303\" class=\"wp-caption-text\">nginx.conf<\/p><\/div><\/li>\n<li><span style=\"color: #000000;\"><strong>Restart Nginx to apply the changes:<\/strong><\/span>\n<pre><span style=\"color: #000000;\"><code>sudo systemctl restart nginx<\/code><\/span><\/pre>\n<\/li>\n<\/ol>\n<h2><span style=\"color: #000000;\">Adding a DNS Entry on Route 53<\/span><\/h2>\n<h3><span style=\"color: #000000;\">Setting Up Route 53:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Navigate to Route 53 in the AWS Management Console.<\/strong><\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Create a new hosted zone<\/strong> for your domain if you haven\u2019t already.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Add an A Record:<\/strong><\/span>\n<ul>\n<li><span style=\"color: #000000;\">Choose your hosted zone and click &#8220;Create Record.&#8221;<\/span><\/li>\n<li><span style=\"color: #000000;\">Set the record type to <strong>A \u2013 IPv4 address<\/strong>.<\/span><\/li>\n<li><span style=\"color: #000000;\">Enter your domain name and the public IP of your EC2 instance.<\/span><\/li>\n<li><span style=\"color: #000000;\">Enable &#8220;Alias&#8221; if you&#8217;re using an AWS Load Balancer (optional).<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Save the Record<\/strong> and wait for DNS propagation.<\/span><\/li>\n<\/ol>\n<h2><span style=\"color: #000000;\">Creating and Customizing Dashboards<\/span><\/h2>\n<h3><span style=\"color: #000000;\">Connecting Prometheus Data Source:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Add Prometheus as a data source in Grafana:<\/strong><\/span>\n<ul>\n<li><span style=\"color: #000000;\">Navigate to <strong>Configuration &gt; Data Sources &gt; Add data source<\/strong>.<\/span><\/li>\n<li><span style=\"color: #000000;\">Choose Prometheus and set the URL to <code>http:\/\/localhost:9090<\/code>.<\/span><\/li>\n<li><span style=\"color: #000000;\">Click <strong>Save &amp; Test<\/strong> to ensure the connection works.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<div id=\"attachment_65258\" style=\"width: 893px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65258\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65258\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/screenshot.png\" alt=\"connection works.\" width=\"883\" height=\"500\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/screenshot.png 1920w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/screenshot-300x170.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/screenshot-1024x580.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/screenshot-768x435.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/screenshot-1536x870.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/screenshot-624x354.png 624w\" sizes=\"(max-width: 883px) 100vw, 883px\" \/><p id=\"caption-attachment-65258\" class=\"wp-caption-text\">connection works.<\/p><\/div>\n<h3><span style=\"color: #000000;\"><br \/>\nCreating Dashboards:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Create a new dashboard:<\/strong><\/span>\n<ul>\n<li><span style=\"color: #000000;\">Go to <strong>Create &gt; Dashboard &gt; Add New Panel<\/strong>.<\/span><\/li>\n<li><span style=\"color: #000000;\">Select Prometheus as the data source and write queries to monitor CPU, memory, and disk usage.<\/span><\/li>\n<li><span style=\"color: #000000;\"><span style=\"color: #000000;\"><span style=\"color: #000000;\"><span style=\"color: #000000;\">Customize panels with various visualization options or import pre-build dashboard&#8217;s from <a href=\"https:\/\/grafana.com\/grafana\/dashboards\/\">https:\/\/grafana.com\/grafana\/dashboards\/<\/a><\/span><\/span><\/span><\/span>\n<div id=\"attachment_65305\" style=\"width: 988px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65305\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65305\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-52-21.png\" alt=\"http:\/\/your-ec2-public-ip:3000\/dashboard\/import\" width=\"978\" height=\"571\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-52-21.png 1391w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-52-21-300x175.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-52-21-1024x598.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-52-21-768x448.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-52-21-624x364.png 624w\" sizes=\"(max-width: 978px) 100vw, 978px\" \/><p id=\"caption-attachment-65305\" class=\"wp-caption-text\">http:\/\/your-ec2-public-ip:3000\/dashboard\/import<\/p><\/div>\n<p><span style=\"color: #000000;\">Below is the Node Exporter Full Dashboard with ID &#8211; 1860, imported from Grafana&#8217;s website<\/span> (<a href=\"https:\/\/grafana.com\/grafana\/dashboards\/\">https:\/\/grafana.com\/grafana\/dashboards\/<\/a>).<br \/>\n<span style=\"color: #000000;\">Link of the Dashboard &#8211;<\/span> <a href=\"https:\/\/grafana.com\/grafana\/dashboards\/1860-node-exporter-full\/\">https:\/\/grafana.com\/grafana\/dashboards\/1860-node-exporter-full\/<\/a><\/p>\n<p><div id=\"attachment_65306\" style=\"width: 1133px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-65306\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-65306\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-55-26.png\" alt=\"Noe Exporter Full\" width=\"1123\" height=\"622\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-55-26.png 1901w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-55-26-300x166.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-55-26-1024x567.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-55-26-768x425.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-55-26-1536x851.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-20-55-26-624x346.png 624w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><p id=\"caption-attachment-65306\" class=\"wp-caption-text\">Noe Exporter Full<\/p><\/div><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><span style=\"color: #000000;\">Setting Up Alerts in Grafana:<\/span><\/h3>\n<ol>\n<li><span style=\"color: #000000;\"><strong>Create an alert rule:<\/strong><\/span>\n<ul>\n<li><span style=\"color: #000000;\">Navigate to a dashboard in the\u00a0Dashboards\u00a0section.<\/span><\/li>\n<li><span style=\"color: #000000;\">In the top right corner of the panel, click on the three dots (ellipses).<\/span><\/li>\n<li><span style=\"color: #000000;\">From the dropdown menu, select More\u2026 and then choose New alert rule.<img decoding=\"async\" loading=\"lazy\" class=\"wp-image-65307 aligncenter\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-21-02-52.png\" alt=\"Alerts\" width=\"855\" height=\"646\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-21-02-52.png 1389w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-21-02-52-300x227.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-21-02-52-1024x773.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-21-02-52-768x580.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/09\/Screenshot-from-2024-09-06-21-02-52-624x471.png 624w\" sizes=\"(max-width: 855px) 100vw, 855px\" \/><\/span><\/li>\n<li><span style=\"color: #000000;\">Define the conditions (e.g., trigger an alert when CPU usage exceeds 80%).<\/span><\/li>\n<li><span style=\"color: #000000;\">Set up the evaluation interval (how frequently the alert should be checked).<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"color: #000000;\"><strong>Configure alert notifications:<\/strong><\/span>\n<ul>\n<li><span style=\"color: #000000;\"><strong>Define Contact Points:<\/strong> Set up your contact points, which are integrations (e.g., email, Slack) to deliver notifications.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Create a Notification Policy:<\/strong> Define a notification policy to set rules for routing alerts to your contact points. In this policy, decide when and where alerts should be sent based on their importance or criteria.<\/span><\/li>\n<li><span style=\"color: #000000;\"><strong>Add Notification Templates (Optional):<\/strong> Use templates to create consistent messaging for your notifications across different contact points.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><span style=\"color: #000000;\">Conclusion<\/span><\/h2>\n<p><span style=\"color: #000000;\">Setting up monitoring with Grafana and Prometheus on an AWS EC2 instance, secured with Nginx and integrated with Route 53 for DNS management, provides a scalable and flexible solution for tracking the health and performance of your infrastructure. This guide walked you through the setup process, from launching an EC2 instance to configuring Prometheus and Grafana, installing Node Exporter, setting up Nginx for SSL termination, configuring alerts in Grafana, and securing your setup. With these tools in place, you can gain valuable insights into your system\u2019s performance and be alerted to any issues before they become critical.<\/span><\/p>\n<p>Observability stacks like Grafana and Prometheus are no longer optional \u2014 they are foundational to running reliable digital products in production. Embedding monitoring and alerting from the start is a key practice in <a href=\"https:\/\/www.tothenew.com\/services\/product-engineering\"><strong>product engineering services<\/strong><\/a>, ensuring issues are caught before they impact users.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Monitoring is a crucial aspect of managing cloud environments, ensuring that you can track the health, performance, and reliability of your infrastructure. Prometheus and Grafana are powerful tools commonly used for monitoring and visualization. Prometheus excels at collecting and querying metrics, while Grafana provides an interface for visualizing this data through customizable dashboards. Using [&hellip;]<\/p>\n","protected":false},"author":1834,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1094},"categories":[5877],"tags":[6183,6430,6429],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/65175"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1834"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=65175"}],"version-history":[{"count":25,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/65175\/revisions"}],"predecessor-version":[{"id":79499,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/65175\/revisions\/79499"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=65175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=65175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=65175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}