Shell Script | Install Telegraf on Linux machines


What is Telegraf? 

Telegraf is an open-source server agent maintained by Influxdata team. This is a commonly used agent to collect metrics from different sources. It can collect data from various inputs (like metrics, logs, events, databases, etc.) and send them to various outputs (like InfluxDB, Graphite, Datadog, Kafka, MQTT, etc.). It provides 100s of plugins to collect different types of data.

Today's Agenda

In this post, we will learn how to install Telegraf agent on a server that can be used to collect data with its various plugins. You can follow this blog to get a separate script that will configure InfluxDB and Grafana with just a single command.

Prerequisite

This post has been prepared for the audience who : 
  1. Have access to a Linux-based system like Ubuntu, CentOS, Redhat, etc.
  2. Have a basic understanding of Linux-based systems and their commands.
  3. And finally, are eager to learn and try something new.

Let's get started

Step 1: Create a new file to store the shell script.

Create a file with the name SetupMetricsAgent-Telegraf.sh and add the below script to it.
#!/bin/bash

if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root user"
  exit 1
fi

usage() {
    echo  -e "\n###\n Telegraf Agent Installation Script
      Note:
        This script is for Ubuntu | Debian | Redhat | CentOS Server types Only.
      Purpose:
        This Script will perform the following functions:
-- Check OS type of server.
-- Install Telegraf 1.16 with required input plugins & dependencies.
      Usage:
        bash $0 --help
        bash $0 start
      Script Parameters:
        start                  starts the script
        --help or -h           shows this help text \n###\n"
    exit 0
}

if test "$1" = "" || test  "$1" = "--help" || test "$1" = "-h"; then
  usage
elif test "$1" = "start" ; then
  break
fi
echo -e "\n##############################################\n"

###########################################################
##         install Telegraf on client machine            ##
###########################################################
debian_telegraf() {
    #Installing Telegraf on Ubuntu
    echo -e "\n###\n Downloading Telegraf 1.16 \n###\n"
    wget https://dl.influxdata.com/telegraf/releases/telegraf_1.16.2-1_amd64.deb
    echo -e "\n###\n Installing Telegraf 1.16 \n###\n"
    sudo dpkg -i telegraf_1.16.2-1_amd64.deb
    echo -e "\n###\n Starting Telegraf Service \n###\n"
    systemctl start telegraf.service
    echo -e "\n###\n Removing deb package \n###\n"
    rm -f telegraf_*.*_amd64.deb
}

redhat_telegraf() {
    #Installing Telegraf on Ubuntu
    echo -e "\n###\n Downloading Telegraf 1.16 \n###\n"
    wget https://dl.influxdata.com/telegraf/releases/telegraf-1.16.2-1.x86_64.rpm
    echo -e "\n###\n Installing Telegraf 1.16 \n###\n"
    sudo yum localinstall telegraf-1.16.2-1.x86_64.rpm
    echo -e "\n###\n Starting Telegraf Service \n###\n"
    systemctl start telegraf.service
    echo -e "\n###\n Removing deb package \n###\n"
    rm -f telegraf_*.*_amd64.deb
}
if [ "$(grep -Ei 'Debian|Ubuntu|Mint' /etc/*release)" ]
    then
        echo " It's a Debian or Ubuntu based system."
        debian_telegraf
elif [ "$(grep -Ei 'Redhat|CentOS|Fedora' /etc/*release)" ]
    then
        echo " It's a Redhat or CentOS based system."
        redhat_telegraf
else
    echo "This script doesn't support this OS type."
    echo "Please refer this page to find your OS type: https://www.influxdata.com/get-influxdb/"
    exit 3
fi

#Finishing
echo  -e "\n###\n ### Telegraf Agent is Installed ###
Following Should Work to check if data is being sent to your database Server:
-- telegraf service should be running
-- telegraf should be able to connect to your database server. \n###\n"

Step 2 : Run this Shell Script to begin Installation.

This Shell Script needs to be run as a root user.

To know how this shell script works, enter the below command:

      bash SetupMetricsAgent-Telegraf.sh --help


Add the asked variables and run the Shell Script as the root user.

      sudo bash SetupMetricsAgent-Telegraf.sh start


To Configure InfluxDB and Grafana, please follow this blog.


Step 3 : Setup InfluxDB and Grafana for setting up the full monitoring stack.

Install InfluxDB (database to store above metrics) and Grafana (to visualise the collected metrics in a meaningful way) on the server.
You can follow this blog to get a separate script that will configure InfluxDB and Grafana with just a single command.

Once All the 3 tools are up and running, you can start with configuring Telegraf plugins to start metrics collection.

That's all, you did a great job !!

If you face any issues or need any suggestions, please comment down below and hit the like button to appreciate the efforts.







Comments

  1. At the time, he was dreaming up his most ambitious device ever. With eye-catching diamond and coronary heart graphics, put together for a blinged-out win on Triple the Thrill™ – Divine Diamonds™! The Heart Connection function is triggered through the base game or free video games by three, 4 or five scattered purple or diamond hearts. The most desired gem of the sport is triggered by a Divine Reel image on reels two, three and four, awarding one Divine Reel spin. Enjoy a 카지노사이트 recent tackle tried-and-true Hold & Spin mechanics with two new Coin Trio™ video games, Fortune Trails and Piggy Burst. These slots combine confirmed game mechanics with progressive options to deliver enhanced rewards.

    ReplyDelete

Post a Comment