From 43d86ff1cdd65711349fcec898ba79800d6b2fdc Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Tue, 30 Aug 2016 16:43:02 +0100 Subject: [PATCH] Add code to build collectd - Add option to build collectd from source - Clones, builds and installs collectd under the source repo - Add install_requirements function - Add config options: - COLLECTD_INSTALL_TYPE - COLLECTD_REPO - COLLECTD_DIR - COLLECTD_BRANCH - COLLECTD_PREFIX - Update documentation in doc/source/usage.rst - Add service file for systemd - Make sure the config dir is included Partial-Bug: #1596966 Change-Id: I92156cf69438634c6340c21089538ff7ea716e6f --- devstack/libs/collectd | 85 +++++++++++++++++-- devstack/settings | 6 ++ doc/source/examples/local.conf.source_build | 33 +++++++ doc/source/usage.rst | 43 ++++++++-- .../build-collectd-1fe373aaf2d10630.yaml | 7 ++ 5 files changed, 160 insertions(+), 14 deletions(-) create mode 100644 doc/source/examples/local.conf.source_build create mode 100644 releasenotes/notes/build-collectd-1fe373aaf2d10630.yaml diff --git a/devstack/libs/collectd b/devstack/libs/collectd index 130a086..1f55c42 100644 --- a/devstack/libs/collectd +++ b/devstack/libs/collectd @@ -17,32 +17,107 @@ function stop_collectd { fi } + function install_requirements { echo "Installing pre-resquisites" + if is_ubuntu; then install_package libvirt-bin libvirt-dev python-libvirt + if [[ "$COLLECTD_INSTALL_TYPE" == "source" ]]; then + install_package byacc flex bison build-essential automake libgcrypt20 libtool + fi + elif is_fedora; then install_package libvirt libvirt-devel libvirt-python + if [[ "$COLLECTD_INSTALL_TYPE" == "source" ]]; then + install_package flex bison automake autoconf libtool + fi 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 is_fedora || is_ubuntu; then - install_package collectd - else - die $LINENO "No support for collectd on this platform" + 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 + + + Filter "*.conf" + +EOF + +} + # Add conf file for plugin function adapt_collectd_conf { if [ ! -d "$COLLECTD_CONF_DIR" ]; then - sudo mkdir -p "$COLLECTD_CONF_DIR" + sudo -E mkdir -p "$COLLECTD_CONF_DIR" fi # Configure collectd-ceilometer-plugin diff --git a/devstack/settings b/devstack/settings index dd7bb29..d1cbddc 100644 --- a/devstack/settings +++ b/devstack/settings @@ -1,8 +1,14 @@ # General settings COLLECTD_CEILOMETER_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd ) COLLECTD_BATCH_SIZE=${COLLECTD_BATCH_SIZE:-1} +COLLECTD_BRANCH=${COLLECTD_BRANCH:-collectd-5.7} +COLLECTD_DIR=${COLLECTD_DIR:-$DEST/collectd-$COLLECTD_BRANCH/} COLLECTD_INSTALL=${COLLECTD_INSTALL:-True} +COLLECTD_INSTALL_TYPE=${COLLECTD_INSTALL_TYPE:-'binary'} COLLECTD_CONF_DIR=${COLLECTD_CONF_DIR:-''} +# this is a mirror of: git://git.verplant.org/collectd.git +COLLECTD_REPO=${COLLECTD_REPO:-'https://github.com/collectd/collectd.git'} +COLLECTD_PREFIX=${COLLECTD_PREFIX:-'/usr'} COLLECTD_CEILOMETER_VERBOSE=${COLLECTD_CEILOMETER_VERBOSE:-False} diff --git a/doc/source/examples/local.conf.source_build b/doc/source/examples/local.conf.source_build new file mode 100644 index 0000000..9d53191 --- /dev/null +++ b/doc/source/examples/local.conf.source_build @@ -0,0 +1,33 @@ +[[local|localrc]] + +HOST_IP= + +VERBOSE=True +FORCE=yes + +MYSQL_PASSWORD=password +DATABASE_PASSWORD=password +RABBIT_PASSWORD=password +ADMIN_PASSWORD=password +SERVICE_PASSWORD=password +HORIZON_PASSWORD=password +SERVICE_TOKEN=tokentoken + +disable_all_services +enable_service key +enable_service mysql +enable_service rabbit +enable_service dstat + +# For more options refer to devstackGSG.rst + +# GNOCCHI +enable_plugin gnocchi https://github.com/openstack/gnocchi master +GNOCCHI_USE_KEYSTONE=True +COLLECTD_GNOCCHI_ENABLED=True + +# Setup collectd-ceilometer plugin +COLLECTD_INSTALL=True +COLLECTD_INSTALL_TYPE=source +COLLECTD_CEILOMETER_VERBOSE=True +enable_plugin collectd-ceilometer http://github.com/openstack/collectd-ceilometer-plugin diff --git a/doc/source/usage.rst b/doc/source/usage.rst index e98f7de..d4fc018 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -12,6 +12,12 @@ To use collectd-ceilometer-plugin in collectd:: local.conf settings ------------------- +COLLECTD_BRANCH + () Indicates which branch of collectd to checkout before + compiling. + + Default: collectd-5.7 + COLLECTD_CONF_DIR (directory) Specify a directory where collectd conf files reside. This is required if you use a distro other than Ubuntu or Fedora, or if @@ -19,11 +25,16 @@ COLLECTD_CONF_DIR be created if it doesn't already exist. Default: /etc/collectd/collectd.conf.d (Ubuntu) /etc/collectd.d (Fedora) +COLLECTD_DIR + (directory) Destination of the cloned collectd source code. + Default: $DEST/collectd-$COLLECTD_BRANCH/ + COLLECTD_INSTALL - (True|False) Indicates whether to install collectd from package manager. - Set this to False if you are running a custom collectd build or do not - want to upgrade installed version. + (True|False) Indicates whether to install collectd. + Set this to False if you are running a pre-built version of collectd or do + not want to upgrade installed version. + Default: True @@ -32,12 +43,6 @@ COLLECTD_BATCH_SIZE Default: 1 i.e. no batching/buffering. -COLLECTD_DIR - Specify collectd directory, this is required if collectd was installed - manually. - Default: /opt/collectd - - CEILOMETER_TIMEOUT Sets the ceilometer's request timeout. The value is passed in milliseconds. Default: 1000 i.e. 1 sec. @@ -89,6 +94,26 @@ COLLECTD_GNOCCHI_ENABLED Default: True + +COLLECTD_INSTALL_TYPE + (source|binary) Specify whether the collectd installation should use the + package manager or install from source. + + Default: binary + + +COLLECTD_REPO + (url) Location of git repo to clone collectd from. + + Default: https://github.com/collectd/collectd.git + + +COLLECTD_PREFIX + (directory) The directory to install collectd under. + + Default: /usr/ + + Authenticating using Identity Server API v3 =========================================== diff --git a/releasenotes/notes/build-collectd-1fe373aaf2d10630.yaml b/releasenotes/notes/build-collectd-1fe373aaf2d10630.yaml new file mode 100644 index 0000000..1c86eb0 --- /dev/null +++ b/releasenotes/notes/build-collectd-1fe373aaf2d10630.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Devstack code added to clone and build collectd from source, allowing + specific versions to be installed, including newly-developed plugin-ins + which have not been released yet, or are not included in the collectd main + repository.