Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Telegraf #10

Merged
merged 4 commits into from
Feb 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add install-telegraf script
  • Loading branch information
tonerdo committed Feb 11, 2019
commit bf23039944493374edc19fdf4d1eb2fe68857649
104 changes: 104 additions & 0 deletions modules/install-telegraf/install-telegraf
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash

set -e

# Import the appropriate bash commons libraries
readonly BASH_COMMONS_DIR="/opt/gruntwork/bash-commons"
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

readonly DEFAULT_TELEGRAF_VERSION="1.9.4"
readonly DEFAULT_TEMP_TELEGRAF_CONFIG_FILE_PATH="/tmp/config/telegraf.conf"
readonly DEFAULT_TELEGRAF_CONFIG_FILE_PATH="/etc/telegraf/telegraf.conf"
readonly DEFAULT_TELEGRAF_DIR="/opt/telegraf"
readonly DEFAULT_TELEGRAF_BIN_DIR="$DEFAULT_TELEGRAF_DIR/bin"

if [[ ! -d "$BASH_COMMONS_DIR" ]]; then
echo "ERROR: this script requires that bash-commons is installed in $BASH_COMMONS_DIR. See https://github.com/gruntwork-io/bash-commons for more info."
exit 1
fi

source "$BASH_COMMONS_DIR/assert.sh"
source "$BASH_COMMONS_DIR/log.sh"
source "$BASH_COMMONS_DIR/os.sh"

function print_usage {
echo
echo "Usage: install-telegraf [options]"
echo
echo "This script can be used to install Telegraf and its dependencies. This script has been tested with Ubuntu 18.04 and Amazon Linux 2."
echo
echo "Options:"
echo
echo -e " --version\t\tThe version of InfluxDB Enterprise to install. Default: $DEFAULT_TELEGRAF_VERSION."
echo -e " --config-file\t\tPath to a custom configuration file. Default: $DEFAULT_TEMP_TELEGRAF_CONFIG_FILE_PATH"

echo
echo "Example:"
echo
echo " install-telegraf --version $DEFAULT_TELEGRAF_VERSION --config-file $DEFAULT_TEMP_TELEGRAF_CONFIG_FILE_PATH"
}

function install_telegraf_on_ubuntu {
local -r version="$1"

log_info "Installing Telegraf"
wget https://dl.influxdata.com/telegraf/releases/telegraf_${version}-1_amd64.deb
tonerdo marked this conversation as resolved.
Show resolved Hide resolved
sudo dpkg -i "telegraf_${version}-1_amd64.deb"
}

function install_telegraf_on_amazon_linux {
local -r version="$1"

log_info "Installing Telegraf"
wget "https://dl.influxdata.com/telegraf/releases/telegraf-${version}-1.x86_64.rpm"
tonerdo marked this conversation as resolved.
Show resolved Hide resolved
sudo yum localinstall -y "telegraf-${version}-1.x86_64.rpm"
}

function install_telegraf {
local version="$DEFAULT_TELEGRAF_VERSION"
local config_file="$DEFAULT_TEMP_TELEGRAF_CONFIG_FILE_PATH"

while [[ $# > 0 ]]; do
local key="$1"

case "$key" in
--help)
print_usage
exit
;;
--version)
assert_not_empty "$key" "$2"
version="$2"
shift
;;
--config-file)
assert_not_empty "$key" "$2"
config_file="$2"
shift
;;
*)
echo "Unrecognized argument: $key"
print_usage
exit 1
;;
esac

shift
done

assert_is_installed "sudo"
assert_is_installed "wget"

if os_is_ubuntu "18.04"; then
install_telegraf_on_ubuntu "$version"
elif os_is_amazon_linux "2"; then
install_telegraf_on_amazon_linux "$version"
else
log_error "This script only supports Ubuntu 18.04 and Amazon Linux 2."
exit 1
fi

sudo mv "$config_file" "$DEFAULT_TELEGRAF_CONFIG_FILE_PATH"
}

install_telegraf "$@"