1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-06 13:17:42 +03:00

feature im-collectd: Added control parameters. Install collectd driver. Added configuration for collectd in oned.conf

This commit is contained in:
Ruben S. Montero 2013-10-13 20:19:13 +02:00
parent 577a721873
commit e3ec77b41a
4 changed files with 100 additions and 5 deletions

View File

@ -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 \

View File

@ -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

View File

@ -15,12 +15,15 @@
/* -------------------------------------------------------------------------- */
#include <sstream>
#include <iostream>
#include <unistd.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
#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;
}

View File

@ -15,11 +15,78 @@
/* -------------------------------------------------------------------------- */
#include "OpenNebulaDriver.h"
#include <unistd.h>
#include <string>
#include <sstream>
#include <iostream>
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();
}