Prometheus and Grafana are powerful open-source tools used for monitoring and visualizing system metrics, making them essential components of any modern infrastructure. In this comprehensive guide, we will walk you through the step-by-step process of installing Prometheus and Grafana on an Ubuntu system. By the end of this tutorial, you’ll have a robust monitoring setup that provides valuable insights into your system’s performance.
Prerequisites
Before we begin, ensure that you have the following:
- An Ubuntu server or virtual machine (minimum Ubuntu 18.04 LTS)
- Sudo access or a user with administrative privileges
- Basic familiarity with the Linux command line
Step 1: Installing Prometheus
Update System Packages:
Start by updating your Ubuntu system packages to ensure you have the latest versions.
apt-get update && apt-get upgrade -y
Download Prometheus:
Visit the official Prometheus website (https://prometheus.io/) and navigate to the downloads page. Choose the appropriate package for your Ubuntu version.
Install Prometheus:
Once the download is complete, extract the Prometheus tarball and move it to the desired location. You may choose to install it system-wide or in your user’s home directory.
# wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz
# tar zxvf prometheus-2.44.0.linux-amd64.tar.gz
# cd prometheus-2.44.0.linux-amd64/
Configure Prometheus:
Prometheus comes with a default configuration file named “prometheus.yml.” You can customize it based on your monitoring needs.
cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
Start Prometheus:
Launch the Prometheus server by executing the following command:
./prometheus –config.file=prometheus.yml
Verify Prometheus Installation:
Open your web browser and access http://server-ip-address:9090. If Prometheus is running correctly, you will see the Prometheus web interface.
Step 2: Installing Grafana
Add the Grafana Repository:
Run the following command to add the Grafana repository to your system:
# sudo apt install -y apt-transport-https
# wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
# echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
Install Grafana
Update the package list and install Grafana with the following commands:
sudo apt-get update
sudo apt-get install grafana
Start Grafana:
Enable and start the Grafana service:
sudo systemctl enable --now grafana-server
Access Grafana:
Open your web browser and go to http://your-server-ip:3000. You will be prompted to set up a new admin password. Follow the on-screen instructions to complete the setup.
Execute the following command to set the admin password to a new value:
# sudo systemctl stop grafana-server
# sudo grafana-cli admin reset-admin-password <new_password>
# sudo systemctl start grafana-server
Replace <new_password>
with your desired new password.
Configure Prometheus as a Data Source:
In the Grafana web interface, click on “Connections” > “Data Sources.” Add a new data source and choose Prometheus. Provide the URL of your Prometheus server (e.g., http://server-ip:9090) and save the configuration.
Create Dashboards:
Grafana provides a rich set of pre-built dashboards and visualizations. Explore the dashboard library or create your custom dashboards to monitor your system metrics effectively.
Congratulations! You have successfully installed Prometheus and Grafana on your Ubuntu system. With this monitoring setup, you can now gain valuable insights into your infrastructure’s performance and troubleshoot any issues promptly. Experiment with Grafana’s visualization options to create personalized dashboards that suit your monitoring requirements. Keep exploring the capabilities of Prometheus and Grafana to unleash their full potential.
2 Comments
How To Tune Your MySQL Server For Optimal Performance - Virtono Community · June 12, 2023 at 9:31 AM
[…] Utilize performance monitoring tools like MySQL Enterprise Monitor, Percona Monitoring, or open-source alternatives like Prometheus and Grafana. […]
How To Deploy Grafana On Kubernetes - Virtono Community · August 24, 2023 at 8:27 PM
[…] article will walk you through the process of deploying Grafana on Kubernetes, specifically using k3s and Helm, and making it accessible via a NodePort on your VPS […]