From e3ec77b41a48daac58aee138c296c868afbca120 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 13 Oct 2013 20:19:13 +0200 Subject: [PATCH] feature im-collectd: Added control parameters. Install collectd driver. Added configuration for collectd in oned.conf --- install.sh | 3 +- share/etc/oned.conf | 17 ++++++ src/im_mad/collectd/OpenNebulaDriver.cc | 12 +++- src/im_mad/collectd/collectd.cc | 73 ++++++++++++++++++++++++- 4 files changed, 100 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 05303abb67..b5ab9a8862 100755 --- a/install.sh +++ b/install.sh @@ -751,7 +751,8 @@ MADS_LIB_FILES="src/mad/sh/madcommon.sh \ src/im_mad/im_exec/one_im_exec \ src/im_mad/im_exec/one_im_ssh \ src/im_mad/im_exec/one_im_sh \ - src/im_mad/ec2/one_im_ec2.rb \ + src/im_mad/im_exec/one_im_sh \ + src/im_mad/collectd/collectd \ src/im_mad/ec2/one_im_ec2 \ src/im_mad/dummy/one_im_dummy.rb \ src/im_mad/dummy/one_im_dummy \ diff --git a/share/etc/oned.conf b/share/etc/oned.conf index bb0bb4f69a..df114ea854 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -171,6 +171,23 @@ DEFAULT_DEVICE_PREFIX = "hd" # /etc/one/ if OpenNebula was installed in /) #******************************************************************************* +#------------------------------------------------------------------------------- +# Information Collector for KVM and Xen IM's. +#------------------------------------------------------------------------------- +# This driver CANNOT BE ASSIGNED TO A HOST, and needs to be used with KVM or +# Xen drivers +# -h prints this help. +# -a Address to bind the collectd sockect (defults 0.0.0.0) +# -p UDP port to listen for monitor information (default 4124) +# -f Interval in seconds to flush collected information (default 5) +# -t Number of threads for the server (defult 50) +#------------------------------------------------------------------------------- +IM_MAD = [ + name = "collectd", + executable = "collectd", + arguments = "-p 4124 -f 5 -t 50" ] +#------------------------------------------------------------------------------- + #------------------------------------------------------------------------------- # KVM Information Driver Manager Configuration # -r number of retries when monitoring a host diff --git a/src/im_mad/collectd/OpenNebulaDriver.cc b/src/im_mad/collectd/OpenNebulaDriver.cc index d629c73a7f..2d539a318a 100644 --- a/src/im_mad/collectd/OpenNebulaDriver.cc +++ b/src/im_mad/collectd/OpenNebulaDriver.cc @@ -15,12 +15,15 @@ /* -------------------------------------------------------------------------- */ #include +#include #include #include #include #include #include +#include +#include #include "OpenNebulaDriver.h" #include "ListenerThread.h" @@ -114,14 +117,20 @@ int IMCollectorDriver::init_collector() if ( sock < 0 ) { + std::cerr << strerror(errno); return -1; } im_server.sin_family = AF_INET; im_server.sin_port = htons(_port); - if ( inet_pton(AF_INET, _address.c_str(), &im_server.sin_addr.s_addr) < 0 ) + if (_address == "0.0.0.0") { + im_server.sin_addr.s_addr = htonl (INADDR_ANY); + } + else if (inet_pton(AF_INET,_address.c_str(),&im_server.sin_addr.s_addr) < 0) + { + std::cerr << strerror(errno); return -1; } @@ -129,6 +138,7 @@ int IMCollectorDriver::init_collector() if ( rc < 0 ) { + std::cerr << strerror(errno); return -1; } diff --git a/src/im_mad/collectd/collectd.cc b/src/im_mad/collectd/collectd.cc index 2c939f2bbb..256392bdaa 100644 --- a/src/im_mad/collectd/collectd.cc +++ b/src/im_mad/collectd/collectd.cc @@ -15,11 +15,78 @@ /* -------------------------------------------------------------------------- */ #include "OpenNebulaDriver.h" +#include +#include +#include +#include -int main() +static const char * usage = +"\n collectd [-h] [-a address] [-p port] [-t threads] [-f flush]\n\n" +"SYNOPSIS\n" +" Information Collector for OpenNebula. It should not be started directly\n\n" +"OPTIONS\n" +"\t-h\tprints this help.\n" +"\t-a\tAddress to bind the collectd sockect\n" +"\t-p\tUDP port to listen for monitor information\n" +"\t-f\tInterval in seconds to flush collected information\n" +"\t-t\tNumber of threads for the server\n"; + +int main(int argc, char ** argv) { - IMCollectorDriver collectd("127.0.0.1", 9876, 1, 1); + std::string address = "0.0.0.0"; + int port = 4124; + int threads = 50; + int flush = 5; + + std::istringstream iss; + int opt; + + while((opt = getopt(argc,argv,":ha:p:t:f:")) != -1) + switch(opt) + { + case 'h': + std::cout << usage; + return 0; + break; + case 'a': + address = optarg; + break; + + case 'p': + iss.clear(); + iss.str(optarg); + + iss >> port; + break; + + case 't': + iss.clear(); + iss.str(optarg); + + iss >> threads; + break; + + case 'f': + iss.clear(); + iss.str(optarg); + + iss >> flush; + break; + + default: + std::cerr << usage; + return -1; + break; + } + + + IMCollectorDriver collectd(address, port, threads, flush); + + if ( collectd.init_collector() != 0 ) + { + std::cerr << ". Could not init collectd, exiting...\n"; + return -1; + } - collectd.init_collector(); collectd.start_collector(); }