1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

feature : Compress output of run_probes and uncompress it in oned

to better deal with the UDP message size limit.
This commit is contained in:
Ruben S. Montero 2016-04-22 18:42:58 +02:00
parent 229ca4be3f
commit dd0a3b61c4
3 changed files with 30 additions and 6 deletions
src

@ -305,9 +305,9 @@ std::string one_util::trim(const std::string& str)
std::string::const_iterator wlast(rwlast.base());
std::string tstr(wfirst, wlast);
std::string tstr(wfirst, wlast);
return tstr;
return tstr;
}
/* -------------------------------------------------------------------------- */
@ -449,12 +449,26 @@ std::string * one_util::zlib_decompress(const std::string& in, bool base64)
zs.next_in = (unsigned char *) const_cast<char *>(in.c_str());
}
if ( zs.avail_in <= 2 ) //At least 2 byte header
{
inflateEnd(&zs);
if ( base64 )
{
delete in64;
}
return 0;
}
do
{
zs.avail_out = ZBUFFER;
zs.next_out = out;
if ( (rc = inflate(&zs, Z_FINISH)) == Z_STREAM_ERROR )
rc = inflate(&zs, Z_FINISH);
if ( rc != Z_STREAM_END && rc != Z_OK && rc != Z_BUF_ERROR )
{
inflateEnd(&zs);

@ -66,11 +66,19 @@ extern "C" void * do_message_thread(void *arg)
void MonitorThread::do_message()
{
// -------------------------------------------------------------------------
// Decode from base64
// Decode from base64, check if it is compressed
// -------------------------------------------------------------------------
string* hinfo = one_util::base64_decode(hinfo64);
string* zinfo = one_util::zlib_decompress(*hinfo, false);
Host* host = hpool->get(host_id,true);
if ( zinfo != 0 )
{
delete hinfo;
hinfo = zinfo;
}
Host* host = hpool->get(host_id,true);
if ( host == 0 )
{

@ -20,6 +20,7 @@ require 'socket'
require 'base64'
require 'resolv'
require 'ipaddr'
require 'zlib'
DIRNAME = File.dirname(__FILE__)
@ -68,7 +69,8 @@ class CollectdClient
data = `#{@run_probes_cmd} 2>&1`
code = $?.exitstatus == 0
data64 = Base64::encode64(data).strip.delete("\n")
zdata = Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION)
data64 = Base64::encode64(zdata).strip.delete("\n")
[data64, code]
end