
Setting up a robust monitoring solution is essential for keeping track of your systems and applications. The TIG Stack, comprising Telegraf, InfluxDB, and Grafana, provides a powerful platform for collecting, storing, and visualizing time-series data. This guide walks you through installing and configuring the TIG Stack on Ubuntu 20.04.
Prerequisites
Before you begin, ensure you have:
- An instance of Ubuntu 20.04 server.
- A user with sudo privileges.
- Basic knowledge of the Linux command line.
Step 1: Installing InfluxDB
InfluxDB is the time-series database component of the TIG Stack. It’s optimized for handling large volumes of time-stamped data.
First, update your package lists:
sudo apt update
Next, install the necessary packages to add a new repository using HTTPS:
sudo apt install -y apt-transport-https curl
Import the InfluxData repository key:
curl -sL https://repos.influxdata.com/influxdata-archive_signed.key | sudo apt-key add -
Add the InfluxData repository to your sources list:
echo "deb https://repos.influxdata.com/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/influxdata.list
Update your package lists again to include the new repository:
sudo apt update
Now, install the InfluxDB package:
sudo apt install -y influxdb
Start the InfluxDB service and enable it to start automatically on boot:
sudo systemctl start influxdb
sudo systemctl enable influxdb
Verify that InfluxDB is running:
sudo systemctl status influxdb
You should see an active (running)
status.
Step 2: Installing Telegraf
Telegraf is a server agent designed to collect metrics from various inputs and write them into various outputs, including databases and message queues. It will be our data collector.
Since we added the InfluxData repository in the previous step, you can simply install Telegraf:
sudo apt install -y telegraf
Start the Telegraf service and enable it:
sudo systemctl start telegraf
sudo systemctl enable telegraf
Verify the Telegraf service status:
sudo systemctl status telegraf
It should also show an active (running)
status.
Step 3: Configuring Telegraf
By default, Telegraf collects system metrics and is configured to output to InfluxDB on localhost
(which is the default). However, it’s good practice to understand and potentially customize its configuration.
The main configuration file is located at /etc/telegraf/telegraf.conf. You can edit it using a text editor like nano
:
sudo nano /etc/telegraf/telegraf.conf
Inside this file, you’ll find sections for [[inputs]]
and [[outputs]]
.
- The
[[outputs.influxdb]]
section configures where Telegraf sends data. The defaulturls = ["http://127.0.0.1:8086"]
is usually correct if InfluxDB is on the same server using the default port. - The
[[inputs.cpu]]
,[[inputs.mem]]
,[[inputs.disk]]
, etc., sections configure which metrics are collected.
For this basic setup, the default configuration should work. If you make any changes, restart Telegraf for them to take effect:
sudo systemctl restart telegraf
Step 4: Installing Grafana
Grafana is the visualization layer of the TIG Stack. It allows you to create dynamic dashboards using the data stored in InfluxDB.
Similar to InfluxDB, we need to add the Grafana repository.
Add the Grafana GPG key:
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
Add the Grafana stable repository:
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
Update your package lists:
sudo apt update
Install Grafana:
sudo apt install -y grafana
Start the Grafana service and enable it:
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
Check the status of the Grafana service:
sudo systemctl status grafana-server
It should be active (running)
.
Step 5: Accessing Grafana and Adding InfluxDB Data Source
Grafana runs on port 3000 by default. Open your web browser and navigate to http://your_server_ip_or_domain:3000
.
You should see the Grafana login page. The default login credentials are:
- Username:
admin
- Password:
admin
You will be prompted to change the password immediately after logging in for the first time.
Once logged in, you need to add InfluxDB as a data source:
- Click the gear icon (Configuration) on the left-hand menu.
- Select Data Sources.
- Click Add data source.
- Choose InfluxDB from the list.
- In the HTTP section, set the URL to
http://localhost:8086
(if InfluxDB is on the same server). - In the InfluxDB Details section:
- Database: You can leave this blank initially or specify the database Telegraf is writing to (default is
telegraf
). - Leave other fields as default for now.
- Database: You can leave this blank initially or specify the database Telegraf is writing to (default is
- Click the Save & Test button. You should see a “Data source is working” message.
Step 6: Creating a Basic Dashboard (Optional but Recommended)
Now that InfluxDB is configured as a data source, you can create a dashboard to visualize the collected metrics.
- Click the ‘+’ icon on the left-hand menu and select Dashboard.
- Click Add new panel.
- In the Query editor, select your InfluxDB data source.
- Write a query to select data. For instance, to view CPU usage collected by Telegraf:
- FROM
default
Measurementcpu
- SELECT
mean()
usage_system
- WHERE
cpu
=cpu-total
- GROUP BY
time($__interval)
fill(null)
- FROM
- Customize the visualization options (title, panel type, etc.).
- Click Apply.
- Save your dashboard by clicking the floppy disk icon at the top.
Conclusion
You have successfully installed and set up the TIG Stack (Telegraf, InfluxDB, and Grafana) on Ubuntu 20.04. Telegraf is now collecting system metrics and sending them to InfluxDB for storage, and Grafana is ready for you to create powerful dashboards to visualize this data. From here, you can explore configuring Telegraf to collect data from various sources and build more complex Grafana dashboards tailored to your specific monitoring needs.
Source: https://kifarunix.com/install-and-setup-tig-stack-on-ubuntu-20-04/