How to install Prometheus and Grafana on Ubuntu

Prometheus and Grafana are essential open-source monitoring tools for Monitoring in DevOps. Collects metrics, and offers a holistic view.
Prometheus is an open-source monitoring toolkit crucial for proactive system health. It excels at collecting metrics from various sources, offering a holistic view of infrastructure. With PromQL, its flexible querying language, Prometheus enables granular analysis to identify bottlenecks and anomalies before performance is affected. Its scalability makes it suitable for diverse environments.
Prometheus: Empowering Real-Time Monitoring
Prometheus, an open-source monitoring and alerting toolkit, is the linchpin for proactive system monitoring. Designed for scalability, Prometheus excels at collecting metrics from diverse sources, providing a holistic view of your infrastructure’s health. With its flexible querying language, PromQL, Prometheus enables granular analysis, helping you identify bottlenecks and anomalies before they impact performance.
In the ever-evolving landscape of digital ecosystems, Prometheus stands out by seamlessly integrating with various applications and services, making it an ideal choice for organizations embracing microservices architectures. Its robust alerting system ensures that potential issues are addressed promptly, reducing downtime and enhancing overall system reliability. Grafana: Crafting Intuitive Visualizations
Enter Grafana, the visualization powerhouse that complements Prometheus with stunning dashboards and interactive graphs. Grafana transforms raw data into actionable insights, providing a user-friendly interface that facilitates data exploration and correlation. This intuitive platform supports a wide array of data sources, making it a versatile choice for businesses with diverse tech stacks.
Installing Prometheus
Set up Prometheus to monitor your application.
Install Dependencies
sudo apt-get update
sudo apt-get install -y apt-transport-https software-properties-common
First, create a dedicated Linux user for Prometheus and download Prometheus:
sudo useradd --system --no-create-home --shell /bin/false prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.47.1/prometheus-2.47.1.linux-amd64.tar.gz
Extract Prometheus files, move them, and create directories:
tar -xvf prometheus-2.47.1.linux-amd64.tar.gz
cd prometheus-2.47.1.linux-amd64/
sudo mkdir -p /data /etc/prometheus
sudo mv prometheus promtool /usr/local/bin/
sudo mv consoles/ console_libraries/ /etc/prometheus/
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
Set ownership for directories:
sudo nano /etc/systemd/system/prometheus.service
Add the following content to the prometheus.service file:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/data \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--web.enable-lifecycle
[Install]
WantedBy=multi-user.target
Here’s a brief explanation of the key parts of this prometheus.service file:
User
andGroup
specify the Linux user and group under which Prometheus will run.ExecStart
is where you specify the Prometheus binary path, the location of the configuration file(prometheus.yml)
, the storage directory, and other settings.web.listen-address
configures Prometheus to listen on all network interfaces on port 9090.web.enable-lifecycle
allows for the management of Prometheus through API calls.
Enable and start Prometheus:
sudo systemctl enable prometheus
sudo systemctl start prometheus
Verify Prometheus’s status:
sudo systemctl status prometheus
You can access Prometheus in a web browser using your server’s IP and port 9090:
http://<your-server-ip>:9090
Installing Grafana
Set up Prometheus to visualize your metrics.
Install Dependencies
sudo apt-get update
sudo apt-get install -y apt-transport-https software-properties-common
Add the GPG Key:
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
Add Grafana Repository: Add the repository for Grafana stable releases
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
Update and Install Grafana:
sudo apt-get update
sudo apt-get -y install grafana
Enable and Start Grafana Service:
sudo systemctl enable grafana-server
Start Grafana:
sudo systemctl start grafana-server
Check Grafana Status:
sudo systemctl status grafana-server
Access Grafana Web Interface:
http://<your-server-ip>:3000
You’ll be prompted to log in to Grafana. The default username is “admin,” and the default password is also “admin.”
Change the Default Password:
When you log in for the first time, Grafana will prompt you to change the default password for security reasons. Follow the prompts to set a new password.