How to Use Grafana for Real-Time Monitoring on Ubuntu
How to Use Grafana for Real-Time Monitoring on Ubuntu
Grafana is a powerful open-source analytics and monitoring platform that allows you to visualize and analyze data from various sources. It is particularly useful for real-time monitoring, enabling users to create dynamic and interactive dashboards. This guide will walk you through the installation and setup of Grafana on Ubuntu, as well as how to use it effectively for real-time monitoring.
Prerequisites
Before you start, ensure you have the following:
- An Ubuntu server (preferably 20.04 LTS or later).
- A user account with sudo privileges.
- A data source for Grafana to monitor, such as Prometheus, InfluxDB, or MySQL.
Step 1: Installing Grafana
Update Your System
Open your terminal and update your package list to ensure you have the latest information about available packages:
–
sudo apt update
sudo apt upgrade -y
Add the Grafana APT Repository
Next, you need to add the Grafana APT repository to your system. This will allow you to easily install and update Grafana using the package manager.
sudo apt install -y software-properties-common
sudo add-apt-repository “deb https://packages.grafana.com/oss/release/deb stable main”
Install Grafana
After adding the repository, update your package list again and install Grafana:
sudo apt update
sudo apt install grafana
Start and Enable Grafana
Once installed, you need to start the Grafana service and enable it to launch on boot:
sudo systemctl start grafana-server
sudo systemctl enable grafana-serverAccess Grafana
Grafana typically runs on port 3000. You can access it by opening a web browser and navigating to:
http://your-server-ip:3000
The default login credentials are:
Username: admin
Password: admin
You will be prompted to change the password upon your first login.
Step 2: Adding a Data Source
Once logged in, the next step is to configure a data source for Grafana to collect data from. Below, we’ll use Prometheus as an example.
Install Prometheus
If you haven’t already installed Prometheus, you can do so by following these steps:
sudo apt install prometheus
Make sure Prometheus is running by checking its service status:
sudo systemctl start prometheus
sudo systemctl enable prometheus
Add Prometheus as a Data Source in Grafana
- In the Grafana dashboard, click on the gear icon (⚙️) to go to the Configuration menu.
- Click on Data Sources.
- Click the Add data source button.
- Select Prometheus from the list.
- In the HTTP section, set the URL to http://localhost:9090 (the default Prometheus endpoint).
- Click Save & Test to verify the connection.
Step 3: Creating Your First Dashboard
With a data source configured, you’re ready to create your first dashboard.
- Create a New Dashboard
- Click on the Plus icon (➕) in the left sidebar.
Select Dashboard.
Add a New Panel - Click on Add new panel.
In the panel editor, select your data source (Prometheus).
Enter a Prometheus query in the Query section. For example, to monitor CPU usage, you could use the following query:
rate(node_cpu_seconds_total{mode=”idle”}[5m])
Customize Your Panel
- Choose the visualization type you prefer (e.g., Graph, Gauge, Bar Gauge).
- Adjust the panel settings, such as titles and legends, to customize how the data is displayed.
- Click Apply to save the panel to your dashboard.
Repeat for More Panels
Add more panels to your dashboard by repeating the steps above, using different queries to visualize various metrics.
Step 4: Setting Up Alerts
Grafana also allows you to set up alerts based on your data, notifying you when certain thresholds are met.
Configure Alerts in a Panel
- Click on the panel you want to set up alerts for.
- Go to the Alert tab in the panel editor.
- Click on Create Alert and configure your alert conditions, such as thresholds and evaluation intervals.
- Define the notification channels where alerts will be sent (e.g., email, Slack, etc.).
- Click Save to apply the alert configuration.
Step 5: Sharing and Collaboration
Once you’ve created your dashboards, you can share them with others:
Share a Dashboard
- Click on the share icon (📤) at the top of the dashboard.
- Choose how you want to share: via link, snapshot, or export.
- Configure access permissions if needed.
- Dashboard Permissions
To manage who can view or edit your dashboards, navigate to the Dashboard settings and configure permissions for specific users or teams.
Thank you for visiting our page! If you’re interested in exploring more articles about Linux systems and using Elasticsearch for full-text search, feel free to check out the links below.