- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Install Glances, InfluxDB and Grafana to Monitor CentOS 7
Introduction
Monitoring the performance and health of your CentOS 7 server is essential for maintaining its stability and optimizing its resources. In this article, we will explore how to install and configure Glances, InfluxDB, and Grafana—a powerful trio of monitoring tools—to gather system metrics, store them in a database, and visualize them in real-time.
Glances: System Monitoring Tool
Glances is a cross-platform system monitoring tool that provides a comprehensive overview of various system metrics such as CPU usage, memory usage, network activity, disk I/O, and much more. To install Glances, follow these steps −
Step 1: Update the System
Before installing any new software, it's always a good practice to update your system packages. Open a terminal and run the following command −
sudo yum update
Step 2: Install Glances
Once the system is updated, install Glances by running the following command −
sudo yum install glances
After the installation is complete, you can launch Glances by executing the following command −
glances
Glances will start displaying real-time system metrics in a user-friendly interface.
InfluxDB : Time-Series Database
InfluxDB is a high-performance, open-source time-series database that is perfect for storing and retrieving large amounts of time-stamped data. It will serve as the backend for storing the system metrics collected by Glances. Here's how you can install InfluxDB:
Step 1: Download and Install InfluxDB
To download the latest version of InfluxDB, visit the official website and obtain the appropriate package for CentOS 7. Once downloaded, navigate to the directory where the package is located and install InfluxDB using the following command −
sudo yum localinstall influxdb_package.rpm
Replace influxdb_package.rpm with the actual package filename.
Step 2: Start and Enable InfluxDB
After the installation is complete, start the InfluxDB service by running the following command −
sudo systemctl start influxdb
To ensure that InfluxDB starts automatically on system boot, enable the service with this command −
sudo systemctl enable influxdb
Step 3: Configure InfluxDB
To configure InfluxDB, open the InfluxDB configuration file using a text editor −
sudo nano /etc/influxdb/influxdb.conf
Inside the configuration file, locate the [http] section and uncomment the bind-address option, specifying the IP address or hostname of your server. Save and close the file.
Step 4: Create a Database in InfluxDB
To create a new database in InfluxDB, open a terminal and execute the following command −
influx
This will open the InfluxDB shell. In the shell, run the following command to create a database −
CREATE DATABASE database_name
Replace database_name with a name of your choice.
Grafana: Data Visualization Tool
Grafana is a popular open-source data visualization tool that allows you to create beautiful and interactive dashboards to monitor and analyze various metrics. Let's install Grafana −
Step 1: Install Grafana
To install Grafana, run the following commands −
sudo yum install -y https://dl.grafana.com/oss/release/grafana_package.rpm sudo systemctl start grafana-server sudo systemctl enable grafana-server
Step 2: Access Grafana Web Interface
Once the installation is complete, you can access the Grafana web interface by opening a web browser and navigating to http://your_server_ip:3000. Log in using the default username and password (admin/admin), and change the password when prompted.
Step 3: Configure InfluxDB Data Source
After logging in to Grafana, add InfluxDB as a data source by following these steps −
Click on the gear icon on the left sidebar to open the configuration menu.
Select "Data Sources" from the menu.
Click on "Add data source."
Choose "InfluxDB" as the type.
Fill in the required details, including the URL, database name, and credentials.
Click on "Save & Test" to ensure the connection is successful.
Step 4: Create a Dashboard
To create a dashboard in Grafana, click on the plus icon on the left sidebar and select "Dashboard." From there, you can add panels to visualize different metrics and customize the layout according to your preferences.
Example 1: Monitoring CPU and Memory Usage
After installing and launching Glances, you will see a comprehensive overview of various system metrics. Let's focus on monitoring CPU and memory usage.
Output
Load Average: 0.12, 0.08, 0.10 CPU Usage: 10% Memory Usage: 40%
In the Glances interface, you can observe the load average, which indicates the average system load over a specific period. The CPU usage percentage represents the utilization of the CPU, and the memory usage percentage reflects the amount of RAM consumed.
Example 2: Tracking Network Activity
Glances provides real-time information about network activity, including incoming and outgoing traffic.
Output
Network Interface - eth0 - Received: 5.2 kB/s - Sent: 2.8 kB/s
This output showcases the network interface eth0, indicating the rate of data received and sent in kilobytes per second (kB/s). It helps monitor network usage and detect potential bottlenecks.
Example 3: Disk I/O Monitoring
Glances also offers insights into disk I/O activity, allowing you to monitor read and write operations on storage devices.
Output
Disk I/O - sda - Read: 50 kB/s - Write: 20 kB/s
This output displays disk I/O metrics for the storage device sda. It shows the rate of data read and written in kilobytes per second (kB/s), enabling you to identify disk performance issues and optimize storage utilization.
Example 4: Visualizing Metrics with Grafana
Grafana provides a powerful dashboarding capability to visualize the metrics collected by Glances and stored in InfluxDB. Let's create a simple Grafana dashboard to monitor CPU and memory usage over time.
In this example, the Grafana dashboard displays a line chart representing CPU and memory usage over a specific timeframe. You can customize the dashboard by adding additional panels, selecting different visualization types, and setting up alerts based on predefined thresholds.
By leveraging the integration of Glances, InfluxDB, and Grafana, you can gain comprehensive insights into the performance and health of your CentOS 7 server, allowing you to make informed decisions for system optimization, troubleshooting, and capacity planning.
Conclusion
Monitoring the performance of your CentOS 7 server is crucial for maintaining its stability and ensuring optimal resource utilization. By installing Glances, InfluxDB, and Grafana, you can gather system metrics, store them in a time-series database, and visualize them in real-time. With these powerful monitoring tools at your disposal, you can proactively identify bottlenecks, optimize resource allocation, and ensure the smooth operation of your CentOS 7 server.