07ae3f81ba
- Automated the required configurations for the collectd.conf file - Enables the virt and network plugins - Included a MULTI_NODE_DEPLOYMENT configuration option for this change - This is only enabled when the libvirt.py file is not in use - Provided instructions on how to deploy multi-node Change-Id: I151e318074250b94dbef247e6858c78086fcd362
213 lines
7.6 KiB
Bash
213 lines
7.6 KiB
Bash
#!/bin/bash
|
|
#
|
|
# common functions for collectd ceilometer plugin
|
|
# -----------------------------------------------
|
|
|
|
# start/stop service
|
|
#
|
|
function start_collectd {
|
|
if [ -e /usr/lib/systemd/system/collectd.service ] || [ -e /etc/init.d/collectd ]; then
|
|
sudo service collectd restart
|
|
fi
|
|
}
|
|
|
|
function stop_collectd {
|
|
if [ -e /usr/lib/systemd/system/collectd.service ] || [ -e /etc/init.d/collectd ]; then
|
|
sudo service collectd stop
|
|
fi
|
|
}
|
|
|
|
|
|
function install_requirements {
|
|
echo "Installing pre-resquisites"
|
|
|
|
if [[ ! -z "$COLLECTD_REQUIREMENTS" ]]; then
|
|
install_package $COLLECTD_REQUIREMENTS $COLLECTD_ADDITIONAL_PACKAGES
|
|
else
|
|
echo "Unsupported distros"
|
|
fi
|
|
|
|
}
|
|
|
|
function install_service_file {
|
|
# Configure systemd service file
|
|
if [[ `ls -la /sbin/init` =~ "systemd" ]]; then
|
|
local service_file=/etc/systemd/system/collectd.service
|
|
local collectd_binary=$COLLECTD_PREFIX/sbin/collectd
|
|
local collectd_conf_file=$COLLECTD_PREFIX/etc/collectd.conf
|
|
|
|
sudo -E cp $COLLECTD_DIR/contrib/systemd.collectd.service $service_file
|
|
sudo sed 's#ExecStart=.*$#ExecStart='"$collectd_binary"' -C '"$collectd_conf_file"'#g' -i $service_file
|
|
|
|
# Enable collectd
|
|
sudo systemctl enable collectd
|
|
else
|
|
die $LINENO "No support for systemd on this platform.\n
|
|
To use collectd, build it, configure the service
|
|
manually, and set COLLECTD_INSTALL=False."
|
|
fi
|
|
|
|
}
|
|
|
|
function build_collectd {
|
|
|
|
git_clone $COLLECTD_REPO $COLLECTD_DIR $COLLECTD_BRANCH
|
|
pushd $COLLECTD_DIR
|
|
|
|
# $PS4 has been defined to call short_source but the function is not
|
|
# available when build.sh is called.
|
|
OPS4=$PS4
|
|
PS4='+'
|
|
|
|
build_output=$( ./build.sh )
|
|
echo "Build output: " $build_output
|
|
|
|
PS4=$OPS4
|
|
|
|
./configure --enable-python --enable-debug \
|
|
--enable-logging --enable-syslog \
|
|
--prefix=$COLLECTD_PREFIX/
|
|
make -j all
|
|
sudo make install
|
|
popd
|
|
|
|
# Allow read access to collectd conf file
|
|
sudo chmod +r $COLLECTD_PREFIX/etc/collectd.conf;
|
|
|
|
install_service_file
|
|
add_include_dir
|
|
|
|
}
|
|
|
|
# install collectd
|
|
function install_collectd {
|
|
if [[ "$COLLECTD_INSTALL" == True ]]; then
|
|
if [[ "$COLLECTD_INSTALL_TYPE" == "source" ]]; then
|
|
build_collectd
|
|
else # if install type is binary
|
|
if is_fedora || is_ubuntu; then
|
|
install_package collectd
|
|
else
|
|
die $LINENO "No support for collectd on this platform"
|
|
fi
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Add the Include block so that conf dir is read
|
|
function add_include_dir {
|
|
cat << EOF | sudo -E tee -a $PREFIX/etc/collectd.conf
|
|
|
|
<Include "$COLLECTD_CONF_DIR">
|
|
Filter "*.conf"
|
|
</Include>
|
|
EOF
|
|
|
|
}
|
|
|
|
# Add conf file for plugin
|
|
function adapt_collectd_conf {
|
|
if [ ! -d "$COLLECTD_CONF_DIR" ]; then
|
|
sudo -E mkdir -p "$COLLECTD_CONF_DIR"
|
|
fi
|
|
|
|
# Configure collectd hostname
|
|
CONF_FILE=$(sudo find /etc -name "collectd.conf")
|
|
sudo sed -E -i 's|(^\|^#)Hostname.*$|Hostname "'$(hostname)'"|g' $CONF_FILE
|
|
|
|
if [[ "$MULTI_NODE_DEPLOYMENT" == "True" ]]; then
|
|
sudo cp $COLLECTD_CEILOMETER_DIR/etc/collectd.conf.d/multi-node.conf $COLLECTD_CONF_DIR/
|
|
fi
|
|
|
|
# configure collectd-gnocchi plugin
|
|
if [[ "$COLLECTD_GNOCCHI_ENABLED" == "True" ]]; then
|
|
|
|
sudo cp $COLLECTD_CEILOMETER_DIR/etc/collectd.conf.d/collectd-gnocchi-plugin.conf $COLLECTD_CONF_DIR/
|
|
|
|
# Configure collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|ModulePath.*$|ModulePath "'$COLLECTD_CEILOMETER_DIR'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|VERBOSE.*$|VERBOSE '$COLLECTD_GNOCCHI_VERBOSE'|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|BATCH_SIZE.*$|BATCH_SIZE "'$COLLECTD_BATCH_SIZE'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|OS_AUTH_URL.*$|OS_AUTH_URL "'$OS_AUTH_URL'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|CEILOMETER_URL_TYPE.*$|CEILOMETER_URL_TYPE "'$CEILOMETER_URL_TYPE'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|CEILOMETER_TIMEOUT.*$|CEILOMETER_TIMEOUT "'$CEILOMETER_TIMEOUT'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|OS_PASSWORD.*$|OS_PASSWORD "'$SERVICE_PASSWORD'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|OS_TENANT_NAME.*$|OS_TENANT_NAME "'$SERVICE_TENANT_NAME'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
sudo sed -i 's|LIBVIRT_METER_ENABLED.*$|LIBVIRT_METER_ENABLED "'$LIBVIRT_METER_ENABLED'"|g' $COLLECTD_CONF_DIR/collectd-gnocchi-plugin.conf
|
|
|
|
config_custom_units "gnocchi" "$COLLECTD_GNOCCHI_UNITS"
|
|
fi
|
|
|
|
# configure collectd-aodh plugin
|
|
if [[ "$COLLECTD_AODH_ENABLED" == "True" ]]; then
|
|
|
|
sudo cp $COLLECTD_CEILOMETER_DIR/etc/collectd.conf.d/collectd-aodh-plugin.conf $COLLECTD_CONF_DIR/
|
|
|
|
# Configure collectd-aodh-plugin.conf
|
|
sudo sed -i 's|ModulePath.*$|ModulePath "'$COLLECTD_CEILOMETER_DIR'"|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
sudo sed -i 's|VERBOSE.*$|VERBOSE '$COLLECTD_AODH_VERBOSE'|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
sudo sed -i 's|OS_AUTH_URL.*$|OS_AUTH_URL "'$OS_AUTH_URL'"|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
sudo sed -i 's|CEILOMETER_URL_TYPE.*$|CEILOMETER_URL_TYPE "'$CEILOMETER_URL_TYPE'"|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
sudo sed -i 's|CEILOMETER_TIMEOUT.*$|CEILOMETER_TIMEOUT "'$CEILOMETER_TIMEOUT'"|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
sudo sed -i 's|OS_PASSWORD.*$|OS_PASSWORD "'$SERVICE_PASSWORD'"|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
sudo sed -i 's|OS_TENANT_NAME.*$|OS_TENANT_NAME "'$SERVICE_TENANT_NAME'"|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
sudo sed -i 's|LIBVIRT_METER_ENABLED.*$|LIBVIRT_METER_ENABLED "'$LIBVIRT_METER_ENABLED'"|g' $COLLECTD_CONF_DIR/collectd-aodh-plugin.conf
|
|
|
|
config_custom_severities "aodh" "$COLLECTD_ALARM_SEVERITIES"
|
|
fi
|
|
|
|
# Configure collectd logfile plugin
|
|
if [ -n $COLLECTD_LOG_FILE ]; then
|
|
touch $COLLECTD_LOG_FILE
|
|
fi
|
|
|
|
sudo cp $COLLECTD_CEILOMETER_DIR/etc/collectd.conf.d/logfile.conf $COLLECTD_CONF_DIR/01-logfile.conf
|
|
|
|
sudo sed -i '/<Plugin.*logfile/,/^<\/Plugin>/{s|LogLevel.*$|LogLevel "'$COLLECTD_LOG_LEVEL'"|}' $COLLECTD_CONF_DIR/01-logfile.conf
|
|
sudo sed -i 's|File.*$|File "'$COLLECTD_LOG_FILE'"|g' $COLLECTD_CONF_DIR/01-logfile.conf
|
|
|
|
# Create a backup for all of the .conf files
|
|
sudo mkdir -p $COLLECTD_CONF_DIR/backup
|
|
sudo cp $COLLECTD_CONF_DIR/*.conf $COLLECTD_CONF_DIR/backup/
|
|
sudo rename 's|\.conf$|.conf.bak|' $COLLECTD_CONF_DIR/backup/*.conf
|
|
}
|
|
|
|
function config_custom_units {
|
|
service_name=$1
|
|
custom_units=$2
|
|
if [[ $custom_units != none ]]; then
|
|
|
|
OIFS=$IFS
|
|
IFS=','
|
|
|
|
for UNIT in $custom_units
|
|
do
|
|
sudo sed -i '/<UNITS>/a\ UNIT '"$UNIT"'' $COLLECTD_CONF_DIR/collectd-$service_name-plugin.conf
|
|
done
|
|
IFS=$OIFS
|
|
fi
|
|
}
|
|
|
|
# Check for severitys defined by the user
|
|
function config_custom_severities {
|
|
service_name=$1
|
|
custom_severities=$2
|
|
if [[ $custom_severities != none ]]; then
|
|
|
|
OIFS=$IFS
|
|
IFS=','
|
|
|
|
for ALARM_SEVERITIES in $custom_severities;
|
|
do
|
|
sudo sed -i '/<ALARM_SEVERITIES>/a\ ALARM_SEVERITY '"$ALARM_SEVERITIES"'' $COLLECTD_CONF_DIR/collectd-$service_name-plugin.conf
|
|
done
|
|
IFS=$OIFS
|
|
fi
|
|
}
|
|
|
|
# remove plugin conf file
|
|
function restore_collectd_conf {
|
|
# Remove all of the .conf files once they are backed up
|
|
sudo rm -f $COLLECTD_CONF_DIR/*.conf
|
|
}
|